Jump to content

Incremental saving


xces

Recommended Posts

Hi there,

 

I'm a begginer as far as coding goes so I'll just throw this out there. :)

 

I'm trying to make a LISP routine that incrementaly saves my file with changing filename, so..

 

what I'm going for is:

 

when I run the command (keyboard shortcut) i want the program to save the file with it's current file name numbered and every next time it's run with num.+1 so i have separate files for each save.

 

1st save: filename_01.dwg

 

2nd save: filename_02.dwg

 

3rd save: filename_03.dwg

.

.

.

n save: filename_n.dwg

 

 

3Dstudio max has this as an option in their release..

 

any help or pointing me in the right direction would be greatly appreciated.

 

thnx

Link to comment
Share on other sites

Try this :

(defun c:SAVE1()
(vl-load-com)  

(setq a 1
     fnme (vl-filename-base (getvar 'dwgname))
     flen (strlen (vl-filename-base (getvar 'dwgname)))
)      
(if (= b nil)  
(progn (setq newfilename (strcat fnme "-"(rtos a 2 0)".dwg" ) b 1  ))
(setq newfilename (strcat (substr fnme 1 (- flen 1)) (rtos b 2 0)".dwg" ))) 
(command "._saveas"
    "2010" ;fileformat
    newfilename
    "" ;enter
)
(setq b (+ b 1))
(princ newfilename)
(princ) 
)

 

but first save your work.

Link to comment
Share on other sites

thnx for the prompt answer guys but this doesn't work for me..

 

i'm using acad 2014 and it doesn't recognize the command, i get an error "Unknown command "SAVE1". Press F1 for help."[\B] although the LISP file is loaded and acad recognizes it while i'm typing it..

 

any suggestions ?

thnx again

Link to comment
Share on other sites

When you run the save1 routine or the first time it assumes that the variable "b" ( integer and global) is nil.

 

If you run other lisps where "b" is global and is modified into non integer then you will have problems with save1.

 

I am using autocad 2010.

Link to comment
Share on other sites

nope, i changed the names of the variables, still the same thing..

 

 

C:SAVE1

Command: SAVE1

._saveas

Current file format: AutoCAD 2010(LT 2010) Drawing

Enter file format [R14(LT98&LT97)/2000(LT2000)/2004(LT2004)/2007(LT2007)/2010(LT2010)/2013(LT2013)/Standards/DXF/Template] : 2010 Save drawing as : Drawing-4.dwg

Command: SAVE1

Unknown command "SAVE1". Press F1 for help.

Command: Drawing-4.dwg

:(:(:ouch:
Link to comment
Share on other sites

  • 1 year later...
Maybe this remove comments (command "._saveas" "2010" newfilename "" )

 

 

still not working, it's just printing incremental file names in the command line..

 

any other advice ?

 

thnx in advance

Link to comment
Share on other sites

  • 1 year later...

rename your local variable to another special name and change (command "._saveas" "2010" newfilename "" ) ---> (command "._saveas" "2010" newfilename)

it worked fine for cad 2017 :)

Link to comment
Share on other sites

from sadhu 's code,try this :

(defun c:SAVE1 (/ cmde a fpath fnme flen newfilename)

(vl-load-com)

(setq 'cmdecho cmde);filedia=0

(setvar 'cmdecho 0)

(setq a 1

fnme (vl-filename-base (getvar 'dwgname))

flen (strlen (vl-filename-base (getvar 'dwgname)))

fpath (getvar "dwgprefix")

)

(if (= save-b nil)

(setq newfilename (strcat fpath fnme "-"(rtos a 2 0)".dwg" ) save-b 1 )

(setq newfilename (strcat fpath (substr fnme 1 (- flen 1)) (rtos save-b 2 0) ".dwg" ))) ;if

(command "._saveas"

"2010" ;fileformat

newfilename

;enter

)

(setq save-b (+ save-b 1))

(princ newfilename)

(setvar 'cmdecho cmde)

(princ)

)

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