<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Plotting - Code errors unless plot command run first. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591728#M68302</link>
    <description>I am currently getting an error when setting the CurrentStyleSheet and/or PlotCentered unless I open and close the plot command.&lt;BR /&gt;
I have compared this code to other examples but cannot see where I am going wtrong.&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub PlottingMain(ByVal sDevice As String, ByVal sPlotServer As String, ByVal sSize As String, ByVal sPlotFile As String, _&lt;BR /&gt;
                ByVal sCTBfile As String, ByVal iArea As Long, ByVal iRotation As Integer, _&lt;BR /&gt;
                Optional ByVal pW1 As VariantType = 0, Optional ByVal pW2 As VariantType = 0, _&lt;BR /&gt;
                Optional ByVal Preview As Integer = 0, Optional ByVal sScale As String = "FIT", _&lt;BR /&gt;
                Optional ByVal bCentre As Boolean = False, Optional ByVal bHide As Boolean = False, _&lt;BR /&gt;
                Optional ByVal lQty As Long = 1, Optional ByVal offX As Double = 0.0, Optional ByVal offY As Double = 0.0)&lt;BR /&gt;
        'plotting function&lt;BR /&gt;
        MsgBox("Plot Type:", MsgBoxStyle.Information, "DEP: PlottingMAIN")&lt;BR /&gt;
        Dim offset(0 To 1)&lt;BR /&gt;
        offset(0) = offX&lt;BR /&gt;
        offset(1) = offY&lt;BR /&gt;
        If Not sDevice Like "*.pc3" Then sDevice = sPlotServer &amp;amp; sDevice&lt;BR /&gt;
        Dim myDWG As ApplicationServices.Document&lt;BR /&gt;
        myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim acCurDb As Database = acDoc.Database&lt;BR /&gt;
        '' Access the Preferences object&lt;BR /&gt;
        ''Dim acPrefComObj As AcadPreferences = Application.Preferences&lt;BR /&gt;
        'Dim acPlotComObj As AcadPlot = AcadPlot&lt;BR /&gt;
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()&lt;BR /&gt;
            '' Reference the Layout Manager&lt;BR /&gt;
            Dim acLayoutMgr As LayoutManager&lt;BR /&gt;
            acLayoutMgr = LayoutManager.Current&lt;BR /&gt;
&lt;BR /&gt;
            '' Get the current layout and output its name in the Command Line window&lt;BR /&gt;
            Dim acLayout As Layout&lt;BR /&gt;
            acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _&lt;BR /&gt;
                                         OpenMode.ForRead)&lt;BR /&gt;
            '' Get the PlotInfo from the layout&lt;BR /&gt;
            Dim acPlInfo As PlotInfo = New PlotInfo()&lt;BR /&gt;
            acPlInfo.Layout = acLayout.ObjectId&lt;BR /&gt;
&lt;BR /&gt;
            '' Get a copy of the plotsettings from the layout&lt;BR /&gt;
            Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)&lt;BR /&gt;
            acPlSet.CopyFrom(acLayout)&lt;BR /&gt;
            '' Update the PlotSettings object&lt;BR /&gt;
            Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current&lt;BR /&gt;
            Debug.Print("PlottingMain Transaction - 01")&lt;BR /&gt;
            acPlSetVdr.SetPlotConfigurationName(acPlSet, sDevice, sSize)&lt;BR /&gt;
&lt;BR /&gt;
            '' Set the plot type&lt;BR /&gt;
            acPlSetVdr.SetPlotType(acPlSet, _&lt;BR /&gt;
                                   Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)&lt;BR /&gt;
&lt;BR /&gt;
            '' Set the plot scale&lt;BR /&gt;
            acPlSetVdr.SetUseStandardScale(acPlSet, True)&lt;BR /&gt;
            acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            acPlSetVdr.SetCurrentStyleSheet(acPlSet, sCTBfile)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            acPlSetVdr.SetPlotCentered(acPlSet, bCentre)&lt;BR /&gt;
&lt;BR /&gt;
            Debug.Print("PlottingMain Transaction - 20")&lt;BR /&gt;
&lt;BR /&gt;
            '' Set the plot info as an override since it will&lt;BR /&gt;
            '' not be saved back to the layout&lt;BR /&gt;
            acPlInfo.OverrideSettings = acPlSet&lt;BR /&gt;
