Valued Contributor
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 1 of 3

Plot dwg as pdf crash the drawing

407 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
86 Posts
1 Kudo
Registered: ‎07-14-2010
Post 2 of 3

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
761 Posts
100 Kudos
Registered: ‎03-21-2011
Post 3 of 3

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