Autocad 2025 LT - Open a file - Print the file that opens - Close the file.

Autocad 2025 LT - Open a file - Print the file that opens - Close the file.

jhouse7UYHW
Observer Observer
272 Views
3 Replies
Message 1 of 4

Autocad 2025 LT - Open a file - Print the file that opens - Close the file.

jhouse7UYHW
Observer
Observer

Autocad 2025 LT - Open a file - Print the file that opens - Close the file.

 

Sounds simple but I'm struggling here.  The coding below successfully prints to PDF the currently opened drawing that is being used to execute the autolisp command.   Then it closes that file.   What it does not do is open the file I want it to open, then print that then close that while leaving the existing file open.

 

Here's why I believe this is happening.  The open file command is executed but then that process is so slow, the next print command overrides it and it just bypasses the open file part and executes the printing function.  Now this is what I think is happening.  I could be wrong. 

 

Any attempt at creating code for it to wait for the file to open has been met with failure.  It just ends up closing the existing file and not printing anything.

 

Anyone with experience in this know how to correct this code to actually make this work as intended?  

 

(defun c:TestPrint ()
;; Specify the file path for the DWG to open
(setq dwgFile "C:\\WORK PERSONAL\\AutoLISP\\AM17.dwg") ; Path to the DWG file

;; Check if the file exists
(if (findfile dwgFile)
(progn
;; Open the specified DWG file
(command "_.OPEN" dwgFile)

;; Construct the PDF output file path
(setq pdfFile (strcat (vl-filename-directory dwgFile) "\\"
(vl-filename-base dwgFile) ".pdf"))

;; Use PLOT command with specific settings
(command "_.PLOT" "N" "" "" "" "" "No" "YES" pdfFile "NO" "NO")

;; Close the file after printing
(command "_.CLOSE" "Y") ; Save changes if prompted

;; Notify user of success
(princ (strcat "\nPDF created successfully at: " pdfFile))
)
;; Notify user if the file cannot be found
(princ "\nFile not found at the specified location.")
)
(princ) ; Exit cleanly
)

 

 

0 Likes
273 Views
3 Replies
Replies (3)
Message 2 of 4

DGCSCAD
Collaborator
Collaborator

A LISP function only runs in the current drawing (the drawing it was executed in). You'd need to create a script, which can run any number of LISP functions on multiple drawings outside of the current drawing.

 

Use Publish if you're looking for an OOTB solution.

 

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 3 of 4

paullimapa
Mentor
Mentor

I believe LT supports Coreconsole. What you can do is use lisp to create a batch /cmd file that executes coreconsole to run a script file that runs the commands to plot that specific dwg and this would allow you to still be in the current dwg while that process is going on in a dos window


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

Like @paullimapa you can write a script that does the 3 steps, open a dwg, (load "aplotlispfile"), close dwg.

 

You need to make a lisp that writes the script say selecting the file to plot, the last line in the lisp is,

(command "script" "myplotscript.scr")
0 Likes