Here is a common request from ADN developers:
Is there any sample showing how to create programmatically a configuration dsd file and use the Publisher.PublishDsd API ?
Solution
Here is a C# example that shows you how to publish to a dwf sheet set two layouts from differents drawings. It also create programmatically a dsd file and write it on the disk. You could also use an existing dsd file that was created previously and provide it directly to the PublishDsd method.
For the sample to work, you need to have two drawings, named "Drawing1.dwg" and "Drawing2.dwg", that are stored at the location: "C:\Temp\". Each drawing needs to have a layout named "Layout1".
[CommandMethod("PublisherDSD")]
static public void PublisherDSD()
{
try
{
DsdEntryCollection collection = new DsdEntryCollection();
DsdEntry entry;
entry = new DsdEntry();
entry.Layout = "Layout1";
entry.DwgName = "c:\\Temp\\Drawing1.dwg";
entry.Nps = "Setup1";
entry.Title = "Sheet1";
collection.Add(entry);
entry = new DsdEntry();
entry.Layout = "Layout1";
entry.DwgName = "c:\\Temp\\Drawing2.dwg";
entry.Nps = "Setup1";
entry.Title = "Sheet2";
collection.Add(entry);
DsdData dsd = new DsdData();
dsd.SetDsdEntryCollection(collection);
dsd.ProjectPath = "c:\\Temp\\";
dsd.LogFilePath = "c:\\Temp\\logdwf.log";
dsd.SheetType = SheetType.MultiDwf;
dsd.NoOfCopies = 1;
dsd.DestinationName = "c:\\Temp\\PublisherTest.dwf";
dsd.SheetSetName = "PublisherSet";
dsd.WriteDsd("c:\\Temp\\publisher.dsd");
int nbSheets = collection.Count;
using (PlotProgressDialog progressDlg =
new PlotProgressDialog(false, nbSheets, true))
{
progressDlg.set_PlotMsgString(
PlotMessageIndex.DialogTitle,
"Plot API Progress");
progressDlg.set_PlotMsgString(
PlotMessageIndex.CancelJobButtonMessage,
"Cancel Job");
progressDlg.set_PlotMsgString(
PlotMessageIndex.CancelSheetButtonMessage,
"Cancel Sheet");
progressDlg.set_PlotMsgString(
PlotMessageIndex.SheetSetProgressCaption,
"Job Progress");
progressDlg.set_PlotMsgString(
PlotMessageIndex.SheetProgressCaption,
"Sheet Progress");
progressDlg.UpperPlotProgressRange = 100;
progressDlg.LowerPlotProgressRange = 0;
progressDlg.UpperSheetProgressRange = 100;
progressDlg.LowerSheetProgressRange = 0;
progressDlg.IsVisible = true;
Autodesk.AutoCAD.Publishing.Publisher publisher =
Application.Publisher;
Autodesk.AutoCAD.PlottingServices.PlotConfigManager.
SetCurrentConfig("DWF6 ePlot.pc3");
publisher.PublishDsd(
"c:\\Temp\\publisher.dsd", progressDlg);
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}