Author Topic: Plotting Error  (Read 1589 times)

0 Members and 1 Guest are viewing this topic.

flowerrobot

  • Guest
Plotting Error
« on: April 19, 2013, 12:30:57 AM »
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.

Code: [Select]
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

n.yuan

  • Bull Frog
  • Posts: 278
Re: Plotting Error
« Reply #1 on: April 19, 2013, 10:36:05 AM »
If the layouts (each becomes a page in your multi-page plotting (to PDF, I suppose, because Autodesk.AutoCAD.PlottingServices namespace does not support DWF/DWFX multiple page plotting) are in different sizes, then the error is expected. That is, with Autodesk.AutoCAD.PlottingServices namespace, yes, you can plot to multiple PDF page only when all the pages to be plotted are in the same size.

If you have read Kean's blog articles on plotting, one of them was about doing multi-page plotting, and there are quite long comments listed, in which this issue is mentioned. It was a couple of years ago. I am not sure if this has been fixed (or even if it made into the wish list or not) in latest release (Acad2014). I just done a quite complicated plotting to PDF/DWFx development with Acad2012 not long ago and dealt with the same issue.

As workaround for multiple page plotting, you may use Autodesk.AutoCAD.Publishing namespace. Or, if it is PDF, then you can plot single page PDF on each layout, and then write some code to merge the PDF (fairly easy task, if you seach the Internet) into multiple page PDF file.

flowerrobot

  • Guest
Re: Plotting Error
« Reply #2 on: April 25, 2013, 06:35:08 PM »
Thanks Yuan,
In this case will only be printing to PDF & Printers, I looked at all the issues you pointed out, and revised the code to suite, However I was still receiving the error.

I have managed to isolate it, Its that i'm plotting a Model & a Paper space item.  If i plot two+ Paper space items its fine.

I too am using ACAD2012, did you come across this error to different space printing?

gile

  • Water Moccasin
  • Posts: 2233
  • Marseille, France
Re: Plotting Error
« Reply #3 on: April 26, 2013, 12:50:30 AM »
Hi,

You can have a look here. It's a way using a temporary DSD file.
Speaking English as a French Frog