Jump to content

Using VBA to export a Pdf File from AutoCAD


muck

Recommended Posts

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,

Link to comment
Share on other sites

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

 

 

 

PlotConfig.RefreshPlotDeviceInfo

'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

PlotConfig.RefreshPlotDeviceInfo

'Now you can use the PlotTofile method

If PtObj.PlotToFile(Replace(ThisDrawing.FullName, "dwg", "pdf"), PlotConfig.ConfigName) Then

MsgBox "PDF Was Created"

Else

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.

PtConfigs.Item("PDF").Delete

Set PlotConfig = Nothing

ThisDrawing.SetVariable "BACKGROUNDPLOT", BackPlot

 

End Sub

Link to comment
Share on other sites

  • 4 years later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...