Mara821 Posted November 17, 2018 Posted November 17, 2018 Hi, I need use (command ".save" pth) in my reactor for automatic back up after 30 minutes. But I can not figure out how to write this in Visual LISP. I want save current unsaved dwg to new file, but current dwg has to remain unchanged and still be active. Method (vla-saveAs doc) makes new file but makes active just this new file and close the old one. (vla-save doc) saves only without creating new file. Following code is a part of commandEnded callback reactor: (defun GM:createBackUp (cmd / doc pth) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq pth (strcat (getvar "TEMPPREFIX") (vl-string-right-trim ".dwg" (getvar "DWGNAME")) "_" (rtos (getvar "CDATE") 2 6) ".dwg")) (if (not (wcmatch cmd "QSAVE,SAVEAS")) (progn ;(command ".save" pth) ;;;!!!! (princ "\nCurrent drawing has been saved.")) (vl-file-copy (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")) pth)) (princ (strcat "\nBackup \"" (getvar "DWGNAME") "\" has been created. (" pth ")"))) Thanks. Quote
Grrr Posted November 17, 2018 Posted November 17, 2018 Hi, Perhaps try with vl-file-copy function (I remember ronjonp using it here within reactor for a similar task) Quote
Lee Mac Posted November 17, 2018 Posted November 17, 2018 Some examples: Backup the Current Drawing without Saving Autosave every 20 commands 1 Quote
Mara821 Posted November 24, 2018 Author Posted November 24, 2018 Thanks for replies, but neither one function doesn't backup actual unsaved drawing. They make a copy of drawing from last saving only. It seems it isn't possible, what i would like. Quote
Lee Mac Posted November 24, 2018 Posted November 24, 2018 3 minutes ago, Mara821 said: Thanks for replies, but neither one function doesn't backup actual unsaved drawing. They make a copy of drawing from last saving only. It seems it isn't possible, what i would like. The program in the first link I provided does exactly this. Quote
Grrr Posted November 24, 2018 Posted November 24, 2018 18 minutes ago, Mara821 said: Thanks for replies, but neither one function doesn't backup actual unsaved drawing. They make a copy of drawing from last saving only. It seems it isn't possible, what i would like. You could try alternative approach with the SendCommand method (example). Quote
Mara821 Posted November 24, 2018 Author Posted November 24, 2018 5 hours ago, Lee Mac said: The program in the first link I provided does exactly this. I tried it several times, but new entities (created after manual save) are still missing in backup file. Probably I do something wrong, but i don't know what. 6 hours ago, Grrr said: You could try alternative approach with the SendCommand method (example). I have not known this method. I am trying this way now but I have problem with dialog box, it always opens. (defun c:test (/) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-sendCommand doc "_.save C:\\Users\\Marek\\Desktop\\testBackUp.dwg ") ) This does what i want (command "._save" "C:\\Users\\Marek\\Desktop\\testBackUp.dwg") Quote
Grrr Posted November 25, 2018 Posted November 25, 2018 18 hours ago, Mara821 said: I have not known this method. I am trying this way now but I have problem with dialog box, it always opens. (defun c:test (/) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-sendCommand doc "_.save C:\\Users\\Marek\\Desktop\\testBackUp.dwg ") ) This does what i want (command "._save" "C:\\Users\\Marek\\Desktop\\testBackUp.dwg") Try setting the filedia variable to 0, and reset it back to its original value, example: (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq dsktop (strcat (getenv "userprofile") "\\Desktop\\")) (setq fd (getvar 'filedia)) (setvar 'filedia 0) (vla-SendCommand doc (strcat "_.save " dsktop "testBackUp.dwg" "\r")) (setvar 'filedia fd) Sorry for my late reply! Quote
Mara821 Posted November 25, 2018 Author Posted November 25, 2018 (edited) 5 hours ago, Grrr said: (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq dsktop (strcat (getenv "userprofile") "\\Desktop\\")) (setq fd (getvar 'filedia)) (setvar 'filedia 0) (vla-SendCommand doc (strcat "_.save " dsktop "testBackUp.dwg" "\r")) (setvar 'filedia fd) vla-SendCommand has strange behaviour or it is feature? it executes command after function is finshed, so variable FILEDIA is already back on 1. If I change FILEDIA on 0 manually, it works fine. From help (I read this, but I didn't understand): This method is generally synchronous. However, if the command sent with this method requires any user interaction (such as picking a point on the screen) then this method will continue as soon as the user input begins. The command will then continue to be processed asynchronously. Edited November 25, 2018 by Mara821 I am idiot Quote
Grrr Posted November 25, 2018 Posted November 25, 2018 (edited) 1 hour ago, Mara821 said: vla-SendCommand has strange behaviour or it is feature? it executes command after function is finshed, so variable FILEDIA is already back on 1. If I change FILEDIA on 0 manually, it works fine. Good call, I never tested it much actually - Indeed it is synchronous: (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (vl-prin1-to-string '(command "_.CIRCLE" pause pause)) "\r" (vl-prin1-to-string '(command "_.LINE" pause pause)) "\r" ) ) Because the above will instantly prompt for errors when calling the command, or even if its 2 separate calls like this: (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (vl-prin1-to-string '(command "_.CIRCLE" pause pause)) "\r" ) ) (vla-SendCommand (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (vl-prin1-to-string '(command "_.LINE" pause pause)) "\r" ) ) Would mean that it does its job, sends the string to be executed in the accoreconsole console (the one thats not in VLIDE).. And returns nil instantly, without waiting the user for inputs from the sended string that was executed. Maybe thats because the return from the SendCommand method doesn't depent on the execution string's result (it just sends it and instantly returns nil, without having to wait) Meaning that the LISP code continues evaluating, while the sended string for execution waits for inputs or is just sended with some delay (what a mess). Now that we observed how it behaves, then why not pass a setvar/getvar expression in it : (defun C:test ( / doc dsktop fd ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq dsktop (strcat (getenv "userprofile") "\\Desktop\\")) (setq fd (getvar 'filedia)) (vla-SendCommand doc (strcat "(setvar 'filedia 0)" "\r" "_.save " dsktop "testBackUp.dwg" "\r" "(setvar 'filedia " (itoa fd) ")" "\r" ) ); vla-SendCommand (princ) ) NOTEs: "\r" simulates hitting ENTER key (vl-prin1-to-string '(command ...)) makes easier to write the call Edited November 25, 2018 by Grrr 1 Quote
Mara821 Posted November 26, 2018 Author Posted November 26, 2018 Thank you very much. It works fine Quote
Roy_043 Posted November 27, 2018 Posted November 27, 2018 I don't understand the advantage of using vla-sendcommand. In what way does it improve this?: On 11/24/2018 at 8:50 PM, Mara821 said: This does what i want (command "._save" "C:\\Users\\Marek\\Desktop\\testBackUp.dwg") Quote
Lee Mac Posted November 27, 2018 Posted November 27, 2018 I guess so that it could be used within a reactor callback function. Aside, I wasn't aware that the SAVE command could produce a SAVEAS without changing the active drawing - that's a new one for me, thanks. Quote
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.