Jump to content

Save Duplicate DWG LISP Routine


lamensterms

Recommended Posts

Hey guys,

 

I found this thread on the Audodesk forums the other day…http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Save-copy-of-AutoCAD-Dwg-file-using-macro/td-p/3574830

 

And thought it looked like a pretty good idea. So I applied the macro code to a QuickSave LISP routine and found that it does work quite well.

 

One thing which is puzzling me… sometimes I get the message “A drawing with this name already exists. Do you want to replace it?” returned in the command line, other times I get no message and the routine completes successfully. My first thought was that I would only (and always) get that message when the message is true – when a file needs to be overwritten. This is not the case, sometimes I can run the routine, there can be an existing file of the same name in my “BackUp” directory, and I will not see the ‘overwrite’ message.

 

My code is:

 

(defun c:q ()
(vl-load-com)
(command "qsave")
(SETQ QSDATE (RTOS (GETVAR "CDATE") 2 0))
(vl-mkdir (strcat "D:/_DWGBackup/" QSDATE "/"))
(command "_.SAVE" (strcat "D:/_DWGBackup/" QSDATE "/" (getvar "DWGNAME")))
(princ)
)

 

I have since found a work-around (code below) for this problem, so it is not a solution that I seek – just and explanation as to why I would only sometimes get that message.

 

(DEFUN C:q (/ newname)
  (setvar "CMDECHO" 0)
  (if (zerop (getvar "dwgtitled"))
	(command "._qsave" (getstring "\n Enter drawing name: "))
	(command "_.qsave")
  )
  (setvar "filedia" 0)
  (vl-mkdir (strcat "D:/_DWGBackup/" QSDATE "/"))
  (setq newname 
		(strcat
		  "D:/_DWGBackup/" QSDATE "/"
		  (getvar "DWGNAME")
		)
  )  
  (if (findfile (strcat newname))
	(command "_.save" newname "_Y")
	(command "_.save" newname)
  )
  (setvar "filedia" 1)
  (princ)
)

 

Thanks for any help.

Link to comment
Share on other sites

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