Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

Thanks so much flowerrobot,

I got it to work now.:D

 

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:

Posted
Thanks so much flowerrobot,

I got it to work now.:D

 

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

Posted

(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?:?

Posted
(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")
   )

Posted

Ahh i thought you wanted that

 

Anther way

 

(if (findfile Str_Filename)
(vl-cmdf "_qsave");!!!!
(vl-cmdf ".saveas" "" Str_Filename)
)


Posted

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

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

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