The following example shows how to query and change the device of the current layout.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices
<CommandMethod("ChangePlotSetting")> _
Public Sub ChangePlotSetting()
'' 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
acLayoutMgr = LayoutManager.Current
'' Get the current layout and output its name in the Command Line window
Dim acLayout As Layout
acLayout = 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 the PlotInfo from the layout
Dim acPlInfo As PlotInfo = New PlotInfo()
acPlInfo.Layout = acLayout.ObjectId
'' Get a copy of the PlotSettings from the layout
Dim 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, "DWF6 ePlot.pc3", _
"ANSI_A_(8.50_x_11.00_Inches)")
'' Update the layout
acLayout.UpgradeOpen()
acLayout.CopyFrom(acPlSet)
'' 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
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
[CommandMethod("ChangePlotSetting")]
public static void ChangePlotSetting()
{
// 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;
acLayoutMgr = LayoutManager.Current;
// Get the current layout and output its name in the Command Line window
Layout acLayout;
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 the PlotInfo from the layout
PlotInfo acPlInfo = new PlotInfo();
acPlInfo.Layout = acLayout.ObjectId;
// Get a copy of the PlotSettings from the layout
PlotSettings acPlSet = new PlotSettings(acLayout.ModelType);
acPlSet.CopyFrom(acLayout);
// Update the PlotConfigurationName property of the PlotSettings object
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3",
"ANSI_A_(8.50_x_11.00_Inches)");
// Update the layout
acLayout.UpgradeOpen();
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();
}
}