.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plotting - Code errors unless plot command run first.

4 REPLIES 4
Reply
Message 1 of 5
Martin60
373 Views, 4 Replies

Plotting - Code errors unless plot command run first.

I am currently getting an error when setting the CurrentStyleSheet and/or PlotCentered unless I open and close the plot command.
I have compared this code to other examples but cannot see where I am going wtrong.
Thanks in advance.

Public Sub PlottingMain(ByVal sDevice As String, ByVal sPlotServer As String, ByVal sSize As String, ByVal sPlotFile As String, _
ByVal sCTBfile As String, ByVal iArea As Long, ByVal iRotation As Integer, _
Optional ByVal pW1 As VariantType = 0, Optional ByVal pW2 As VariantType = 0, _
Optional ByVal Preview As Integer = 0, Optional ByVal sScale As String = "FIT", _
Optional ByVal bCentre As Boolean = False, Optional ByVal bHide As Boolean = False, _
Optional ByVal lQty As Long = 1, Optional ByVal offX As Double = 0.0, Optional ByVal offY As Double = 0.0)
'plotting function
MsgBox("Plot Type:", MsgBoxStyle.Information, "DEP: PlottingMAIN")
Dim offset(0 To 1)
offset(0) = offX
offset(1) = offY
If Not sDevice Like "*.pc3" Then sDevice = sPlotServer & sDevice
Dim myDWG As ApplicationServices.Document
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument

Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'' Access the Preferences object
''Dim acPrefComObj As AcadPreferences = Application.Preferences
'Dim acPlotComObj As AcadPlot = AcadPlot
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
Debug.Print("PlottingMain Transaction - 01")
acPlSetVdr.SetPlotConfigurationName(acPlSet, sDevice, sSize)

'' 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)


acPlSetVdr.SetCurrentStyleSheet(acPlSet, sCTBfile)


acPlSetVdr.SetPlotCentered(acPlSet, bCentre)

Debug.Print("PlottingMain Transaction - 20")

'' 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 acPlInfoVldr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVldr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVldr.Validate(acPlInfo)
End Using
End Sub
4 REPLIES 4
Message 2 of 5
DeathTiger
in reply to: Martin60

try removing the following
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.
{code}acPlSet.CopyFrom(acLayout){code}
Message 3 of 5
Martin60
in reply to: Martin60

Thanks. I like that solution.
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.
Message 4 of 5
DeathTiger
in reply to: Martin60

I understand how frustrating it can be, and a real pain to debug.

I use the following for driving my PDF and paper plots, it may serve some use to you.

{code}
//Create plot settings
PlotSettings acPS = new PlotSettings(acL.ModelType);

PlotSettingsValidator acPSV = PlotSettingsValidator.Current;
//Plot Sheet Outline (As setup for Office)
//Specify the view name to plot
acPSV.SetPlotViewName(acPS, "Sheet Outline");
acPSV.SetPlotType(acPS, Autodesk.AutoCAD.DatabaseServices.PlotType.View);
//We are Metric, so Millimeters will do nicely
acPSV.SetPlotPaperUnits(acPS, PlotPaperUnit.Millimeters);
acPSV.SetPlotRotation(acPS, PlotRotation.Degrees090);
acPSV.RefreshLists(acPS);

//use a unique scale
acPSV.SetUseStandardScale(acPS, false);
//specify the scale (note, must convert the 1:mm value to 1:in)
acPSV.SetCustomPrintScale(acPS, new CustomScale(1.0, GT_Math.GT_MiliToInch(iScale)));
//Center the plot... da
acPSV.SetPlotCentered(acPS, true);

//If the System Variable 'PSTYLEMODE' is set to 1, we need to use .ctb settings
if (Convert.ToInt16(Application.GetSystemVariable("PSTYLEMODE")) == 1)
{
acPSV.SetCurrentStyleSheet(acPS, sPens + ".ctb");
}
//else use .stb settings
else
{
acPSV.SetCurrentStyleSheet(acPS, sPens + ".stb");
}

//specify the device name and media
acPSV.SetPlotConfigurationName(acPS, sDevice, sMedia);

//reference of the layout to plot
acPI.Layout = acL.Id;

//Overide the default plot settings with that specified
acPI.OverrideSettings = acPS;
//Validate all information
acPIV.Validate(acPI);

//If there is only 1 layout to plot
if (iSheetCount == 1)
{
// Define the status messages to display when plotting starts
acPPD.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Plot Progress");
acPPD.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
acPPD.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
acPPD.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
acPPD.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");

// Set the plot progress range
acPPD.LowerPlotProgressRange = 0;
acPPD.UpperPlotProgressRange = 100;
acPPD.PlotProgressPos = 0;

// Display the Progress dialog
acPPD.OnBeginPlot();
acPPD.IsVisible = true;

// Start to plot the layout
acPE.BeginPlot(acPPD, null);

//Begin plotting the document
acPE.BeginDocument(acPI, acDWG.Name, null, 1, false, "");

}

// Set the sheet progress range
acPPD.OnBeginSheet();
acPPD.LowerSheetProgressRange = 0;
acPPD.UpperSheetProgressRange = 100;
acPPD.SheetProgressPos = 0;

// Plot the first sheet/layout
PlotPageInfo acPlPageInfo = new PlotPageInfo();
acPE.BeginPage(acPlPageInfo, acPI, true, null);

acPE.BeginGenerateGraphics(null);
acPE.EndGenerateGraphics(null);

// Finish plotting the sheet/layout
acPE.EndPage(null);
acPPD.SheetProgressPos = 100;
acPPD.OnEndSheet();

// Finish plotting the document
acPE.EndDocument(null);

// Finish the plot
acPPD.PlotProgressPos = 100;
acPPD.OnEndPlot();
acPE.EndPlot(null);

//I Destroy and Dispose so Batching can take place
acPE.Destroy();
acPE.Dispose();
{code}
Message 5 of 5
Martin60
in reply to: Martin60

Thanks
That looks like it will be very handy for what I'm looking at todday

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost