//private void HandleCancelledOrFailedPublish(object sender, PublishEventArgs e) //{ // app.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Error : publishing failed/cancelled...", e.ToString()); //} //private void HandleEndPublish(object sender, PublishEventArgs e) //{ // app.DocumentManager.MdiActiveDocument.Editor.WriteMessage("All publishing tasks finished...", e.ToString()); //} //private void HandleBeginPublishingSheet(object sender, BeginPublishingSheetEventArgs e) //{ // app.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Error : while publishing...", e.ToString()); //} private bool TryCreateDSD() { using (DsdData dsd = new DsdData()) using (DsdEntryCollection dsdEntries = CreateDsdEntryCollection(this._layouts)) { if (dsdEntries == null || dsdEntries.Count <= 0) { return(false); } if (!Directory.Exists(this._outputDir)) { Directory.CreateDirectory(this._outputDir); } this._numberOfsheets = dsdEntries.Count; dsd.SetDsdEntryCollection(dsdEntries); dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE"); dsd.SetUnrecognizedData("PromptForPwd", "FALSE"); //dsd.SheetType = SheetType.MultiDwf; dsd.SheetType = SheetType.MultiPdf; //previously MultiDwf -- check dsd.NoOfCopies = 1; dsd.DestinationName = this._pdfFile; dsd.IsHomogeneous = false; dsd.LogFilePath = Path.Combine(this._outputDir, _logFile); PostProcessDSD(dsd); return(true); } }
// Creates the DSD file from a template (default options) private bool TryCreateDSD() { using (var dsd = new DsdData()) using (var dsdEntries = CreateDsdEntryCollection(_layouts)) { if (dsdEntries.Count <= 0) { return(false); } if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } sheetNum = dsdEntries.Count; dsd.SetDsdEntryCollection(dsdEntries); dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE"); dsd.SetUnrecognizedData("PromptForPwd", "FALSE"); dsd.NoOfCopies = 1; dsd.DestinationName = outputFile; dsd.IsHomogeneous = false; dsd.LogFilePath = Path.Combine(outputDir, LOG); PostProcessDSD(dsd); return(true); } }
// Creates the DSD file from a template (default options) private bool TryCreateDSD(string layerName) { using (DsdData dsd = new DsdData()) using (DsdEntryCollection dsdEntries = CreateDsdEntryCollection(this.layouts, Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database, layerName)) { if (dsdEntries == null || dsdEntries.Count <= 0) { return(false); } if (!Directory.Exists(this.outputDir)) { Directory.CreateDirectory(this.outputDir); } this.sheetNum = dsdEntries.Count; dsd.SetDsdEntryCollection(dsdEntries); dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE"); dsd.SetUnrecognizedData("PromptForPwd", "FALSE"); dsd.SetUnrecognizedData("INCLUDELAYER", "FALSE"); dsd.NoOfCopies = 1; dsd.DestinationName = this.outputFile; dsd.IsHomogeneous = false; dsd.LogFilePath = Path.Combine(this.outputDir, LOG); PostProcessDSD(dsd); return(true); } }
// Creates the DSD file from a template (default options) private bool tryCreateDSD() { using (DsdData dsd = new DsdData()) using (DsdEntryCollection dsdEntries = CreateDsdEntryCollection(this.layouts)) { if (dsdEntries == null || dsdEntries.Count <= 0) return false; if (!Directory.Exists(this.outputDir)) Directory.CreateDirectory(this.outputDir); this.sheetNum = dsdEntries.Count; dsd.SetDsdEntryCollection(dsdEntries); dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE"); dsd.SetUnrecognizedData("PromptForPwd", "FALSE"); dsd.NoOfCopies = 1; dsd.DestinationName = this.outputFile; dsd.IsHomogeneous = false; dsd.LogFilePath = Path.Combine(this.outputDir, LOG); postProcessDSD(dsd); return true; } }
public void PublishNew(string pdfLocation, string layerName) { Document doc = Application.DocumentManager.MdiActiveDocument; Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication.GetType().InvokeMember("ZoomExtents", BindingFlags.InvokeMethod, null, Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, null); Database db = doc.Database; Editor ed = doc.Editor; string dwgFileName = Application.GetSystemVariable("DWGNAME") as string; string dwgPath = Application.GetSystemVariable("DWGPREFIX") as string; string name = System.IO.Path.GetFileNameWithoutExtension(dwgFileName); //find a temp location. string strTemp = System.IO.Path.GetTempPath(); //PromptStringOptions options = // new PromptStringOptions("Specific the DWF file name"); //options.DefaultValue = "c:\\temp\\" + name + ".dwf"; //PromptResult result = ed.GetString(options); //if (result.Status != PromptStatus.OK) // return; //get the layout ObjectId List System.Collections.ArrayList layoutList = null; try { layoutList = layouts; } catch { // Application.ShowAlertDialog("Unable to get layouts name"); return; } Publisher publisher = Application.Publisher; //put the plot in foreground short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT"); Application.SetSystemVariable("BACKGROUNDPLOT", 0); using (Transaction tr = db.TransactionManager.StartTransaction()) { DsdEntryCollection collection = new DsdEntryCollection(); Layout _layout = null; foreach (ObjectId layoutId in layoutList) { Layout layout = tr.GetObject(layoutId, OpenMode.ForWrite) as Layout; #region plot Extends Point3d pMin = layout.Extents.MinPoint; Point3d pMax = layout.Extents.MaxPoint; PlotSettingsValidator psv = PlotSettingsValidator.Current; PlotSettings ps = new PlotSettings(layout.ModelType); ps.CopyFrom(layout); psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents); bool bAreaIsLandscape = true; if (layout.ModelType) { bAreaIsLandscape = (db.Extmax.X - db.Extmin.X) > (db.Extmax.Y - db.Extmin.Y) ? true : false; } else { bAreaIsLandscape = (layout.Extents.MaxPoint.X - layout.Extents.MinPoint.X) > (layout.Extents.MaxPoint.Y - layout.Extents.MinPoint.Y) ? true : false; } bool bPaperIsLandscape = (ps.PlotPaperSize.X > ps.PlotPaperSize.Y) ? true : false; if (bPaperIsLandscape != bAreaIsLandscape) { psv.SetPlotRotation(ps, PlotRotation.Degrees270); } ps.PlotSettingsName = layout.LayoutName + "_plot"; ps.AddToPlotSettingsDictionary(db); tr.AddNewlyCreatedDBObject(ps, true); psv.RefreshLists(ps); layout.CopyFrom(ps); #endregion DsdEntry entry = new DsdEntry(); entry.DwgName = dwgPath + dwgFileName; entry.Layout = layout.LayoutName; entry.Title = Path.GetFileNameWithoutExtension(this.dwgFile) + "-" + layerName + "-" + layout.LayoutName; entry.Nps = ps.PlotSettingsName;// "AA"; _layout = layout; collection.Add(entry); } DsdData dsdData = new DsdData(); dsdData.SheetType = SheetType.SinglePdf; dsdData.ProjectPath = pdfLocation; dsdData.DestinationName = pdfLocation + name + " " + layerName + ".pdf"; dsdData.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE"); dsdData.SetUnrecognizedData("PromptForPwd", "FALSE"); dsdData.SetUnrecognizedData("INCLUDELAYER", "FALSE"); dsdData.NoOfCopies = 1; dsdData.IsHomogeneous = false; string dsdFile = pdfLocation + name + layerName + ".dsd"; if (System.IO.File.Exists(dsdFile)) { System.IO.File.Delete(dsdFile); } dsdData.SetDsdEntryCollection(collection); dsdData.PromptForDwfName = false; //Workaround to avoid promp for dwf file name //set PromptForDwfName=FALSE in //dsdData using StreamReader/StreamWriter dsdData.WriteDsd(dsdFile); StreamReader sr = new StreamReader(dsdFile); string str = sr.ReadToEnd(); sr.Close(); //str = // str.Replace("PromptForDwfName=TRUE", // "PromptForDwfName=FALSE"); str = str.Replace("IncludeLayer=TRUE", "IncludeLayer=FALSE"); StreamWriter sw = new StreamWriter(dsdFile); sw.Write(str); sw.Close(); dsdData.ReadDsd(dsdFile); //18-07-2018 //PlotSettings ps = new PlotSettings(_layout.ModelType); //ps.CopyFrom(_layout); //PlotSettingsValidator psv = PlotSettingsValidator.Current; //psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents); //psv.SetUseStandardScale(ps, true); //psv.SetStdScaleType(ps, StdScaleType.ScaleToFit); //psv.SetPlotCentered(ps, true); //// We'll use the standard DWF PC3, as //// for today we're just plotting to file //psv.SetPlotConfigurationName(ps, "DWG to PDF.PC3", "ANSI_A_(8.50_x_11.00_Inches)"); using (PlotConfig pc = PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3")) { publisher.PublishExecute(dsdData, pc); } System.IO.File.Delete(dsdFile); tr.Commit(); } //reset the background plot value Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot); }