Valued Contributor
Posts: 86
Registered: ‎07-14-2010
Message 1 of 3 (402 Views)

Plot dwg as pdf crash the drawing

402 Views, 2 Replies
09-27-2012 05:50 AM

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

                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)

                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

                '--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.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)





                    End Using

                End If

            Catch ex As Exception
            End Try

        End Using
    End Sub



How can I solve it?





Valued Contributor
Posts: 86
Registered: ‎07-14-2010
Message 2 of 3 (395 Views)

Re: Plot dwg as pdf crash the drawing

09-27-2012 06:22 AM in reply to: yaqiz

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

ADN Support Specialist
Posts: 746
Registered: ‎03-21-2011
Message 3 of 3 (365 Views)

Re: Plot dwg as pdf crash the drawing

10-01-2012 09:13 AM in reply to: yaqiz

Hi Yaqi Zhang,


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

Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.