Plot from Model Space
 
 
 

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.

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.

Plot the extents of the Model layout

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.

VB.NET

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

C#

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);
              }
          }
      }
  }
}
VBA/ActiveX Code Reference

The device name can be specified using the ConfigName property. This device can be overridden in the PlotToDevice method by specifying a PC3 file.