&lt;BR /&gt;
            '' Validate the plot info&lt;BR /&gt;
            Dim acPlInfoVldr As PlotInfoValidator = New PlotInfoValidator()&lt;BR /&gt;
            acPlInfoVldr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled&lt;BR /&gt;
            acPlInfoVldr.Validate(acPlInfo)          &lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub</description>
    <pubDate>Thu, 19 Nov 2009 03:48:18 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-11-19T03:48:18Z</dc:date>
    <item>
      <title>Plotting - Code errors unless plot command run first.</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591728#M68302</link>
      <description>I am currently getting an error when setting the CurrentStyleSheet and/or PlotCentered unless I open and close the plot command.&lt;BR /&gt;
I have compared this code to other examples but cannot see where I am going wtrong.&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub PlottingMain(ByVal sDevice As String, ByVal sPlotServer As String, ByVal sSize As String, ByVal sPlotFile As String, _&lt;BR /&gt;
                ByVal sCTBfile As String, ByVal iArea As Long, ByVal iRotation As Integer, _&lt;BR /&gt;
                Optional ByVal pW1 As VariantType = 0, Optional ByVal pW2 As VariantType = 0, _&lt;BR /&gt;
                Optional ByVal Preview As Integer = 0, Optional ByVal sScale As String = "FIT", _&lt;BR /&gt;
                Optional ByVal bCentre As Boolean = False, Optional ByVal bHide As Boolean = False, _&lt;BR /&gt;
                Optional ByVal lQty As Long = 1, Optional ByVal offX As Double = 0.0, Optional ByVal offY As Double = 0.0)&lt;BR /&gt;
        'plotting function&lt;BR /&gt;
        MsgBox("Plot Type:", MsgBoxStyle.Information, "DEP: PlottingMAIN")&lt;BR /&gt;
        Dim offset(0 To 1)&lt;BR /&gt;
        offset(0) = offX&lt;BR /&gt;
        offset(1) = offY&lt;BR /&gt;
        If Not sDevice Like "*.pc3" Then sDevice = sPlotServer &amp;amp; sDevice&lt;BR /&gt;
        Dim myDWG As ApplicationServices.Document&lt;BR /&gt;
        myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;
        Dim acCurDb As Database = acDoc.Database&lt;BR /&gt;
        '' Access the Preferences object&lt;BR /&gt;
        ''Dim acPrefComObj As AcadPreferences = Application.Preferences&lt;BR /&gt;
        'Dim acPlotComObj As AcadPlot = AcadPlot&lt;BR /&gt;
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()&lt;BR /&gt;
            '' Reference the Layout Manager&lt;BR /&gt;
            Dim acLayoutMgr As LayoutManager&lt;BR /&gt;
            acLayoutMgr = LayoutManager.Current&lt;BR /&gt;
&lt;BR /&gt;
            '' Get the current layout and output its name in the Command Line window&lt;BR /&gt;
            Dim acLayout As Layout&lt;BR /&gt;
            acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _&lt;BR /&gt;
                                         OpenMode.ForRead)&lt;BR /&gt;
            '' Get the PlotInfo from the layout&lt;BR /&gt;
            Dim acPlInfo As PlotInfo = New PlotInfo()&lt;BR /&gt;
            acPlInfo.Layout = acLayout.ObjectId&lt;BR /&gt;
&lt;BR /&gt;
            '' Get a copy of the plotsettings from the layout&lt;BR /&gt;
            Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)&lt;BR /&gt;
            acPlSet.CopyFrom(acLayout)&lt;BR /&gt;
            '' Update the PlotSettings object&lt;BR /&gt;
            Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current&lt;BR /&gt;
            Debug.Print("PlottingMain Transaction - 01")&lt;BR /&gt;
            acPlSetVdr.SetPlotConfigurationName(acPlSet, sDevice, sSize)&lt;BR /&gt;
&lt;BR /&gt;
            '' Set the plot type&lt;BR /&gt;
            acPlSetVdr.SetPlotType(acPlSet, _&lt;BR /&gt;
                                   Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)&lt;BR /&gt;
&lt;BR /&gt;
            '' Set the plot scale&lt;BR /&gt;
            acPlSetVdr.SetUseStandardScale(acPlSet, True)&lt;BR /&gt;
            acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            acPlSetVdr.SetCurrentStyleSheet(acPlSet, sCTBfile)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
            acPlSetVdr.SetPlotCentered(acPlSet, bCentre)&lt;BR /&gt;
