swanny89 Posted Thursday at 04:08 PM Posted Thursday at 04:08 PM Hi all, I've been trying to accomplish what I thought would be an easy thing, but despite hours of searching I can't seem to get it to work! I'm trying to create a lisp that I can run in AutoCAD LT (2025) that does a "SAVE AS" and simply adds " - EXPORTED" as a suffix onto the original filename. I'd like this to happen without any dialogue boxes popping up, and If it could have the following features it would be absolutley perfect (but these arent crucial). 1. specify the file version from within the lisp 2. save the exported versions into a folder within the same directory called "exported" (and overwrite previous versions if they exist) The closest I've gotten is using the below code to do the saveas, but it throws an error (; error: bad argument type: stringp nil) (defun c:TEST () (vl-load-com) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat myfilepath myfilename ".dwg") ac2018_dwg) ) If anyone is able to help me out I'd very much appreciate it Quote
Steven P Posted Thursday at 07:54 PM Posted Thursday at 07:54 PM LT is not brilliant with VLA- or VL- commands so best really avoid them for now. Perhaps not the most efficient method but try the (command "_.saveas" ...... ) method Quote
GLAVCVS Posted Thursday at 08:12 PM Posted Thursday at 08:12 PM (edited) Hi It's not certain that all the functions in this code will work in AutoCAD LT. Try it. (defun c:guardA (/ v nvoD f?) (setq v (member (vla-get-saveAsType (vla-get-openSave (vla-get-preferences (vlax-get-acad-object)))) (list acr14_dwg "v14" ac2000_dwg "v2000" ac2004_dwg "v2004" ac2007_dwg "v2007" ac2010_dwg "v2010" ac2013_dwg "v2013" ac2018_dwg "v2018"))) (setq f? (if (not (vl-directory-files (setq nvoD (strcat (getvar "DWGPREFIX") "EXPORTED\\")))) (VL-MKDIR nvoD) T)) (vla-saveas (vla-get-activedocument (vlax-get-acad-object)) (strcat (if f? nvoD (getvar "DWGPREFIX")) (VL-FILENAME-BASE (getvar "DWGNAME")) "-EXPORTED_" (cadr v) ".dwg") (car v)) (princ "\nDone!") (princ) ) Edited Thursday at 08:37 PM by GLAVCVS Quote
Lee Mac Posted Thursday at 10:13 PM Posted Thursday at 10:13 PM 6 hours ago, swanny89 said: The closest I've gotten is using the below code to do the saveas, but it throws an error (; error: bad argument type: stringp nil) (defun c:TEST () (vl-load-com) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat myfilepath myfilename ".dwg") ac2018_dwg) ) Have you defined the variables 'myfilepath' and 'myfilename' somewhere? If not, these symbols will evaluate to nil, yielding the error you have described. 1 Quote
swanny89 Posted yesterday at 08:30 AM Author Posted yesterday at 08:30 AM (edited) Thanks for the assistance guys. I managed to get another version working after some trial and error (code below) @Lee Mac Yes, I had the variables defined but I just couldn't crack it with my limited LISP knowledge. Can I just add that I'm super thankful for all your work! Your LISP routines have had an immesurably beneficial impact on my workflow! If you have time, could you please take a look at this topic....it's the last LISP I need to 'complete' my LISP library! Thank you in advance if you can Polyline modification LISP - AutoLISP, Visual LISP & DCL - AutoCAD Forums Code that worked for me in the original post: (defun c:CLIENTDWG () (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (setq fullpath (vla-get-FullName doc)) (if (and fullpath (/= fullpath "")) (progn (setq fname (vl-filename-base fullpath)) (setq fext (vl-filename-extension fullpath)) (setq fdir (vl-filename-directory fullpath)) (setq exportDir (strcat fdir "\\Exported Versions")) ;; Create EXPORTED folder if it doesn't exist (if (not (vl-file-directory-p exportDir)) (vl-mkdir exportDir) ) ;; Avoid duplicate suffix (if (wcmatch (strcase fname) "* - EXPORTED VERSION") (setq baseName fname) ; already has suffix (setq baseName (strcat fname " - EXPORTED VERSION")) ) ;; Construct new file path (setq newname (strcat exportDir "\\" baseName "." fext)) ;; Delete existing file if it exists (if (findfile newname) (vl-file-delete newname) ) ;; Save the drawing with the new name (vla-SaveAs doc newname) (princ (strcat "\nDrawing exported and saved as: " newname)) ) (princ "\nDrawing must be saved before exporting.") ) (princ) ) Edited 12 hours ago by SLW210 Added Code Tags!! Quote
SLW210 Posted 12 hours ago Posted 12 hours ago Please place Code in Tags in the future. (<> in the editor toolbar) Quote
swanny89 Posted 4 hours ago Author Posted 4 hours ago no problem thanks for demonstrating how to do it, Quote
Recommended Posts
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.