Jump to content

Recommended Posts

Posted

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 :)

 

 

 

 

Posted

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

Posted (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 by GLAVCVS
  • Like 1
Posted
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.

  • Like 1
Posted (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 by SLW210
Added Code Tags!!
Posted

Please place Code in Tags in the future. (<> in the editor toolbar)

Posted

no problem thanks for demonstrating how to do it,

Posted
On 10/16/2025 at 10:12 PM, GLAVCVS said:

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) 
)

 

 

What would need to be changed in this code to save multiple DWG versions at once?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...