複数のレイアウトをパブリッシュするには、各レイアウトに関する情報を収集する必要があります。パブリッシュする各レイアウトの DsdEntry オブジェクトを作成します。DsdEntry オブジェクトには、レイアウト名、タイトル、優先ページ設定、レイアウトが保存されている図面ファイルが含まれます。DsdEntry オブジェクトは DsdEntryCollection オブジェクトに追加され、このオブジェクトは SetDsdEntryCollection メソッドによって DsdData オブジェクトに追加されます。
DsdData オブジェクトは、指定されたレイアウトをパブリッシュするときに使用する設定を定義します。DsdData オブジェクトが定義されたら、WriteDsd メソッドを使用して DSD ファイルを作成できます。このファイルは、PUBLISH[マルチシート DWF パブリッシュ]コマンドや Publisher オブジェクトで使用できます。
Publisher オブジェクトは、DSD ファイル内のレイアウトの出力に使用されます。[マルチシート DWF をパブリッシュ]ダイアログ ボックスと同様に、定義済みの印刷デバイスと設定を使用してレイアウトを出力したり、PublishDsd メソッドで DsdEntry オブジェクトの優先ページ設定を使用できます。また、PublishExecute メソッドを使用すると、レイアウトに割り当てられているデバイスをオーバーライドすることもできます。
この例では、PublishExecute メソッドを使用して 2 つのレイアウトを PDF ファイルにパブリッシュします。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices
' Publishes layouts to a PDF file
<CommandMethod("PublishLayouts")> _
Public Shared Sub PublishLayouts()
Using dsdDwgFiles As New DsdEntryCollection
' Add first drawing file
Using dsdDwgFile1 As New DsdEntry
' Set the file name and layout
dsdDwgFile1.DwgName = "C:\AutoCAD\Samples\Sheet Sets\Architectural\A-01.dwg"
dsdDwgFile1.Layout = "MAIN AND SECOND FLOOR PLAN"
dsdDwgFile1.Title = "A-01 MAIN AND SECOND FLOOR PLAN"
' Set the page setup override
dsdDwgFile1.Nps = ""
dsdDwgFile1.NpsSourceDwg = ""
dsdDwgFiles.Add(dsdDwgFile1)
End Using
' Add second drawing file
Using dsdDwgFile2 As New DsdEntry
' Set the file name and layout
dsdDwgFile2.DwgName = "C:\AutoCAD\Samples\Sheet Sets\Architectural\A-02.dwg"
dsdDwgFile2.Layout = "ELEVATIONS"
dsdDwgFile2.Title = "A-02 ELEVATIONS"
' Set the page setup override
dsdDwgFile2.Nps = ""
dsdDwgFile2.NpsSourceDwg = ""
dsdDwgFiles.Add(dsdDwgFile2)
End Using
' Set the properties for the DSD file and then write it out
Using dsdFileData As New DsdData
' Set the target information for publishing
dsdFileData.DestinationName = Environment.GetFolderPath( _
Environment.SpecialFolder.MyDocuments) & "\MyPublish2.pdf"
dsdFileData.ProjectPath = Environment.GetFolderPath( _
Environment.SpecialFolder.MyDocuments) & "\"
dsdFileData.SheetType = SheetType.MultiPdf
' Set the drawings that should be added to the publication
dsdFileData.SetDsdEntryCollection(dsdDwgFiles)
' Set the general publishing properties
dsdFileData.LogFilePath = Environment.GetFolderPath( _
Environment.SpecialFolder.MyDocuments) & "\myBatch.txt"
' Create the DSD file
dsdFileData.WriteDsd(Environment.GetFolderPath( _
Environment.SpecialFolder.MyDocuments) & _
"\batchdrawings2.dsd")
Try
' Publish the specified drawing files in the DSD file, and
' honor the behavior of the BACKGROUNDPLOT system variable
Using dsdDataFile As New DsdData
dsdDataFile.ReadDsd(Environment.GetFolderPath( _
Environment.SpecialFolder.MyDocuments) & _
"\batchdrawings2.dsd")
' Get the DWG to PDF.pc3 and use it as a
' device override for all the layouts
Dim acPlCfg As PlotConfig = _
PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3")
Application.Publisher.PublishExecute(dsdDataFile, acPlCfg)
End Using
Catch es As Autodesk.AutoCAD.Runtime.Exception
MsgBox(es.Message)
End Try
End Using
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
// Publishes layouts to a PDF file
[CommandMethod("PublishLayouts")]
public static void PublishLayouts()
{
using (DsdEntryCollection dsdDwgFiles = new DsdEntryCollection())
{
// Define the first layout
using (DsdEntry dsdDwgFile1 = new DsdEntry())
{
// Set the file name and layout
dsdDwgFile1.DwgName = "C:\\AutoCAD\\Samples\\Sheet Sets\\Architectural\\A-01.dwg";
dsdDwgFile1.Layout = "MAIN AND SECOND FLOOR PLAN";
dsdDwgFile1.Title = "A-01 MAIN AND SECOND FLOOR PLAN";
// Set the page setup override
dsdDwgFile1.Nps = "";
dsdDwgFile1.NpsSourceDwg = "";
dsdDwgFiles.Add(dsdDwgFile1);
}
// Define the second layout
using (DsdEntry dsdDwgFile2 = new DsdEntry())
{
// Set the file name and layout
dsdDwgFile2.DwgName = "C:\\AutoCAD\\Samples\\Sheet Sets\\Architectural\\A-02.dwg";
dsdDwgFile2.Layout = "ELEVATIONS";
dsdDwgFile2.Title = "A-02 ELEVATIONS";
// Set the page setup override
dsdDwgFile2.Nps = "";
dsdDwgFile2.NpsSourceDwg = "";
dsdDwgFiles.Add(dsdDwgFile2);
}
// Set the properties for the DSD file and then write it out
using (DsdData dsdFileData = new DsdData())
{
// Set the target information for publishing
dsdFileData.DestinationName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\MyPublish2.pdf";
dsdFileData.ProjectPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\";
dsdFileData.SheetType = SheetType.MultiPdf;
// Set the drawings that should be added to the publication
dsdFileData.SetDsdEntryCollection(dsdDwgFiles);
// Set the general publishing properties
dsdFileData.LogFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\myBatch.txt";
// Create the DSD file
dsdFileData.WriteDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings2.dsd");
try
{
// Publish the specified drawing files in the DSD file, and
// honor the behavior of the BACKGROUNDPLOT system variable
using (DsdData dsdDataFile = new DsdData())
{
dsdDataFile.ReadDsd(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\batchdrawings2.dsd");
// Get the DWG to PDF.pc3 and use it as a
// device override for all the layouts
PlotConfig acPlCfg = PlotConfigManager.SetCurrentConfig("DWG to PDF.PC3");
Application.Publisher.PublishExecute(dsdDataFile, acPlCfg);
}
}
catch (Autodesk.AutoCAD.Runtime.Exception es)
{
System.Windows.Forms.MessageBox.Show(es.Message);
}
}
}
}