&lt;BR /&gt;
            Debug.Print("PlottingMain Transaction - 20")&lt;BR /&gt;
&lt;BR /&gt;
            '' Set the plot info as an override since it will&lt;BR /&gt;
            '' not be saved back to the layout&lt;BR /&gt;
            acPlInfo.OverrideSettings = acPlSet&lt;BR /&gt;
&lt;BR /&gt;
            '' Validate the plot info&lt;BR /&gt;
            Dim acPlInfoVldr As PlotInfoValidator = New PlotInfoValidator()&lt;BR /&gt;
            acPlInfoVldr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled&lt;BR /&gt;
            acPlInfoVldr.Validate(acPlInfo)          &lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub</description>
      <pubDate>Thu, 19 Nov 2009 03:48:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591728#M68302</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T03:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting - Code errors unless plot command run first.</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591729#M68303</link>
      <description>try removing the following&lt;BR /&gt;
I've had errors where there is no plot setup for the current layout, and I've attempted to grab it through the same code (listed below).  If you manually set the required settings you will find that it will plot without error.&lt;BR /&gt;
{code}acPlSet.CopyFrom(acLayout){code}</description>
      <pubDate>Thu, 19 Nov 2009 08:58:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591729#M68303</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T08:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting - Code errors unless plot command run first.</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591730#M68304</link>
      <description>Thanks. I like that solution.&lt;BR /&gt;
I intended to set everything manually but as I'm new to VB.Net I am in the phase of adapting whatever samples I can find.</description>
      <pubDate>Thu, 19 Nov 2009 21:12:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591730#M68304</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T21:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting - Code errors unless plot command run first.</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591731#M68305</link>
      <description>I understand how frustrating it can be, and a real pain to debug.&lt;BR /&gt;
