Hello,
I have created a .NET dll to publish multisheet PDF using
Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Application.Publisher;
But I can not use this dll in the accorconsole.exe because above publisher class is in the acmgd.dll (UI related) obviously program/process crashes on the
publisher.PublishExecute(dsdData, pc); line execution.
Please suggest workaround to publish multisheet PDF without using acmgd.dll classes to use in accorconsole.exe process
Thanks in advance,
Solved! Go to Solution.
Solved by Virupaksha_aithal. Go to Solution.
Hi,
Maybe you can use the -PUBLISH command in the accoreconsole passing it a DSD file (not tested).
You can write the DSD file by code (see the TryCreateDSD(), CreateDsdEntryCollection() and PostProcessDsd() private methods in the MultiSheetsPdf class).
Hi,
You can reuse some of the code available in http://adndevblog.typepad.com/autocad/2012/05/how-to-use-autodeskautocadpublishingpublisherpublishex... .
Example, below code do not need reference to acmgd.dll
static public void PublishTest() { DsdEntryCollection collection = new DsdEntryCollection(); Database db = HostApplicationServices.WorkingDatabase; string filename = db.Filename; using (Transaction Tx = db.TransactionManager.StartTransaction()) { System.Collections.Generic.List<ObjectId> ids = getLayoutIds(db); foreach (ObjectId layoutId in ids) { Layout layout = Tx.GetObject( layoutId, OpenMode.ForRead) as Layout; DsdEntry entry = new DsdEntry(); entry.DwgName = filename; entry.Layout = layout.LayoutName; entry.Title = layout.LayoutName; entry.NpsSourceDwg = entry.DwgName; entry.Nps = "Setup1"; collection.Add(entry); } Tx.Commit(); } DsdData dsdData = new DsdData(); dsdData.SheetType = SheetType.MultiPdf; dsdData.ProjectPath = "C:\\Temp"; //Not used for "SheetType.SingleDwf" //dsdData.DestinationName = dsdData.ProjectPath + "\\output.dwf"; dsdData.SetDsdEntryCollection(collection); string dsdFile = dsdData.ProjectPath + "\\dsdData.dsd"; //Workaround to avoid promp for dwf file name //set PromptForDwfName=FALSE in dsdData //using StreamReader/StreamWriter if (System.IO.File.Exists(dsdFile)) System.IO.File.Delete(dsdFile); dsdData.WriteDsd(dsdFile); System.IO.StreamReader sr = new System.IO.StreamReader(dsdFile); string str = sr.ReadToEnd(); sr.Close(); str = str.Replace( "PromptForDwfName=TRUE", "PromptForDwfName=FALSE"); System.IO.StreamWriter sw = new System.IO.StreamWriter(dsdFile); sw.Write(str); sw.Close(); dsdData.ReadDsd(dsdFile); System.IO.File.Delete(dsdFile); using (PlotConfig plotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("DWG To PDF.pc3")) { Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher; publisher.PublishExecute(dsdData, plotConfig); } } private static System.Collections.Generic.List<ObjectId> getLayoutIds(Database db) { System.Collections.Generic.List<ObjectId> layoutIds = new System.Collections.Generic.List<ObjectId>(); using (Transaction Tx = db.TransactionManager.StartTransaction()) { DBDictionary layoutDic = Tx.GetObject( db.LayoutDictionaryId, OpenMode.ForRead, false) as DBDictionary; foreach (DBDictionaryEntry entry in layoutDic) { layoutIds.Add(entry.Value); }
Tx.Commit(); } return layoutIds; }
Hello Gile and Virupaksha,
Thanks for the reply. I could successfully run the script and produce the PDF with publisher (of accoremgd.dll) but when I use by calling accoreconsole.exe it produces the PDF as expected but crashes AutoCAD after that. Please find attached image of crash.
1) Does Autodesk.AutoCAD.Publishing.Publisher publisher = Autodesk.AutoCAD.ApplicationServices.Core.Application.Publisher; can not use in accoreconsole calling? Because it show progress bar in normal autocad dll usage
Please see attached crash image file.
2) How to use -PUBLISH with .dsd file
Please guide on this as everything works fine if I comment 'publisher.PublishExecute(dsdData, plotConfig);' line. Am I missing any system variable settings to print without UI? I also set Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("BACKGROUNDPLOT", 1);
I don't understand what am I doing wrong.
Thanks,
Pushpak
Update to above problem. I have removed cr/lf at the end of .scr file which solves my autocad/accoreconsole crash issue.
Thanks to Gile and Virupaksha for helping on this.
Cheers,
its an good artical , its help me lot to generate multi sheet pdf using AutoCAD self pc3 files , its working fine for me.
but when I tried to use third party pdf printer (adobe pdf .pc3) I getting issues while publishing.
my code is as below,
My CODE sample : CreateDSDFile("Test.dsd");
using (DsdData dsdDataFile = new DsdData())
{
dsdDataFile.ReadDsd("c:\\Test.dsd"); // Get the Adobe PDF.pc3 and use it as a device override for all the layouts
PlotConfig acPlCfg = PlotConfigManager.SetCurrentConfig("Adobe PDF.pc3");
Application.Publisher.PublishExecute(dsdDataFile, acPlCfg);
}
Error :
This is the error:
Category name:
Page setup: 1 As To 2 A3 PDF
Device name: DWG To PDF.pc3
Plot file path: D:\A3 PDF-1 As To 2 .dwg
ERROR: Internal Error: Null Pointer
ERROR: Unable to open the DWF6 ePlot.pc3 file. You can recreate it with Add Plotter.
Test.dsd file content:
[DWF6Version]
Ver=1
[DWF6Sheet:Drawing-Model]
DWG=D:\Drawing.DWG
Layout=Model
Setup=1 As To 2 A3 PDF|D:\A3 PDF-1 As To 2 .dwg
[DWF6Sheet:Drawing1.DWG-Model]
DWG=D:\Drawing1.DWG
Layout=Model
Setup=1 As To 2 A3 PDF|D:\A3 PDF-1 As To 2 .dwg
[DWF6Sheet:Drawing2.DWG-Model]
DWG=D:Drawing2.DWG
Layout=Model
Setup=1 As To 2 A3 PDF|D:\A3 PDF-1 As To 2 .dwg
[Target]
Type=6
DWF= D:\DrawingPackage.pdf
OUT=D:\
PWD=