Help with AutoLISP Script for Compiling Multiple DWG Files into a Single PDF

Help with AutoLISP Script for Compiling Multiple DWG Files into a Single PDF

heuiy
Participant Participant
711 Views
3 Replies
Message 1 of 4

Help with AutoLISP Script for Compiling Multiple DWG Files into a Single PDF

heuiy
Participant
Participant

Hello Autodesk Community,

 

I'm working with an AutoLISP script intended to batch plot DWG files to PDF and then compile all the output into a single PDF document. Despite several attempts to correct the script, I keep encountering issues, particularly with the PDF output settings. Below is the essential part of the script:

 

```

(defun c:BatchPlotDWGtoPDF ()
(setq dwg-path "D:\\#.Secure Work Folder\\BIG\\Project\\23~24Y\\240129 CAD Reading Automation\\DWG\\out\\240419 print\\") ; DWG files location
(setq pdf-path "D:\\#.Secure Work Folder\\BIG\\Project\\23~24Y\\240129 CAD Reading Automation\\PDF\\out\\") ; PDF output location

;; Retrieve DWG file list
(setq files (vl-directory-files dwg-path "*.dwg" 1))

;; Process each file
(foreach file files
(setq full-path (strcat "\"" dwg-path file "\"")) ; Full file path, enclosed in quotes
;; Open DWG file
(command "_.OPEN" full-path)

;; PDF output settings
(command "_.-PLOT" "Yes" "" "DWG to PDF.pc3" "ISO_full_bleed_A3_(420.00_x_297.00_MM)" "Inches" "Landscape" "No" "Extents" "Fit" "Center" "Yes" (strcat "\"" pdf-path file ".pdf\"" ) "No" "Yes")

;; Close file
(command "_.CLOSE" "No")
)
(princ)
)

```

 

When running this script, I encounter an "Unknown command" error specifically when attempting to plot to PDF. I have double-checked the file paths and syntax but cannot seem to resolve the issue.

 

Additionally, I aim to compile all the plotted PDFs into a single PDF document located at the specified pdf-path. Could anyone provide insights on how to improve this script to not only batch plot but also compile the outputs into one PDF? Any help on why the _.-PLOT command might not be recognized would also be greatly appreciated.

 

Thank you in advance for your support!

 

0 Likes
Accepted solutions (1)
712 Views
3 Replies
  • LSP
Replies (3)
Message 2 of 4

pendean
Community Legend
Community Legend
Accepted solution
May I ask, why not use PUBLISH command for this duplicate task it can do?
Combine it with SSM and you have "sets" too.

Just a thought.
Message 3 of 4

heuiy
Participant
Participant

Thank you for your suggestion to use the PUBLISH command and SSM for creating sets. I initially attempted to export areas from DWG files into PDF using the script below, but I encountered issues with the PDF not being saved correctly, so I considered using the PUBLISH command as an alternative to batch process DWG files into PDFs.

 

```

(defun C:ExportAreaPDF ()
(setq coords '(
(-7420 -5720 -6584 -5138)
(-8320 -5720 -7484 -5138)
(-9220 -5720 -8384 -5138)
))
(setq outputPath "C:\\Users\\LG\\Desktop\\")
(setq i 0)

(foreach area coords
(setq xMin (car area)
yMin (cadr area)
xMax (caddr area)
yMax (cadddr area))
(command "-PLOT" "N" "Model" "Adobe PDF" "" "Inches" "Landscape" "N" "Window"
(strcat (rtos xMin 2 2) "," (rtos yMin 2 2))
(strcat (rtos xMax 2 2) "," (rtos yMax 2 2))
"Fit" "Center" "Y" "" "Y" "N" "N" "N" "Y"
(strcat outputPath "Output_" (itoa (1+ (setq i (1+ i)))) ".pdf")
"Y")
(command "_.delay" "2000")
)
(princ)
)

```

 

Regarding your suggestion to use SSM to handle sets, I faced an issue because the DWG files I am working with only contain models without any layouts defined. When I try to batch print these files, the result is mostly blank since there are no layouts to define the print area.

 

Do you have any advice or scripts that you usually use for handling such situations where the DWG files lack predefined layouts but still need to be batch printed? Any help would be appreciated!

0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

See other post. Automatically Creating Layouts for DWG Files Lacking Predefined Layouts - Autodesk Community - AutoC...

 

Just a comment, you can use Ghostscript to join multiple pdf's into 1 pdf, can be driven from lisp or say a script.

0 Likes