&lt;BR /&gt;
I use the following for driving my PDF and paper plots, it may serve some use to you.&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
//Create plot settings&lt;BR /&gt;
PlotSettings acPS = new PlotSettings(acL.ModelType);&lt;BR /&gt;
&lt;BR /&gt;
PlotSettingsValidator acPSV = PlotSettingsValidator.Current;&lt;BR /&gt;
//Plot Sheet Outline (As setup for Office)&lt;BR /&gt;
//Specify the view name to plot&lt;BR /&gt;
acPSV.SetPlotViewName(acPS, "Sheet Outline");&lt;BR /&gt;
acPSV.SetPlotType(acPS, Autodesk.AutoCAD.DatabaseServices.PlotType.View);&lt;BR /&gt;
//We are Metric, so Millimeters will do nicely&lt;BR /&gt;
acPSV.SetPlotPaperUnits(acPS, PlotPaperUnit.Millimeters);&lt;BR /&gt;
acPSV.SetPlotRotation(acPS, PlotRotation.Degrees090);&lt;BR /&gt;
acPSV.RefreshLists(acPS);&lt;BR /&gt;
&lt;BR /&gt;
//use a unique scale&lt;BR /&gt;
acPSV.SetUseStandardScale(acPS, false);&lt;BR /&gt;
//specify the scale (note, must convert the 1:mm value to 1:in)&lt;BR /&gt;
acPSV.SetCustomPrintScale(acPS, new CustomScale(1.0, GT_Math.GT_MiliToInch(iScale)));&lt;BR /&gt;
//Center the plot... da&lt;BR /&gt;
acPSV.SetPlotCentered(acPS, true);&lt;BR /&gt;
&lt;BR /&gt;
//If the System Variable 'PSTYLEMODE' is set to 1, we need to use .ctb settings&lt;BR /&gt;
if (Convert.ToInt16(Application.GetSystemVariable("PSTYLEMODE")) == 1)&lt;BR /&gt;
{&lt;BR /&gt;
    acPSV.SetCurrentStyleSheet(acPS, sPens + ".ctb");&lt;BR /&gt;
}&lt;BR /&gt;
//else use .stb settings&lt;BR /&gt;
else&lt;BR /&gt;
{&lt;BR /&gt;
    acPSV.SetCurrentStyleSheet(acPS, sPens + ".stb");&lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
//specify the device name and media&lt;BR /&gt;
acPSV.SetPlotConfigurationName(acPS, sDevice, sMedia);&lt;BR /&gt;
&lt;BR /&gt;
//reference of the layout to plot&lt;BR /&gt;
acPI.Layout = acL.Id;&lt;BR /&gt;
&lt;BR /&gt;
//Overide the default plot settings with that specified&lt;BR /&gt;
acPI.OverrideSettings = acPS;&lt;BR /&gt;
//Validate all information&lt;BR /&gt;
acPIV.Validate(acPI);&lt;BR /&gt;
&lt;BR /&gt;
//If there is only 1 layout to plot&lt;BR /&gt;
if (iSheetCount == 1)&lt;BR /&gt;
{&lt;BR /&gt;
    // Define the status messages to display when plotting starts&lt;BR /&gt;
    acPPD.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Plot Progress");&lt;BR /&gt;
    acPPD.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");&lt;BR /&gt;
    acPPD.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");&lt;BR /&gt;
    acPPD.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");&lt;BR /&gt;
    acPPD.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");&lt;BR /&gt;
&lt;BR /&gt;
    // Set the plot progress range&lt;BR /&gt;
    acPPD.LowerPlotProgressRange = 0;&lt;BR /&gt;
    acPPD.UpperPlotProgressRange = 100;&lt;BR /&gt;
    acPPD.PlotProgressPos = 0;&lt;BR /&gt;
&lt;BR /&gt;
    // Display the Progress dialog&lt;BR /&gt;
    acPPD.OnBeginPlot();&lt;BR /&gt;
    acPPD.IsVisible = true;&lt;BR /&gt;
&lt;BR /&gt;
    // Start to plot the layout&lt;BR /&gt;
    acPE.BeginPlot(acPPD, null);&lt;BR /&gt;
&lt;BR /&gt;
    //Begin plotting the document&lt;BR /&gt;
    acPE.BeginDocument(acPI, acDWG.Name, null, 1, false, "");&lt;BR /&gt;
  &lt;BR /&gt;
}&lt;BR /&gt;
&lt;BR /&gt;
// Set the sheet progress range&lt;BR /&gt;
acPPD.OnBeginSheet();&lt;BR /&gt;
acPPD.LowerSheetProgressRange = 0;&lt;BR /&gt;
acPPD.UpperSheetProgressRange = 100;&lt;BR /&gt;
acPPD.SheetProgressPos = 0;&lt;BR /&gt;
&lt;BR /&gt;
// Plot the first sheet/layout&lt;BR /&gt;
PlotPageInfo acPlPageInfo = new PlotPageInfo();&lt;BR /&gt;
acPE.BeginPage(acPlPageInfo, acPI, true, null);&lt;BR /&gt;
&lt;BR /&gt;
acPE.BeginGenerateGraphics(null);&lt;BR /&gt;
acPE.EndGenerateGraphics(null);&lt;BR /&gt;
&lt;BR /&gt;
// Finish plotting the sheet/layout&lt;BR /&gt;
acPE.EndPage(null);&lt;BR /&gt;
acPPD.SheetProgressPos = 100;&lt;BR /&gt;
acPPD.OnEndSheet();&lt;BR /&gt;
&lt;BR /&gt;
// Finish plotting the document&lt;BR /&gt;
acPE.EndDocument(null);&lt;BR /&gt;
&lt;BR /&gt;
// Finish the plot&lt;BR /&gt;
acPPD.PlotProgressPos = 100;&lt;BR /&gt;
acPPD.OnEndPlot();&lt;BR /&gt;
acPE.EndPlot(null);&lt;BR /&gt;
&lt;BR /&gt;
//I Destroy and Dispose so Batching can take place&lt;BR /&gt;
acPE.Destroy();&lt;BR /&gt;
acPE.Dispose();&lt;BR /&gt;
{code}</description>
      <pubDate>Thu, 19 Nov 2009 21:26:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591731#M68305</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T21:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Plotting - Code errors unless plot command run first.</title>
      <link>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591732#M68306</link>
      <description>Thanks&lt;BR /&gt;
That looks like it will be very handy for what I'm looking at todday</description>
      <pubDate>Thu, 19 Nov 2009 21:55:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/plotting-code-errors-unless-plot-command-run-first/m-p/2591732#M68306</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T21:55:34Z</dc:date>
    </item>
  </channel>
</rss>

