.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plot dwg as pdf crash the drawing

2 REPLIES 2
Reply
Message 1 of 3
yaqiz
668 Views, 2 Replies

Plot dwg as pdf crash the drawing

Hi Guys,

 

I try to plot the current drawing as pdf file. I took Kean's code from his blog. The function didn't throw any exception. How ever after the function finished the drawing crash.

 

Here is my code segment

 <CommandMethod("pdfTest")> _
    Public Sub PDFTest()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database

        Using tr As Transaction = db.TransactionManager.StartTransaction
            Try

                Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead)

                Dim lo As Layout = tr.GetObject(btr.LayoutId, OpenMode.ForRead)

                '--We need a PlotInfo object
                '--linked to the layout
                Dim pi As New PlotInfo
                pi.Layout = btr.LayoutId

                '--We need a PlotSettings object
                '-- based on the layout settings
                '--which we then customize
                Dim ps As PlotSettings = New PlotSettings(lo.ModelType)
                ps.CopyFrom(lo)

                Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current

                '--We'll plot the extents, centered and 
                '--scaled to fit
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
                psv.SetUseStandardScale(ps, True)
                psv.SetStdScaleType(ps, StdScaleType.ScaleToFit)
                psv.SetPlotCentered(ps, True)

                '--We'll use the standard PDF PC3, as
                '--for today we're just plotting to file
                psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", "ANSI_A_(8.50_x_11.00_Inches)")

                '--We need to link the PlotInfo to the
                '--PlotSettings and then validate it
                pi.OverrideSettings = ps
                Dim piv As New PlotInfoValidator

                piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
                piv.Validate(pi)

                '--A PlotEngine does the actual plotting
                '--(can also create one for Preview)
                If (PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting) Then

                    Using pe As PlotEngine = PlotFactory.CreatePublishEngine

                        Dim ppd As PlotProgressDialog = New PlotProgressDialog(False, 1, False)
                        ppd.LowerPlotProgressRange = 0
                        ppd.UpperPlotProgressRange = 100
                        ppd.PlotProgressPos = 0
                        ppd.IsVisible = False

                        ppd.OnBeginPlot()
                        ppd.IsVisible = False

                        pe.BeginPlot(ppd, Nothing)
                        pe.BeginDocument(pi, doc.Name, Nothing, 1, True, "c:\pdftest")

                        Dim ppi As New PlotPageInfo
                        pe.BeginPage(ppi, pi, True, Nothing)

                        pe.BeginGenerateGraphics(Nothing)
                        pe.EndGenerateGraphics(Nothing)

                        pe.EndPage(Nothing)

                        pe.EndDocument(Nothing)

                        pe.EndPlot(Nothing)

                        tr.Commit()
                    End Using




                End If

            Catch ex As Exception
                tr.Abort()
                Debug.Print(ex.Message)
            End Try


        End Using
    End Sub

 error

 

How can I solve it?

 

Thanks

 

Yaqi

2 REPLIES 2
Message 2 of 3
yaqiz
in reply to: yaqiz

If the crash haven't happen straight away, it will happen after some time.

Message 3 of 3
Balaji_Ram
in reply to: yaqiz

Hi Yaqi Zhang,

 

Did you try disposing the PlotProgressDialog after you are done with it ?



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost