.NET

.NET

Reply
Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 1 of 4 (262 Views)

plot pdf using example code yields no pdf file

262 Views, 3 Replies
05-17-2013 05:52 AM

so I implemented the code from the autodesk developers guide for plotting

(http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a919382...)

 

I made a few minor changes such as making it a sub instead of a command, and commented out a few of the plot settings

 

the routine seems to work except that I don't get a PDF

 

I added the actrans.commit() to see fi that might help = nope.

 

also note that ACF.acdoc & ACF.db in my code replace acdoc & acCurDb in the original code

 

  '<CommandMethod("PlotCurrentLayout")> _
    Public Sub PlotMe(suBpath As String, subFileName As String)

        '' Get the current document and database, and start a transaction

        'Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        'Dim acCurDb As Database = acDoc.Database

        Using acTrans As Transaction = ACF.Db.TransactionManager.StartTransaction()
            '' Reference the Layout Manager
            Dim acLayoutMgr As LayoutManager
            acLayoutMgr = LayoutManager.Current

            '' Get the current layout and output its name in the Command Line window
            Dim acLayout As Layout
            acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForRead)

            '' Get the PlotInfo from the layout
            Dim acPlInfo As PlotInfo = New PlotInfo()
            acPlInfo.Layout = acLayout.ObjectId

            '' Get a copy of the PlotSettings from the layout
            Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
            acPlSet.CopyFrom(acLayout)

            '' Update the PlotSettings object
            Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current

            '' Set the plot type
            'acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)

            '' Set the plot scale
            'acPlSetVdr.SetUseStandardScale(acPlSet, True)
            ' acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)

            '' Center the plot
            ' acPlSetVdr.SetPlotCentered(acPlSet, True)

            '' Set the plot device to use
            'acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)")

            '' Set the plot info as an override since it will
            '' not be saved back to the layout
            acPlInfo.OverrideSettings = acPlSet

            '' Validate the plot info
            Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator()
            acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
            acPlInfoVdr.Validate(acPlInfo)

            '' Check to see if a plot is already in progress
            If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting Then

                Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine()

                    '' Track the plot progress with a Progress dialog
                    Dim acPlProgDlg As PlotProgressDialog = New PlotProgressDialog(False, 1, True)

                    Using (acPlProgDlg)
                        '' Define the status messages to display when plotting starts
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.DialogTitle) = _
                                                                   "Plot Progress"
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = _
                                                                   "Cancel Job"
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = _
                                                                   "Cancel Sheet"
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = _
                                                                   "Sheet Set Progress"
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = _
                                                                   "Sheet Progress"

                        '' Set the plot progress range
                        acPlProgDlg.LowerPlotProgressRange = 0
                        acPlProgDlg.UpperPlotProgressRange = 100
                        acPlProgDlg.PlotProgressPos = 0

                        '' Display the Progress dialog
                        acPlProgDlg.OnBeginPlot()
                        acPlProgDlg.IsVisible = True

                        '' Start to plot the layout
                        acPlEng.BeginPlot(acPlProgDlg, Nothing)

                        '' Define the plot output
                        acPlEng.BeginDocument(acPlInfo, ACF.acDoc.Name, Nothing, 1, True, suBpath & subFileName)

                        '' Display information about the current plot
                        acPlProgDlg.PlotMsgString(PlotMessageIndex.Status) = "Plotting: " & ACF.acDoc.Name & " - " & acLayout.LayoutName

                        '' Set the sheet progress range
                        acPlProgDlg.OnBeginSheet()
                        acPlProgDlg.LowerSheetProgressRange = 0
                        acPlProgDlg.UpperSheetProgressRange = 100
                        acPlProgDlg.SheetProgressPos = 0

                        '' Plot the first sheet/layout
                        Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo()
                        acPlEng.BeginPage(acPlPageInfo, acPlInfo, True, Nothing)

                        acPlEng.BeginGenerateGraphics(Nothing)
                        acPlEng.EndGenerateGraphics(Nothing)

                        '' Finish plotting the sheet/layout
                        acPlEng.EndPage(Nothing)
                        acPlProgDlg.SheetProgressPos = 100
                        acPlProgDlg.OnEndSheet()

                        '' Finish plotting the document
                        acPlEng.EndDocument(Nothing)

                        '' Finish the plot
                        acPlProgDlg.PlotProgressPos = 100
                        acPlProgDlg.OnEndPlot()
                        acPlEng.EndPlot(Nothing)
                    End Using

                End Using

            End If

            acTrans.Commit()

        End Using
    End Sub

 

*Expert Elite*
norman.yuan
Posts: 982
Registered: ‎04-27-2009
Message 2 of 4 (255 Views)

Re: plot pdf using example code yields no pdf file

05-17-2013 06:41 AM in reply to: kcimos

Does the code run through without exception raised (it seems, because you did not mention)? If the code did run through without error, could it be that AutoCAD did output something but you did not notice:

 

The output is a DWF (because you used "DWF6 ePlot.pc3", not PDF. If your true intention is to plot to PDF, you should use "DWG to PDF.pc3 (or other available PDF plotting device available to the computer). So, if you tried to find *.PDF file in the output folder, you did not see PDF file, thus you thought nothing was plotted. Well, I do not know what output file name you passed in is. Assume it is correct (with *.pdf extention), try again with "Dwg To Pdf.pc3".

 

 

 

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 3 of 4 (243 Views)

Re: plot pdf using example code yields no pdf file

05-17-2013 09:27 AM in reply to: kcimos

BACKGROUNDPLOT – system variable


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 4 of 4 (219 Views)

Re: plot pdf using example code yields no pdf file

05-21-2013 10:17 AM in reply to: kcimos

setting background plotting to be off probably helped.

I also need to add a "\" between my file path & file name.

 

now when i run the code with this:

 

acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)")

 

 

it works,

 

but if I change that line to this:

acPlSetVdr.SetPlotConfigurationName(acPlSet, "CutePDF Writer.pc3", "Letter")

 it almost works; I get a PLT file instead of a pdf, & yes I do have a pc3 named "CutePDF Writer"

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.