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