Using PlotToFile on Layout Tabs

Using PlotToFile on Layout Tabs

Abby_Baratta
Enthusiast Enthusiast
934 Views
7 Replies
Message 1 of 8

Using PlotToFile on Layout Tabs

Abby_Baratta
Enthusiast
Enthusiast

I am currently working on writing a script that will go through each tab and plot to file. The model tab has been working fine and will plot with the correct name in the correct location each time. The layout tabs, however, are coming up with 'serious errors' when I try to plot them. The errors are not ones that will stop the code -  they can only be seen in the plot and publish details section. I've attached the sub that I wrote that is supposed to take in the save directory and the name of the pdf and plot to file.

 

plottofile.PNG

 

If anyone knows how I might be able to get this to work, I'd really appreciate it!

0 Likes
935 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

Please post your code in a code window, not an image of it.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 8

Abby_Baratta
Enthusiast
Enthusiast
Sub CreatePDF(PDFsavedir As String, PDFname As String)
Dim PtConfigs As AcadPlotConfigurations
Dim PlotConfig As AcadPlotConfiguration
Dim PtObj As AcadPlot
Dim BackPlot As Variant
Dim plotFileName As String

'Auto open PDF is default setting using AutoCAD's print to PDF driver
'must be turned off on virtual machine in order for script to run all the way through
'added 1/04/2024 AB

'Create new plot with all needed parameters
'Set PtObj = ThisDrawing.Plot
Set PtConfigs = ThisDrawing.PlotConfigurations

'Adding a new plot configuration
PtConfigs.Add "PDF", False

'Activate the new new plot
Set PlotConfig = PtConfigs.Item("PDF")

'Scale the plot
PlotConfig.StandardScale = acScaleToFit

'Update the plot
PlotConfig.RefreshPlotDeviceInfo

'
'preferences (taken from PDFcombine module)
   'ThisDrawing.ActiveLayout.CanonicalMediaName = "ANSI_A_(8.50_x_11.00_Inches)"
   'ThisDrawing.Regen acActiveViewport
   ThisDrawing.ActiveLayout.PlotType = acDisplay
   ThisDrawing.ActiveLayout.StandardScale = acScaleToFit
   ThisDrawing.ActiveLayout.CenterPlot = True
   ThisDrawing.ActiveLayout.PlotRotation = ac0degrees
   ThisDrawing.ActiveLayout.RefreshPlotDeviceInfo
   ThisDrawing.ActiveLayout.PlotType = acExtents
   ThisDrawing.ActiveLayout.StyleSheet = "monochrome.ctb"
   ThisDrawing.Regen acActiveViewport
   
   
'testing


'pc3 file
PlotConfig.ConfigName = "AutoCAD PDF (General Documentation).pc3"


'Use PlotToFile method to create our PDF
plotFileName = PDFsavedir & PDFname & ".pdf"
ThisDrawing.Plot.PlotToFile (plotFileName)


End Sub

 

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

Please describe what "serious errors" are. I don't see anything in your code that switches to a new layout. It just plots the active layout. Did you know that the PUBLISH command does what you want? Also, the DWG TO PDF printer driver always opens the pdf after printing. Other pdf drivers have more options. I use Bluebeam. It also gives you control over the filename. There are some free ones too.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 8

Abby_Baratta
Enthusiast
Enthusiast

I'm unsure what the serious errors are because when the plot and publish details box opens up, the only thing is says is serious error.

 

I currently have the settings so that it won't automatically open the PDF when it creates and so far it's been working pretty well. 

 

I'm working with code that was written for AutoCAD2004 and no longer works in the newer AutoCAD versions. In that original code, a drawing would be made in the model tab, then printed to PDF. It would then move on to the first layout tab, do whatever it's gotta do, and then print to PDF. It did this for all the layout tabs and then used Adobe to grab all the PDFs and merge them into one. My goal is to just use this plot to file function to create those PDFs and let the merge code do its thing. 

 

I have tried sending an AutoPublish command, but so far that has been unsuccessful. I am still looking into it because that would shorten the process and get rid of the need for the merging of the PDFs, but for some reason it is not working with ThisDrawing.SendCommand. 

0 Likes
Message 6 of 8

Ed__Jobe
Mentor
Mentor

You may be running into the problem I described in this thread.

 

When I mentioned the PUBLISH command, I was referring to using the interface inside AutoCAD, not using SendCommand. First you build a sheet list by importing the layouts from selected drawings. Then set the plot options. You can name an output file and create a multi-page pdf. Then set a page setup for all the sheets. Then it plots in the background. In less than a minute, you've created a batch process. It's even easier if you use sheet sets.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 8

Abby_Baratta
Enthusiast
Enthusiast

I'll look into this - thank you!

0 Likes
Message 8 of 8

Ed__Jobe
Mentor
Mentor

Here's a video on how to use the PUBLISH command to create multi page pdf's.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes