+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Super Member
    not specified
    Join Date
    Feb 2006

    Default Using VBA to export a Pdf File from AutoCAD

    Registered forum members do not see this ad.

    AutoCAD 2010

    Is there any VBA code to create a pdf file. Maybe using something like Exportpdf command
    in AutoCAD without the page setup menu. Some that could be put in a batch loop in VBA.
    Thank you,

  2. #2
    Super Member
    not specified
    Join Date
    Feb 2006

    Default If anyone is interested, this is the code I found.

    Sub CreatePDF()

    Dim PtConfigs As AcadPlotConfigurations
    Dim PlotConfig As AcadPlotConfiguration
    Dim PtObj As AcadPlot
    Dim BackPlot As Variant

    'Create a new plot configuration with all needed parameters
    Set PtObj = ThisDrawing.Plot
    Set PtConfigs = ThisDrawing.PlotConfigurations
    'Add a new plot configuration
    PtConfigs.Add "PDF", False
    'The plot config you created become active
    Set PlotConfig = PtConfigs.Item("PDF")
    'Use this method to set the scale
    PlotConfig.StandardScale = acScaleToFit
    'Updates the plot

    'Here you specify the pc3 file you want to use
    PlotConfig.ConfigName = "DWG To PDF.pc3"
    'You can select the plot style table here
    PlotConfig.StyleSheet = ComboBox3.Value
    'PlotConfig.StyleSheet = "Acad.ctb"

    'Specifies whether or not to plot using the plot styles
    PlotConfig.PlotWithPlotStyles = True

    'If you are going to create pdf files in a batch mode,
    'I would recommend to turn off the BACKGROUNDPLOT system variable,
    'so autocad will not continue to do anything until finishes
    'the pdf creation
    BackPlot = ThisDrawing.GetVariable("BACKGROUNDPLOT")
    ThisDrawing.SetVariable "BACKGROUNDPLOT", 0
    'Updates the plot
    'Now you can use the PlotTofile method
    If PtObj.PlotToFile(Replace(ThisDrawing.FullName, "dwg", "pdf"), PlotConfig.ConfigName) Then
    MsgBox "PDF Was Created"
    MsgBox "PDF Creation Unsuccessful"
    End If
    'If you wish you can delete th plot configuration you created
    'programmatically, and set the 'BACKGROUNDPLOT' system variable
    'to its original status.
    Set PlotConfig = Nothing
    ThisDrawing.SetVariable "BACKGROUNDPLOT", BackPlot

    End Sub

  3. #3
    Forum Newbie
    AutoCAD 2012
    Join Date
    Aug 2015


    Registered forum members do not see this ad.

    Sorry to dig out this topic, I would like to know if it is possible to use "Export" as a VBA command in order to export the drawing to a PDF file ?

    I used the code you described and it works but it takes 25 sec. for one drawing. And when I manually do it on AutoCad I see that "Export PDF" takes less than 1 second after the click to make the wanted PDF.

    Is there a code to use the Export command ? I tried "SendCommand" but it doesn't work.

Similar Threads

  1. Export/import drawing file to/from csv(text) file
    By mtjipta in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 9th Jan 2010, 04:14 am
  2. how shall i export dwg file to 3d max
    By sudhaathreya in forum 3D Modelling
    Replies: 1
    Last Post: 9th Oct 2009, 06:19 pm
  3. Export DWG file with .txt or .CSV
    By DMS in forum AutoCAD General
    Replies: 8
    Last Post: 21st May 2009, 03:43 am
  4. How to export stl file from autocad 2006
    By luisitopwr in forum AutoCAD General
    Replies: 0
    Last Post: 14th Aug 2007, 11:16 pm
  5. HELP! with .sat file export in autocad 2006
    By bobray in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 23rd Jun 2006, 07:51 pm


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts