Hey Guys,
I've written a plotting routine, based on the many examples out there. However I can not get it to execute when it is a multi page plot.
When it goes to print the second page it throws an error "eIncompatiblePlotSettings" when it comes to validating the Plot info "PlotInfoVal.Validate(PlotInfo)"
However either page can be ploted with the same routine.
I would really appreciated any help.
Private Sub Print()
Dim InitialLayOutName As String = Nothing
Try
' Using AcTrans As Transaction = AcDB.TransactionManager.StartTransaction
'Dim BlkTbl As BlockTable = DirectCast(AcTrans.GetObject(AcDB.BlockTableId, OpenMode.ForRead), BlockTable)
Dim PlotInfo As New PlotInfo
Dim PlotInfoVal As New PlotInfoValidator
PlotInfoVal.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
If PlotFactory.ProcessPlotState = ProcessPlotState.NotPlotting Then
Using PlotEng As PlotEngine = PlotFactory.CreatePublishEngine()
Using PlotProgressDia As New PlotProgressDialog(False, 1, True)
Dim ShtCount As Integer = 1
MuliSettings.Reverse()
For Each myPrintSettings As Flw_PrintSettings In MuliSettings
Dim PlotSettings As New PlotSettings(myPrintSettings.Layout.ModelType) 'This is the page setup settings
Dim PlotSettingsVal As PlotSettingsValidator = PlotSettingsValidator.Current
PlotSettings.CopyFrom(myPrintSettings.Layout) 'Use existing settings in model/paper space as template
If myPrintSettings.PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Window Then
PlotSettingsVal.SetPlotWindowArea(PlotSettings, myPrintSettings.Window)
End If
PlotSettingsVal.SetPlotType(PlotSettings, myPrintSettings.PlotType) 'Sets if its extends,display or window
PlotSettingsVal.SetStdScaleType(PlotSettings, StdScaleType.ScaleToFit) 'Scales image to fix paper
PlotSettingsVal.SetUseStandardScale(PlotSettings, True)
PlotSettingsVal.SetPlotCentered(PlotSettings, True) 'Center plot on paper
'This controls what ctb file you use.
Try
For Each CTB As String In PlotSettingsVal.GetPlotStyleSheetList() 'you need to do this, or refesh the list otherwise error
If myPrintSettings.CTBFile.ToUpper = CTB.ToUpper Then
PlotSettingsVal.SetCurrentStyleSheet(PlotSettings, CTB)
Exit For
End If
Next
'Dim CTB_Path_File As String = HostApplicationServices.Current.FindFile(SheetPath & "\" & myPrintSettings.CTBFile, AcDB, FindFileHint.Default)
'If CTB_Path_File IsNot Nothing AndAlso Not String.IsNullOrEmpty(CTB_Path_File) Then
' 'PlotSettings.CurrentStyleSheet
' PlotSettingsVal.SetCurrentStyleSheet(PlotSettings, CTB_Path_File)
' ' PlotSettingsVal.SetCurrentStyleSheet(PlotSettings, myPrintSettings.CTBFile) 'This controls what ctb file you use.
'Else
' PlotSettingsVal.SetCurrentStyleSheet(PlotSettings, "")
'End If
Catch
MsgBox("You do not have the standards CTB files")
End Try
'PlotSettingsVal.GetPlotDeviceList() 'Gets avalible printing devices
'PlotSettingsVal.GetCanonicalMediaNameList(PlotSettings) 'Gets avalible paper size
PlotSettingsVal.SetPlotConfigurationName(PlotSettings, myPrintSettings.PrinterName, myPrintSettings.PaperSize) 'Sets what printer & paper you want
If myPrintSettings.Layout.LayoutName <> LayoutManager.Current.CurrentLayout Then 'Changes layout to active
If InitialLayOutName Is Nothing Then
InitialLayOutName = LayoutManager.Current.CurrentLayout
End If
LayoutManager.Current.CurrentLayout = myPrintSettings.Layout.LayoutName
End If
PlotInfo.Layout = myPrintSettings.Layout.Id
PlotInfo.OverrideSettings = PlotSettings
PlotInfoVal.Validate(PlotInfo)
If ShtCount = 1 Then
'Set up the progress dialogue box
PlotProgressDia.PlotMsgString(PlotMessageIndex.DialogTitle) = "Outotec Quick Print Progress"
PlotProgressDia.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = "Cancel Job"
PlotProgressDia.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = "Cancel Sheet"
PlotProgressDia.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = "Sheet Set Progress"
PlotProgressDia.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = "Sheet Progress"
PlotProgressDia.LowerPlotProgressRange = 0
PlotProgressDia.UpperPlotProgressRange = 100
PlotProgressDia.PlotProgressPos = 0
' Let's start the plot
PlotProgressDia.OnBeginPlot()
PlotProgressDia.IsVisible = True
PlotEng.BeginPlot(PlotProgressDia, Nothing)
' We'll be plotting muliple sheets to a document
PlotEng.BeginDocument(PlotInfo, AcDoc.Name, Nothing, 1, True, myPrintSettings.Output)
End If
PlotProgressDia.StatusMsgString = "Printing files"
PlotProgressDia.OnBeginSheet()
PlotProgressDia.LowerSheetProgressRange = 0
PlotProgressDia.UpperSheetProgressRange = 100
PlotProgressDia.SheetProgressPos = 0
Dim PlPageInfo As New PlotPageInfo()
PlotEng.BeginPage(PlPageInfo, PlotInfo, (ShtCount = MuliSettings.Count), Nothing)
PlotEng.BeginGenerateGraphics(Nothing)
PlotProgressDia.SheetProgressPos = 50
PlotEng.EndGenerateGraphics(Nothing)
' Finish the sheet
PlotEng.EndPage(Nothing)
PlotProgressDia.SheetProgressPos = 100
PlotProgressDia.OnEndSheet()
ShtCount += 1
Next
' Finish the document
PlotEng.EndDocument(Nothing)
' And finish the plot
PlotProgressDia.PlotProgressPos = 100
PlotProgressDia.OnEndPlot()
PlotEng.EndPlot(Nothing)
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbCr & "Print successful")
End Using
End Using
Else
MsgBox(vbLf & "Another plot is in progress.")
End If
' End Using
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
If InitialLayOutName IsNot Nothing Then
LayoutManager.Current.CurrentLayout = InitialLayOutName 'return active space to normal
End If
End Try
End Sub