Message 1 of 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Im trying to set up Design Automation for AutoCAD. After submitting the work item I get a response saying it was successful. But when I look at the logs it seems to have trouble running the script
AutoCAD menu utilities loaded.
[07/23/2024 23:02:54] Command:
[07/23/2024 23:02:54] Command: Enter BACKSPACE to interrupt script.
[07/23/2024 23:02:54] Command:
[07/23/2024 23:02:54] Command: (load "DWGToPDF.lsp")
[07/23/2024 23:02:54] C:DWGTOPDF
[07/23/2024 23:02:54] Command: (c:DWGToPDF)
[07/23/2024 23:02:54] ; error: bad argument type: VLA-OBJECT nil
[07/23/2024 23:02:55] End AutoCAD Core Engine standard output dump.
[07/23/2024 23:02:55] Error: AutoCAD Core Console output contains error(s).
[07/23/2024 23:02:55] End script phase.
Am I doing something wrong in my script?
(defun c:DWGToPDF()
(vl-load-com)
; Suppress file dialog boxes
(setq originalFileDia (getvar "FILEDIA"))
(setvar "FILEDIA" 0)
; Get the active document in AutoCAD
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
; Check if the document is valid
(if (null doc)
(progn
(princ "\nError: No active document found.")
(exit)
)
)
; Get the full path of the active document
(setq docPath (vlax-get-property doc 'FullName))
; Extract the directory path from the full path
(setq outputDir (vl-filename-directory docPath))
; Get the Layouts collection
(setq layouts (vla-get-Layouts doc))
; List to store output PDF file paths
(setq outputFiles '())
; Iterate through all layouts
(vlax-for layout layouts
(setq layoutName (vla-get-Name layout))
; Skip the "Model" layout
(if (/= layoutName "Model")
(progn
; Print the name of the current layout for debugging
(princ (strcat "\nProcessing layout: " layoutName "\n"))
; Generate the output file path
(setq sanitizedLayoutName (vl-string-translate "/\\:*?\"<>|" "_" layoutName))
(setq outputFile (strcat outputDir "\\" sanitizedLayoutName ".pdf"))
(princ (strcat "\nOutput file path: " outputFile "\n"))
; Add to output files list
(setq outputFiles (cons outputFile outputFiles))
; Start the plot command
(command
"-plot" ; Start the plot command
"Yes" ; Detailed plot configuration
layoutName ; Layout name
"DWG To PDF.pc3" ; Output device name
"ARCH full bleed E1 (30.00 x 42.00 Inches)"; Paper size
"inches" ; Paper units (default)
"Landscape" ; Drawing orientation
"No" ; Plot upside down?
"Extents" ; Plot area
"Fit" ; Plot scale
"0,0" ; Plot offset (centered)
"Yes" ; Plot with plot styles?
"" ; Plot style table name
"Yes" ; Plot with lineweights?
"Yes" ; Scale lineweights with plot scale?
"No" ; Plot paper space last
"No" ; Hide plot
outputFile ; Output file name
"No" ; Prompt for plot details
"No" ; Save changes to layout
)
)
)
)
; Reset FILEDIA variable to original state
(setvar "FILEDIA" originalFileDia)
; Print completion message
(princ "\nPlotting complete.\n")
; Print output files for Design Automation to recognize
(foreach file outputFiles
(princ (strcat "\nOutput file: " file "\n"))
)
(princ)
)
Solved! Go to Solution.