JeepMaster Posted October 5, 2009 Share Posted October 5, 2009 I found this lisp from another thread here and I'm using this as a subroutine for my other Bind lisp. This SaveIt.lsp will create a BOUND folder and then a dated folder (ie: A)and saves the drawing in there. The problem I have is when I already have the drawing in the dated folder(A) and I try saving the same drawing again, it will create another bound folder and dated folder (B) inside the dated folder (A). How can I fix this so it will just overwrite the existing drawing. (defun c:SaveIt ( / ) (setq vDia (getvar "filedia") vEcho (getvar "cmdecho") vPrefix (getvar "dwgprefix") vName (getvar "dwgname") vDate (rtos (getvar "cdate") 2 6) vYear (substr vDate 1 4) vMonth (substr vDate 5 2) vDay (substr vDate 7 2) VLogin (getvar "loginname") vDateStr (strcat vYear "-" vMonth "-" vDay "_" vLogin ) ) (setvar "filedia" 0) (setvar "cmdecho" 0) (setq vDir (strcat vPrefix "Bound")) (if (= (vl-file-directory-p vDir) nil) (progn (vl-mkdir vDir) (vl-mkdir (strcat vDir "\\" vDateStr)) ) (if (= (vl-file-directory-p (strcat vDir "\\" vDateStr)) nil) (vl-mkdir (strcat vDir "\\" vDateStr)) ) ) (command ".saveas" "" (strcat vDir "\\" vDateStr "\\" vName)) (setvar "filedia" vDia) (setvar "cmdecho" vEcho) (princ) ) Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted October 6, 2009 Share Posted October 6, 2009 ***Edit: The question beckons, Why use "save as" if you want it in the same place & same name? Purhaps (defun c:SaveIt ( / Bk_Echo vDir Str_FileName vDate vDateStr Str_NewDir Str_FileLoc Str_FileDir) (vl-load-com) (setq Bk_Echo (getvar "cmdecho") vDate (rtos (getvar "cdate") 2 6) vDateStr (strcat (substr vDate 1 4) "-" (substr vDate 5 2) "-" (substr vDate 7 2) "_" (getvar "loginname")) Str_FileLoc (getvar "dwgprefix") Str_FileDir (substr Str_FileLoc 1 (vl-string-search "Bound" Str_FileLoc)) vDir (strcat Str_FileDir "Bound") Str_NewDir (strcat vDir "\\" vDateStr) Str_FileName (strcat Str_NewDir "\\" (getvar "dwgname")) ) (setvar "cmdecho" 0) (if (not (vl-file-directory-p vDir))(vl-mkdir vDir)) (if (not (vl-file-directory-p Str_NewDir))(vl-mkdir Str_NewDir)) (vl-cmdf ".saveas" "" Str_FileName) (setvar "cmdecho" Bk_Echo) (princ "File Saved") (princ) ) Sorry im in one of those stages Just used this (setqStr_FileDir (substr Str_FileLoc 1 (vl-string-search "Bound" Str_FileLoc)) to stop any bound\bound stuff Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted October 6, 2009 Author Share Posted October 6, 2009 Thanks so much flowerrobot, I got it to work now. My only issue now is if the dwg is already there, it'll ask me if I want to overwrite existing file. What I did was add another command "Y" to the "saveas" command line. (vl-cmdf ".saveas" "" Str_Filename "Y") Which works fine. But it will show an "Unknown command "Y" " If the dwg is saved the first time around.:wink: Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 6, 2009 Share Posted October 6, 2009 Thanks so much flowerrobot,I got it to work now. My only issue now is if the dwg is already there, it'll ask me if I want to overwrite existing file. What I did was add another command "Y" to the "saveas" command line. (vl-cmdf ".saveas" "" Str_Filename "Y") Which works fine. But it will show an "Unknown command "Y" " If the dwg is saved the first time around.:wink: Give this a try: (vl-cmdf ".saveas" "" Str_Filename) (or (zerop (getvar "dbmod"))) (vl-cmdf "_y") ) Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted October 6, 2009 Author Share Posted October 6, 2009 (vl-cmdf ".saveas" "" Str_Filename) (or (zerop (getvar "dbmod"))) (vl-cmdf "_y") [color=Red])[/color] Thanks Alan, but it doesn't seem to make any difference. I still get the "unknown command Y " Where did the extra ")" come from? Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 6, 2009 Share Posted October 6, 2009 (vl-cmdf ".saveas" "" Str_Filename) (or (zerop (getvar "dbmod"))) (vl-cmdf "_y") [color=Red])[/color] Thanks Alan, but it doesn't seem to make any difference. I still get the "unknown command Y " Where did the extra ")" come from? Oops, got a little paren-happy. Try this: (vl-cmdf ".saveas" "" Str_Filename) (or (zerop (getvar "dbmod")) (vl-cmdf "_y") ) Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted October 7, 2009 Share Posted October 7, 2009 Ahh i thought you wanted that Anther way (if (findfile Str_Filename) (vl-cmdf "_qsave");!!!! (vl-cmdf ".saveas" "" Str_Filename) ) Quote Link to comment Share on other sites More sharing options...
JeepMaster Posted October 7, 2009 Author Share Posted October 7, 2009 flowerrobot, I don't think qsave will work because I'm saving from a different folder to a .../bound/date folder. I certainly don't want to save my "working" drawing because I'm using this as a subroutine after I bind my drawing(before saving). Eitherway, the one Alan wrote works fine. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
alanjt Posted October 7, 2009 Share Posted October 7, 2009 flowerrobot,I don't think qsave will work because I'm saving from a different folder to a .../bound/date folder. I certainly don't want to save my "working" drawing because I'm using this as a subroutine after I bind my drawing(before saving). Eitherway, the one Alan wrote works fine. Thanks for your help. Glad that helped. I had started writing it differently, but backed up. I guess I forgot to remove all my parens. Quote Link to comment Share on other sites More sharing options...
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.