发布布局 (.NET)
在发布多个布局之前,需要收集有关每个布局的信息。您可以为要发布的每个布局创建一个对象。对象包含布局名称、标题、覆盖页面设置以及它所在的图形文件。 然后将对象添加到对象中,然后使用该方法将对象添加到对象中。DsdEntryDsdEntryDsdEntryDsdEntryCollectionDsdDataSetDsdEntryCollection 对象定义应用于发布指定布局的设置。定义对象后,可以使用该方法创建用于 PUBLISH 命令或对象的 DSD 文件。DsdDataDsdDataWriteDsdPublisher 该对象用于输出 DSD 文件中的布局。与“发布”对话框类似,可以使用布局的打印设备和定义的设置来输出布局,也可以通过该方法在对象中使用覆盖页面设置。还可以使用该方法替代分配给布局的设备。PublisherDsdEntryPublishDsdPublishExecute 注意:在使用该方法发布 DSD 文件之前,应将 BACKGROUNDPLOT 系统变量设置为值 0。PublishDsd
将布局发布到 PDF 文件本示例使用该方法将两个布局发布到 PDF 文件。PublishExecute VB.NETImports 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 C#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); } } } } 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-19 06:53
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.