以下示例演示如何查询和更改当前布局的设备。 VB.NETImports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices
' Changes the plot settings for a layout directly
<CommandMethod("ChangeLayoutPlotSettings")> _
Public Shared Sub ChangeLayoutPlotSettings()
' 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)
' Output the name of the current layout and its device
acDoc.Editor.WriteMessage(vbLf & "Current layout: " & _
acLayout.LayoutName)
acDoc.Editor.WriteMessage(vbLf & "Current device name: " & _
acLayout.PlotConfigurationName)
' Get a copy of the PlotSettings from the layout
Using acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
acPlSet.CopyFrom(acLayout)
' Update the PlotConfigurationName property of the PlotSettings object
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", _
"ANSI_B_(11.00_x_17.00_Inches)")
' Zoom to show the whole paper
acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, True)
' Update the layout
acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite)
acLayout.CopyFrom(acPlSet)
End Using
' Output the name of the new device assigned to the layout
acDoc.Editor.WriteMessage(vbLf & "New device name: " & _
acLayout.PlotConfigurationName)
' Save the new objects to the database
acTrans.Commit()
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;
// Changes the plot settings for a layout directly
[CommandMethod("ChangeLayoutPlotSettings")]
public static void ChangeLayoutPlotSettings()
{
// 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;
// Output the name of the current layout and its device
acDoc.Editor.WriteMessage("\nCurrent layout: " + acLayout.LayoutName);
acDoc.Editor.WriteMessage("\nCurrent device name: " + acLayout.PlotConfigurationName);
// Get a copy of the PlotSettings from the layout
using (PlotSettings acPlSet = new PlotSettings(acLayout.ModelType))
{
acPlSet.CopyFrom(acLayout);
// Update the PlotConfigurationName property of the PlotSettings object
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", "ANSI_B_(11.00_x_17.00_Inches)");
// Zoom to show the whole paper
acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, true);
// Update the layout
acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite);
acLayout.CopyFrom(acPlSet);
}
// Output the name of the new device assigned to the layout
acDoc.Editor.WriteMessage("\nNew device name: " + acLayout.PlotConfigurationName);
// Save the new objects to the database
acTrans.Commit();
}
// Update the display
acDoc.Editor.Regen();
}
VBA/ActiveX 代码参考Public Sub ChangePlotSetting()
Dim layoutObj As AcadLayout
Set layoutObj = ThisDrawing.ActiveLayout
' Output the name of the current layout and its device
ThisDrawing.Utility.Prompt vbLf & "Current layout: " & layoutObj.Name
ThisDrawing.Utility.Prompt vbLf & "Current device name: " & _
layoutObj.ConfigName
' Change the name of the output device for the current layout
layoutObj.RefreshPlotDeviceInfo
layoutObj.ConfigName = "DWF6 ePlot.pc3"
layoutObj.CanonicalMediaName = "ANSI_A_(8.50_x_11.00_Inches)"
' Output the name of the new device assigned to the layout
ThisDrawing.Utility.Prompt vbLf & "Current device name: " & _
layoutObj.ConfigName & vbLf
End Sub
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 17:09
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.