xces Posted January 9, 2015 Share Posted January 9, 2015 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 Quote Link to comment Share on other sites More sharing options...
sadhu Posted January 9, 2015 Share Posted January 9, 2015 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 9, 2015 Share Posted January 9, 2015 You might also consider the reverse using VL-file-delete to remove unwanted versions. Quote Link to comment Share on other sites More sharing options...
xces Posted January 10, 2015 Author Share Posted January 10, 2015 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 Quote Link to comment Share on other sites More sharing options...
sadhu Posted January 10, 2015 Share Posted January 10, 2015 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 10, 2015 Share Posted January 10, 2015 Change the name of a & b sad-a sad-b it should work then. Quote Link to comment Share on other sites More sharing options...
xces Posted January 12, 2015 Author Share Posted January 12, 2015 nope, i changed the names of the variables, still the same thing.. C:SAVE1Command: SAVE1 ._saveas Current file format: AutoCAD 2010(LT 2010) Drawing Enter file format [R14(LT98<97)/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 :( Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 12, 2015 Share Posted January 12, 2015 Maybe this remove comments (command "._saveas" "2010" newfilename "" ) Quote Link to comment Share on other sites More sharing options...
xces Posted February 19, 2016 Author Share Posted February 19, 2016 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 Quote Link to comment Share on other sites More sharing options...
sieu khung khiep Posted May 23, 2017 Share Posted May 23, 2017 rename your local variable to another special name and change (command "._saveas" "2010" newfilename "" ) ---> (command "._saveas" "2010" newfilename) it worked fine for cad 2017 Quote Link to comment Share on other sites More sharing options...
sieu khung khiep Posted May 23, 2017 Share Posted May 23, 2017 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) ) Quote Link to comment Share on other sites More sharing options...
sieu khung khiep Posted May 23, 2017 Share Posted May 23, 2017 sorry about some mistake: local --> global and (setq cmde (getvar 'cmdecho)), 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.