Typically, when you plot a large drawing such as a floorplan, you specify a scale to convert the real drawing units into plotted inches or millimeters. However, when you plot from Model space, the defaults that are used if there are no settings specified include plot to system printer, plot the current display, scaled to fit, 0 rotation, and 0,0 offset.
通常情况下,当打印较大的图形时,例如平面布置图,可以指定一个比例将实际图形单位转换为打印英寸或毫米。如果从模型空间打印时未指定设置,则使用默认设置。默认设置包括打印到系统打印机、打印当前显示、缩放到充满、0 旋转和 0,0 偏移。
You use a PlotSettings object to modify the plot settings of the layout to plot, and then validate the plot settings with a PlotSettingsValidatorobject before passing the PlotSettings object to a PlotInfo object. Once the Plot Info object is defined, you use a PlotEngine object to output create the plot and pass to it the PlotInfo object that contains the information of the sheet or layout to plot.
要修改用于打印的布局的打印设置可以使用 PlotSettings 对象,然后在传递 PlotSettings 对象给 PlotInfo 对象之前使用 PlotSettingsValidatorobject 验证打印设置。只要打印信息被定义,用户就可以使用 PlotEngine 对象输出创建的图和传递给它的 PlotInfo 对象,它包含图形和打印布局的信息。
This example establishes several plot settings before generating the final plot. The output generated is a DWF file named Myplot. Before running this example, you might want to add some objects to Model space first.
本样例在生成最终的打印图之前确定了几个打印设置。输出生成的 DWF 文件被命名为 Myplot。在运行本例前,用户首先需要添加几个对象到模型空间中去。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.PlottingServices
<CommandMethod("PlotCurrentLayout")> _
Public Sub PlotCurrentLayout()
''获得当前文档和数据库,并启动一个事务 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)
'' 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 PlotSettings object
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
'' Set the plot type
acPlSetVdr.SetPlotType(acPlSet, _
Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'' Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, True)
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)
'' Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, True)
'' Set the plot device to use
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3", _
"ANSI_A_(8.50_x_11.00_Inches)")
'' Set the plot info as an override since it will
'' not be saved back to the layout
acPlInfo.OverrideSettings = acPlSet
'' Validate the plot info
Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVdr.Validate(acPlInfo)
'' Check to see if a plot is already in progress
If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices. _
ProcessPlotState.NotPlotting Then
Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine()
'' Track the plot progress with a Progress dialog
Dim acPlProgDlg As PlotProgressDialog = New PlotProgressDialog(False, _
1, _
True)
Using (acPlProgDlg)
'' Define the status messages to display when plotting starts
acPlProgDlg.PlotMsgString(PlotMessageIndex.DialogTitle) = _
"Plot Progress"
acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = _
"Cancel Job"
acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = _
"Cancel Sheet"
acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = _
"Sheet Set Progress"
acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = _
"Sheet Progress"
'' Set the plot progress range
acPlProgDlg.LowerPlotProgressRange = 0
acPlProgDlg.UpperPlotProgressRange = 100
acPlProgDlg.PlotProgressPos = 0
'' Display the Progress dialog
acPlProgDlg.OnBeginPlot()
acPlProgDlg.IsVisible = True
'' Start to plot the layout
acPlEng.BeginPlot(acPlProgDlg, Nothing)
'' Define the plot output
acPlEng.BeginDocument(acPlInfo, _
acDoc.Name, _
Nothing, _
1, _
True, _
"c:\myplot")
'' Display information about the current plot
acPlProgDlg.PlotMsgString(PlotMessageIndex.Status) = _
"Plotting: " & acDoc.Name & _
" - " & acLayout.LayoutName
'' Set the sheet progress range
acPlProgDlg.OnBeginSheet()
acPlProgDlg.LowerSheetProgressRange = 0
acPlProgDlg.UpperSheetProgressRange = 100
acPlProgDlg.SheetProgressPos = 0
'' Plot the first sheet/layout
Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo()
acPlEng.BeginPage(acPlPageInfo, _
acPlInfo, _
True, _
Nothing)
acPlEng.BeginGenerateGraphics(Nothing)
acPlEng.EndGenerateGraphics(Nothing)
'' Finish plotting the sheet/layout
acPlEng.EndPage(Nothing)
acPlProgDlg.SheetProgressPos = 100
acPlProgDlg.OnEndSheet()
'' Finish plotting the document
acPlEng.EndDocument(Nothing)
'' Finish the plot
acPlProgDlg.PlotProgressPos = 100
acPlProgDlg.OnEndPlot()
acPlEng.EndPlot(Nothing)
End Using
End Using
End If
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.PlottingServices;
[CommandMethod("PlotCurrentLayout")]
public static void PlotCurrentLayout()
{
// 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;
// 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 PlotSettings object
PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
// Set the plot type
acPlSetVdr.SetPlotType(acPlSet,
Autodesk.AutoCAD.DatabaseServices.PlotType.Extents);
// Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, true);
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit);
// Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, true);
// Set the plot device to use
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3",
"ANSI_A_(8.50_x_11.00_Inches)");
// Set the plot info as an override since it will
// not be saved back to the layout
acPlInfo.OverrideSettings = acPlSet;
// Validate the plot info
PlotInfoValidator acPlInfoVdr = new PlotInfoValidator();
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
acPlInfoVdr.Validate(acPlInfo);
// Check to see if a plot is already in progress
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
using (PlotEngine acPlEng = PlotFactory.CreatePublishEngine())
{
// Track the plot progress with a Progress dialog
PlotProgressDialog acPlProgDlg = new PlotProgressDialog(false,
1,
true);
using (acPlProgDlg)
{
// Define the status messages to display when plotting starts
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle,
"Plot Progress");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage,
"Cancel Job");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage,
"Cancel Sheet");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption,
"Sheet Set Progress");
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption,
"Sheet Progress");
// Set the plot progress range
acPlProgDlg.LowerPlotProgressRange = 0;
acPlProgDlg.UpperPlotProgressRange = 100;
acPlProgDlg.PlotProgressPos = 0;
// Display the Progress dialog
acPlProgDlg.OnBeginPlot();
acPlProgDlg.IsVisible = true;
// Start to plot the layout
acPlEng.BeginPlot(acPlProgDlg, null);
// Define the plot output
acPlEng.BeginDocument(acPlInfo,
acDoc.Name,
null,
1,
true,
"c:\\myplot");
// Display information about the current plot
acPlProgDlg.set_PlotMsgString(PlotMessageIndex.Status,
"Plotting: " + acDoc.Name + " - " +
acLayout.LayoutName);
// Set the sheet progress range
acPlProgDlg.OnBeginSheet();
acPlProgDlg.LowerSheetProgressRange = 0;
acPlProgDlg.UpperSheetProgressRange = 100;
acPlProgDlg.SheetProgressPos = 0;
// Plot the first sheet/layout
PlotPageInfo acPlPageInfo = new PlotPageInfo();
acPlEng.BeginPage(acPlPageInfo,
acPlInfo,
true,
null);
acPlEng.BeginGenerateGraphics(null);
acPlEng.EndGenerateGraphics(null);
// Finish plotting the sheet/layout
acPlEng.EndPage(null);
acPlProgDlg.SheetProgressPos = 100;
acPlProgDlg.OnEndSheet();
// Finish plotting the document
acPlEng.EndDocument(null);
// Finish the plot
acPlProgDlg.PlotProgressPos = 100;
acPlProgDlg.OnEndPlot();
acPlEng.EndPlot(null);
}
}
}
}
}
The device name can be specified using the ConfigName property. This device can be overridden in the PlotToDevice method by specifying a PC3 file.
设备的名字可以是使用 ConfigName 属性指定。这个设备可以在 PlotToDevice 方法中通过指定 PC3 文件来代替。