.NET

.NET

Reply
Valued Contributor
smcclure
Posts: 60
Registered: ‎06-08-2006
Message 1 of 2 (302 Views)

Plot Using Plot API Produces No Errors, But Does Not Plot

302 Views, 1 Replies
06-08-2006 01:23 PM
Using the code below, I am trying to plot a series of pages to a plotter. Unforunately, the code executes without error but nothing is spooled to the plotter. I have tried plotting to the same plotter with AutoCAD plot, and it works fine. If the plotter didnt exist/was set to "None", the validator should have flagged it, but it always validates (as seen in the msgbox).

If anyone has any suggestions on how to debug this or where the problem is, I would be very grateful.

The code is below:
-----------------------------------------------------------------------------------
[code]
Private Sub Plot()
Dim Acad As Autodesk.AutoCAD.Interop.AcadApplication = Application.AcadApplication
'Change over to MDI mode to plot, then return to existing setting
Dim origSDI As Boolean = Application.AcadApplication.Preferences.System.SingleDocumentMode
Dim plotInfo As PlotInfo = New PlotInfo()
Dim piValidator As PlotInfoValidator = New PlotInfoValidator()
Dim plotSet As PlotSettings = New PlotSettings(True)
Dim plotEngine As PlotEngine = PlotFactory.CreatePublishEngine()
Dim plotDialog As PlotProgressDialog = New PlotProgressDialog(False, lstFiles.SelectedItems.Count, False)
Try

Dim psValidator As PlotSettingsValidator = PlotSettingsValidator.Current()

CommandLinePrompts.Message("DEBUG: Setting PlotInfo layout ID..." & vbNewLine)
'Sets the plot to model space
plotInfo.Layout = LayoutManager.Current.GetLayoutId(MODEL_LAYER_NAME)

CommandLinePrompts.Message("DEBUG: Setting PlotSettings through validator..." & vbNewLine)
'Attempts to find the closest media size to an 11 x 17 sheet,
'matching the physical boundary size (not the printable boundaries)
'psValidator.get
'psValidator.SetClosestMediaName(plotSet, 11, 17, PlotPaperUnit.Inches, False)
'Sets the paper units
psValidator.SetPlotPaperUnits(plotSet, PlotPaperUnit.Inches)
'Set the plotter to plot landscape, upside down
psValidator.SetPlotRotation(plotSet, PlotRotation.TwoSeventyDegrees)
'Sets the boundaries to drawing extents
psValidator.SetPlotType(plotSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'Instructs AutoCAD to use a standard scale (scale to fit), not a custom scale
psValidator.SetUseStandardScale(plotSet, True)
psValidator.SetStdScaleType(plotSet, StdScaleType.ScaleToFit)
'Instructs AutoCAD not to center the plot, and use the given offset
psValidator.SetPlotCentered(plotSet, False)
psValidator.SetPlotOrigin(plotSet, New Point2d(0.0, 0.75))
'Set the style for the plot
psValidator.SetCurrentStyleSheet(plotSet, PLOT_STYLE_NAME)
'Remove reference to the PlotSettingsValidator
psValidator = Nothing
CommandLinePrompts.Message("DEBUG: Setting directly accessible PlotSettings" & vbNewLine)
plotSet.ShadePlot = PlotSettingsShadePlotType.AsDisplayed
'Plot with lineweights
plotSet.PrintLineweights = True
plotSet.ScaleLineweights = False
'Override the plot settings with our own
plotInfo.OverrideSettings = plotSet
CommandLinePrompts.Message("DEBUG: Validating settings..." & vbNewLine)
'validate the plot info
piValidator.Validate(plotInfo)
MsgBox("Validated:" & plotInfo.IsValidated)

Application.AcadApplication.Preferences.System.SingleDocumentMode = False

If plotEngine IsNot Nothing Then
plotDialog.IsVisible = True
plotDialog.OnBeginPlot()
CommandLinePrompts.Message("DEBUG: Beginning plot..." & vbNewLine)
plotEngine.BeginPlot(plotDialog, Nothing)
CommandLinePrompts.Message("DEBUG: Beginning document..." & vbNewLine)
plotEngine.BeginDocument(plotInfo, Acad.ActiveDocument.Name, Nothing, numCopies.Value, False, Nothing)

Dim curItem As Integer
For curItem = 0 To lstFiles.SelectedItems.Count - 1
CommandLinePrompts.Message("DEBUG: Loading file at " & Path.Combine(Acad.ActiveDocument.Path, lstFiles.SelectedItems(curItem)) & "..." & vbNewLine)

Dim filename As String = lstFiles.SelectedItems(curItem)
Dim document As AcadDocument = Acad.Documents.Open((Path.Combine(Acad.ActiveDocument.Path, filename)), True)
CommandLinePrompts.Message("DEBUG: Creating page info..." & vbNewLine)
Dim pageInfo As PlotPageInfo = New PlotPageInfo()

CommandLinePrompts.Message("DEBUG: Setting layout..." & vbNewLine)
'Set the current layout to the model layer
LayoutManager.Current.CurrentLayout = MODEL_LAYER_NAME

CommandLinePrompts.Message("DEBUG: Beginning sheet..." & vbNewLine)
plotDialog.OnBeginSheet()

If (curItem <> lstFiles.SelectedItems.Count - 1) Then
'Not the last page, pass false to signify more pages should be expected
plotEngine.BeginPage(pageInfo, plotInfo, False, Nothing)
Else
CommandLinePrompts.Message("DEBUG: Plotting last page...")
'Last page, pass true to signify document is complete
plotEngine.BeginPage(pageInfo, plotInfo, True, Nothing)
End If

CommandLinePrompts.Message("DEBUG: Beginning to generate graphics..." & vbNewLine)
plotEngine.BeginGenerateGraphics(Nothing)
plotEngine.EndGenerateGraphics(Nothing)
plotEngine.EndPage(Nothing)
plotDialog.OnEndSheet()
document.Close()
Next

plotEngine.EndDocument(Nothing)
plotEngine.EndPlot(Nothing)
plotDialog.OnEndPlot()

'Acad.Documents.Close()
End If
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox("Exception: " & ex.Message & ", Error Code:" & ex.ErrorStatus)
Finally
Application.AcadApplication.Preferences.System.SingleDocumentMode = origSDI
Acad = Nothing
piValidator.Dispose()
plotSet.Dispose()
plotInfo.Dispose()
plotDialog.Dispose()
plotEngine.Dispose()
End Try

End Sub
[/code]

Message was edited by: smcclure Message was edited by: smcclure
Contributor
gepetto143
Posts: 23
Registered: ‎10-06-2005
Message 2 of 2 (302 Views)

Re: Plot Using Plot API Produces No Errors, But Does Not Plot

10-09-2007 11:08 AM in reply to: smcclure
It looks like you forgot to specify the printer you wanted to use.

add this to your code

psValidator.SetPlotConfigurationName(plotSet, Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices(2).DeviceName, "A4")

you can display a list of your printers using something like that
'Dim text As String = ""
'Dim i As Integer
'MessageBox.Show("Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices.Count = " & Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices.Count)
'For i = 1 To Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices.Count
'text = text & "i" & Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices.Item(i).DeviceName & vbNewLine
'MessageBox.Show(text)
'Next

I had to display the "text" in the for because it crashed before reaching the end of the list but it didn't mater because I had already got the device number of my printer
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.