对象与对象类似,因为两者都包含相同的绘图信息,这是因为类是从类派生的。主要区别在于对象具有包含要打印的几何图形的关联对象。对象不与特定对象关联,而是存储在图形的 PlotSettings 字典中。 对象在 AutoCAD 用户界面中称为页面设置,可从页面设置管理器访问。页面设置可以应用于布局,也可以用作在打印或发布时覆盖布局设置的方法。PlotSettingsLayoutLayoutPlotSettingsLayoutBlockTableRecordPlotSettingsBlockTableRecordPlotSettings 列出可用的页面设置本示例列出图形中包含的页面设置。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.PlottingServices ' Lists the available page setups <CommandMethod("ListPageSetup")> _ Public Shared Sub ListPageSetup() ' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database ' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim plSettings As DBDictionary = _ acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead) acDoc.Editor.WriteMessage(vbLf & "Page Setups: ") ' List each named page setup For Each item As DBDictionaryEntry In plSettings acDoc.Editor.WriteMessage(vbLf & " " & item.Key) Next ' Abort the changes to the database acTrans.Abort() End Using End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.PlottingServices; // Lists the available page setups [CommandMethod("ListPageSetup")] public static void ListPageSetup() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { DBDictionary plSettings = acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary; acDoc.Editor.WriteMessage("\nPage Setups: "); // List each named page setup foreach (DBDictionaryEntry item in plSettings) { acDoc.Editor.WriteMessage("\n " + item.Key); } // Abort the changes to the database acTrans.Abort(); } } 创建新页面设置本示例基于当前布局创建新的页面设置。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.PlottingServices ' Creates a new page setup or edits the page set if it exists <CommandMethod("CreateOrEditPageSetup")> _ Public Shared Sub CreateOrEditPageSetup() ' Get the current document and database, and start a transaction Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim plSets As DBDictionary = _ acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead) Dim vStyles As DBDictionary = _ acTrans.GetObject(acCurDb.VisualStyleDictionaryId, OpenMode.ForRead) Dim acPlSet As PlotSettings Dim createNew As Boolean = False ' Reference the Layout Manager Dim acLayoutMgr As LayoutManager = LayoutManager.Current ' Get the current layout and output its name in the Command Line window Dim acLayout As Layout = _ acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _ OpenMode.ForRead) ' Check to see if the page setup exists If plSets.Contains("MyPageSetup") = False Then createNew = True ' Create a new PlotSettings object: ' True - model space, False - named layout acPlSet = New PlotSettings(acLayout.ModelType) acPlSet.CopyFrom(acLayout) acPlSet.PlotSettingsName = "MyPageSetup" acPlSet.AddToPlotSettingsDictionary(acCurDb) acTrans.AddNewlyCreatedDBObject(acPlSet, True) Else acPlSet = plSets.GetAt("MyPageSetup").GetObject(OpenMode.ForWrite) End If ' Update the PlotSettings object Try Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current ' Set the Plotter and page size acPlSetVdr.SetPlotConfigurationName(acPlSet, _ "DWF6 ePlot.pc3", _ "ANSI_B_(17.00_x_11.00_Inches)") ' Set to plot to the current display If acLayout.ModelType = False Then acPlSetVdr.SetPlotType(acPlSet, _ DatabaseServices.PlotType.Layout) Else acPlSetVdr.SetPlotType(acPlSet, _ DatabaseServices.PlotType.Extents) acPlSetVdr.SetPlotCentered(acPlSet, True) End If ' Use SetPlotWindowArea with PlotType.Window 'acPlSetVdr.SetPlotWindowArea(plSet, _ ' New Extents2d(New Point2d(0.0, 0.0), _ ' New Point2d(9.0, 12.0))) ' Use SetPlotViewName with PlotType.View 'acPlSetVdr.SetPlotViewName(plSet, "MyView") ' Set the plot offset acPlSetVdr.SetPlotOrigin(acPlSet, _ New Point2d(0, 0)) ' Set the plot scale acPlSetVdr.SetUseStandardScale(acPlSet, True) acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit) acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Inches) acPlSet.ScaleLineweights = True ' Specify if plot styles should be displayed on the layout acPlSet.ShowPlotStyles = True ' Rebuild plotter, plot style, and canonical media lists ' (must be called before setting the plot style) acPlSetVdr.RefreshLists(acPlSet) ' Specify the shaded viewport options acPlSet.ShadePlot = PlotSettingsShadePlotType.AsDisplayed acPlSet.ShadePlotResLevel = ShadePlotResLevel.Normal ' Specify the plot options acPlSet.PrintLineweights = True acPlSet.PlotTransparency = False acPlSet.PlotPlotStyles = True acPlSet.DrawViewportsFirst = True ' Use only on named layouts - Hide paperspace objects option ' plSet.PlotHidden = True ' Specify the plot orientation acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000) ' Set the plot style If acCurDb.PlotStyleMode = True Then acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.ctb") Else acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.stb") End If ' Zoom to show the whole paper acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, True) Catch es As Autodesk.AutoCAD.Runtime.Exception MsgBox(es.Message) End Try ' Save the changes made acTrans.Commit() If createNew = True Then acPlSet.Dispose() End If End Using End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.PlottingServices; // Creates a new page setup or edits the page set if it exists [CommandMethod("CreateOrEditPageSetup")] public static void CreateOrEditPageSetup() { // Get the current document and database, and start a transaction Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { DBDictionary plSets = acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary; DBDictionary vStyles = acTrans.GetObject(acCurDb.VisualStyleDictionaryId, OpenMode.ForRead) as DBDictionary; PlotSettings acPlSet = default(PlotSettings); bool createNew = false; // Reference the Layout Manager LayoutManager acLayoutMgr = LayoutManager.Current; // Get the current layout and output its name in the Command Line window Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead) as Layout; // Check to see if the page setup exists if (plSets.Contains("MyPageSetup") == false) { createNew = true; // Create a new PlotSettings object: // True - model space, False - named layout acPlSet = new PlotSettings(acLayout.ModelType); acPlSet.CopyFrom(acLayout); acPlSet.PlotSettingsName = "MyPageSetup"; acPlSet.AddToPlotSettingsDictionary(acCurDb); acTrans.AddNewlyCreatedDBObject(acPlSet, true); } else { acPlSet = plSets.GetAt("MyPageSetup").GetObject(OpenMode.ForWrite) as PlotSettings; } // Update the PlotSettings object try { PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current; // Set the Plotter and page size acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3", "ANSI_B_(17.00_x_11.00_Inches)"); // Set to plot to the current display if (acLayout.ModelType == false) { acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Layout); } else { acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents); acPlSetVdr.SetPlotCentered(acPlSet, true); } // Use SetPlotWindowArea with PlotType.Window //acPlSetVdr.SetPlotWindowArea(plSet, // new Extents2d(New Point2d(0.0, 0.0), // new Point2d(9.0, 12.0))); // Use SetPlotViewName with PlotType.View //acPlSetVdr.SetPlotViewName(plSet, "MyView"); // Set the plot offset acPlSetVdr.SetPlotOrigin(acPlSet, new Point2d(0, 0)); // Set the plot scale acPlSetVdr.SetUseStandardScale(acPlSet, true); acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit); acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Inches); acPlSet.ScaleLineweights = true; // Specify if plot styles should be displayed on the layout acPlSet.ShowPlotStyles = true; // Rebuild plotter, plot style, and canonical media lists // (must be called before setting the plot style) acPlSetVdr.RefreshLists(acPlSet); // Specify the shaded viewport options acPlSet.ShadePlot = PlotSettingsShadePlotType.AsDisplayed; acPlSet.ShadePlotResLevel = ShadePlotResLevel.Normal; // Specify the plot options acPlSet.PrintLineweights = true; acPlSet.PlotTransparency = false; acPlSet.PlotPlotStyles = true; acPlSet.DrawViewportsFirst = true; // Use only on named layouts - Hide paperspace objects option // plSet.PlotHidden = true; // Specify the plot orientation acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000); // Set the plot style if (acCurDb.PlotStyleMode == true) { acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.ctb"); } else { acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.stb"); } // Zoom to show the whole paper acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, true); } catch (Autodesk.AutoCAD.Runtime.Exception es) { System.Windows.Forms.MessageBox.Show(es.Message); } // Save the changes made acTrans.Commit(); if (createNew == true) { acPlSet.Dispose(); } } } 将页面设置分配给布局本示例将页面设置分配给当前布局。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.PlottingServices ' Assigns a page setup to a layout <CommandMethod("AssignPageSetupToLayout")> _ Public Shared Sub AssignPageSetupToLayout() ' Get the current document and database, and start a transaction Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() ' Reference the Layout Manager Dim acLayoutMgr As LayoutManager = LayoutManager.Current ' Get the current layout and output its name in the Command Line window Dim acLayout As Layout = _ acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _ OpenMode.ForRead) Dim acPlSet As DBDictionary = _ acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead) ' Check to see if the page setup exists If acPlSet.Contains("MyPageSetup") = True Then Dim plSet As PlotSettings = _ acPlSet.GetAt("MyPageSetup").GetObject(OpenMode.ForRead) ' Update the layout acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite) acLayout.CopyFrom(plSet) ' Save the new objects to the database acTrans.Commit() Else ' Ignore the changes made acTrans.Abort() End If End Using ' Update the display acDoc.Editor.Regen() End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.PlottingServices; // Assigns a page setup to a layout [CommandMethod("AssignPageSetupToLayout")] public static void AssignPageSetupToLayout() { // Get the current document and database, and start a transaction Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Reference the Layout Manager LayoutManager acLayoutMgr = LayoutManager.Current; // Get the current layout and output its name in the Command Line window Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead) as Layout; DBDictionary acPlSet = acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, OpenMode.ForRead) as DBDictionary; // Check to see if the page setup exists if (acPlSet.Contains("MyPageSetup") == true) { PlotSettings plSet = acPlSet.GetAt("MyPageSetup").GetObject(OpenMode.ForRead) as PlotSettings; // Update the layout acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite); acLayout.CopyFrom(plSet); // Save the new objects to the database acTrans.Commit(); } else { // Ignore the changes made acTrans.Abort(); } } // Update the display acDoc.Editor.Regen(); } 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:10
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.