I desparately need help...I'm working on a batch plot manager in vb.net. I found this code on the posts here and modified it to accomidate my program.
The problem is that my program will loop through the selecteditems of a listbox and I know the loop works properly...It will successfully plot each time but it plots the same drawing each time though.
I'm not exactly sure how to specify what open drawing to plot...Is it the plotsettings object, the validator. I thought is was drawing name that is passed to the BeginDocument method, but I've debuged what is passed to the method and it works properly.
The idea of my program is that the user can manually select what open drawings to plot and what settings to use.
The odd thing is that the print queue in windows shows the unique filenames of the each drawing when plotting but the same page plots each time.
Any thoughts?? Any suggestions would be greatly appreciated.
Dim i As Integer, iDocs As Integer
Dim bFound As Boolean
Dim dOrigin(0 To 1) As Double
Dim bReturnVal As Boolean
Dim acadDocument As Autodesk.AutoCAD.ApplicationServices.Document
Dim strSelectedDrawing As String
Dim strPlotFilename As String
'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
Dim plotEngine As PlotEngine = PlotFactory.CreatePublishEngine
Dim plotDialog As PlotProgressDialog = New PlotProgressDialog(False, 1, False)
Dim strListItem As String
Dim pmDrawing As pmDrawingRecord
'Change over to MDI mode to plot, then return to existing setting
Dim psValidator As PlotSettingsValidator
For Each strListItem In lstDrawings.SelectedItems
For Each pmDrawing In pmOpenDrawings
If strListItem.StartsWith(pmDrawing.strName) = True Then
Exit For
End If
Next
For Each acadDocument In acadApp.DocumentManager
If pmDrawing.strName = acadDocument.Name Then
Exit For
End If
Next
plotSet = New PlotSettings(True)
psValidator = PlotSettingsValidator.Current
'Sets the plot to model space
'MsgBox("Layouts: " & LayoutManager.Current.LayoutCount)
plotInfo.Layout = LayoutManager.Current.GetLayoutId("Model")
psValidator.SetPlotConfigurationName(plotSet, cboDeviceName.Text, cboPaperSize.Text)
'Sets the paper units
psValidator.SetPlotPaperUnits(plotSet, PlotPaperUnit.Inches)
'Set the plotter to plot landscape, upside down
psValidator.SetPlotRotation(plotSet, PlotRotation.Degrees090)
'Sets the boundaries to drawing extents
psValidator.SetPlotType(plotSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'psValidator.SetPlotWindowArea(plotSet, extents1)
'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, True)
'psValidator.SetPlotOrigin(plotSet, New Point2d(0.0, 0.75))
'Set the style for the plot
psValidator.SetCurrentStyleSheet(plotSet, cboPen.Text)
'Remove reference to the PlotSettingsValidator
psValidator = Nothing
plotSet.ShadePlot = PlotSettingsShadePlotType.AsDisplayed
'Plot with lineweights
plotSet.PrintLineweights = True
plotSet.ScaleLineweights = False
'Override the plot settings with our own
plotInfo.OverrideSettings = plotSet
'validate the plot info
piValidator.Validate(plotInfo)
MsgBox("Validated:" & plotInfo.IsValidated)
'pivalidator.
'Application.AcadApplication.Preferences.System.SingleDocumentMode = False
If plotEngine IsNot Nothing Then
plotDialog.IsVisible = True
plotDialog.OnBeginPlot()
plotEngine.BeginPlot(plotDialog, Nothing)
plotEngine.BeginDocument(plotInfo, pmDrawing.strName, Nothing, 1, False, Nothing)
'Dim curItem As Integer
'For curItem = 0 To lstFiles.SelectedItems.Count - 1
acadDocument.LockDocument()
Dim filename As String '= lstFiles.SelectedItems(curItem)
'Dim document As acadApp = Acad.Documents.Open((Path.Combine(Acad.ActiveDocument.Path, filename)), True)
Dim pageInfo As PlotPageInfo = New PlotPageInfo()
'Set the current layout to the model layer
LayoutManager.Current.CurrentLayout = "Model"
plotDialog.OnBeginSheet()
plotEngine.BeginPage(pageInfo, plotInfo, True, Nothing)
plotEngine.BeginGenerateGraphics(Nothing)
plotEngine.EndGenerateGraphics(Nothing)
plotEngine.EndPage(Nothing)
plotDialog.OnEndSheet()
plotEngine.EndDocument(Nothing)
plotEngine.EndPlot(Nothing)
plotDialog.OnEndPlot()
End If
plotSet.Dispose()
Next
piValidator.Dispose()
plotInfo.Dispose()
plotDialog.Dispose()
plotEngine.Dispose()