Lee Mac Posted June 28, 2017 Share Posted June 28, 2017 Hi, I need something similar and I thought I could get it but certainly I can't do it.I want to make a command to save a copy of the current drawing in a subdirectory and rename it sequentially (Drawing1.dwg, Drawing1 (2) .dwg, Drawing1 (3) .dwg ...). It would not be necessary to add a date to the file name but the revision number would be unlimited (or at least very high (3 digits)). Something like this? Quote Link to comment Share on other sites More sharing options...
supertxull Posted June 28, 2017 Share Posted June 28, 2017 Something like this? OMG!!!! that's exactly what I was searching for. Thank you very much for support. Sorry for not using the search engine correctly but my English is not very good. The LM:uniquefilename () function was the key. Congratulations. Quote Link to comment Share on other sites More sharing options...
CADgrunt Posted November 19, 2020 Share Posted November 19, 2020 I know these post are old but If I can get some assistance it would be much appreciated. @Lee Mac I've gone through your code and a bunch of others and have pieced together a routine that is working for me, however I would like to add more to it but getting stump at every turn. (Please note that I'm very rusty with lisp, use to have a team member that was awesome with this stuff now I'm on my own) I need the ability to save my file, striped clean of xrefs and UCS set to world, to a "Collaboration" folder for posting to FTP sites and what not. Currently my code is working well enough to get the job done. What I would like to add, is some checks and balances, notify if my current file hasn't been saved, and maybe a little user input. If possible, I would like to have a dialog pop up and give the option to save my current file before running the routine(so that I don't loose the work in my main file), and maybe add some check boxes for removing xrefs and one for setting the UCS to world to toggle on or off, along with a button to run the routine. (Dialog not needed but if the code for a dcl isn't much then would be nice) I haven't been able to find a way to check if the file exist and if so create a second copy but within a folder with a time stamp or a "am" and "pm" folder. Something that allows me to make multiple backups if needed due to coordination efforts and still have the previous collaborated file just incase I need to revert back. This isn't something that I would be creating hundreds of copies a day, most of the time I'm only running the routine once at the end of the work day but occasionally I need to run it a couple times throughout the day. Currently my code saves a copy into the a folder structure like so: "....\\Collaboration\\2020-01-01\\filename" I would like it to be able to do this if needed: "....\\Collaboration\\2020-01-01\\AM8:53\\filename" or "....\\2020-01-01\\R01\\filename" Some sort of time reference or even a revision number for a folder. I just need to keep the file name the same. Here is my code: (defun c:Save2Collab ( / ) (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) vDateStr (strcat vYear "-" vMonth "-" vDay ) ) (setvar "filedia" 0) (setvar "cmdecho" 0) (setq vDir (strcat vPrefix "Collaboration")) (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 "-xref" "D" "*") (command "_.ucs" "_W") (command ".saveas" "" (strcat vDir "\\" vDateStr "\\" vName)) (setvar "filedia" vDia) (setvar "cmdecho" vEcho) (command "_.CLOSE") (princ) ) Any help would be amazing! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 20, 2020 Share Posted November 20, 2020 A quick google there is examples about saving a dwg to new name. Maybe https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/save-copy-of-autocad-dwg-file-using-macro/td-p/3574830 If you draw what you want in a dcl I am sure some one will help just text and say a sq for the buttons. Maybe something like this its at Cadtutor downloads Multi toggles.lsp Quote Link to comment Share on other sites More sharing options...
CADgrunt Posted December 17, 2020 Share Posted December 17, 2020 @BIGAL So I've looked into everything you suggested. Unfortunately I'm still at a lost as to how correlate a check box to a command in my lisp. I've been able to get a dcl with a few radio buttons and some toggle boxes. My lisp is bringing up the dialog just fine. I can check everything the way I want but to get the lisp to run all the "selected" routines I'm still lost. I've been researching like crazy but still can't get it to work. I think I'm getting stuck at the "(progn" portion of the lisp. If I check "Remove Xrefs" and hit OK, how do I get the lisp to actually remove the xrefs? Sorry, I'm just really confused at this point. I haven't even been able to get it to save a new drawing on OK. Any extra help here would be much appreciated. Here is my dcl code: Save2Collab : dialog { //dialog name label = "Save to Collaboration" ; //give it a label //______________________________________________________________________ :boxed_radio_column { //*define radio column label = "Save before Collaborating?" ; //*give it a label : radio_button { //*define radion button key = "rb1" ; //*give it a name label = "Yes" ; //*give it a label value = "1" ; //*switch it on } //*end definition : radio_button { //*define radio button key = "rb2" ; //*give it a name label = "No" ; //*give it a label } //*end definition } //*end radio column //______________________________________________________________________ :boxed_row { //define boxed row label = "Please choose option(s):" ; //*give it a label :toggle { //define toggle key = "tog1"; //give it a name label = "Remove Xref's"; //give it a label } //end toggle :toggle { //define toggle key = "tog2"; //give it a name label = "Set USC to World"; //give it a label } //end definition } //end boxed row //______________________________________________________________________ : button { key = "accept"; label = "Collaborate"; is_default = true; fixed_width = true; alignment = centered; } ok_cancel ; //predifined OK/Cancel : row { //define row : image { //define image tile key = "im" ; //give it a name height = 1.0 ; //and a height width = 1.0 ; //and now a width } //end image : paragraph { //define paragraph : text_part { //define text label = "Don't forget to SAVE"; //give it some text } //end text : text_part { //define more text label = "before collaborating!"; //some more text } //end text } //end paragraph } //end row } //end dialog Here is my current lisp code to run the DCL: (defun C:Save2Collab (/ *error* dcl_id );define function (defun *error* (x) (princ "\n*Cancel*")) (setq dcl_id (load_dialog "Save2Collab.dcl"));load dialog (if (not (new_dialog "Save2Collab" dcl_id);test for dialog );not (exit);exit if no dialog );end if (setq w (dimx_tile "im");get image tile width h (dimy_tile "im");get image tile height );setq (start_image "im");start the image (fill_image 0 0 w h 5);fill it with blue (end_image);end image (action_tile "rb1" "(setq Save \"Yes\")");store variable (action_tile "rb2" "(setq Save \"No\")");store variable ;(action_tile "rb3" "(setq 123 \"123\")");store variable (setq xref ;|need code here|;);get remove xref value (set_tile "tog1" xref);switch toggle on or off (setq ucsw ;|need code here|;);get ucs value (set_tile "tog2" ucsw);switch toggle on or off (action_tile "cancel";if cancel button pressed "(done_dialog) (setq userclick nil)";close dialog, set flag );action_tile (action_tile "accept";if O.K. pressed " (done_dialog)(setq userclick T))";close dialog, set flag );action tile (action_tile "accept";if O.K. pressed (strcat;string 'em together "(progn " (done_dialog)(setq userclick T))" ;close dialog, set flag );strcat (start_dialog) ;start dialog (unload_dialog dcl_id) ;unload (princ) );defun C:samp (princ) Here is the code I have been running (without DCL): (defun c:Save2Collab ( / ) (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) vDateStr (strcat vYear "-" vMonth "-" vDay ) vHour (substr vDate 10 2) vMin (substr vDate 12 2) vTime (strcat vHour "-" vMin ) ) (setvar "filedia" 0) (setvar "cmdecho" 0) (setq vDir (strcat vPrefix "Collaboration")) (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 "-xref" "D" "*") (command "_.ucs" "_W") (command ".saveas" "" (strcat vDir "\\" vDateStr "\\" vName)) (setvar "filedia" vDia) (setvar "cmdecho" vEcho) (command "_.CLOSE") (princ) ) 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.