chulse Posted April 13, 2010 Posted April 13, 2010 I am working on a reactor to set several things on dwg close. A little background is HERE. The trouble I am having now is that it seems to do what it's supposed to, except it doesn't save the changes. I have this as part of the S::STARTUP (I have a "mystartup" appended to it and saved in the acaddoc.lsp file - shared on our network) Any help greatly appreciated. (defun Create_Close_Reactor() (vl-load-com) (if(not close:reactor) (setq close:reactor (vlr-editor-reactor nil '((:vlr-beginClose . CloseReaction)))) ); end if (princ) ); end of Create_Close_Reactor (defun CloseReaction(args reac / tmp actDoc) (setq actDoc(vla-get-ActiveDocument (vlax-get-acad-object))) (vla-put-ActiveSpace actDoc 1) (vla-ZoomExtents(vlax-get-acad-object)) (vla-put-ActiveLayer actDoc (vla-Item(vla-get-Layers actDoc)"0")) ;;(repeat 3(vla-PurgeAll actDoc)) ;;set ucs to world;; (vla-put-ActiveUCS doc (vla-add (vla-get-usercoordinatesystems doc) (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point '(1. 0. 0.)) (vlax-3D-point '(0. 1. 0.)) "TempWord_UCS")) (vla-Save actDoc) (princ) ); end of CloseReaction (Create_Close_Reactor) Quote
alanjt Posted April 14, 2010 Posted April 14, 2010 You do realize that you can never open a drawing without saving. Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 You do realize that you can never open a drawing without saving. Well no, I didn't... But if I open a dwg, work on it, save it and close it, this reactor appears too make the changes before the close as it is supposed to (change to model space, zoom extents, set the ucs to world, etc - I can watch it do it) but when I open the dwg again, it has not saved those changes?? I'm just not sure what I am missing here... Quote
Lee Mac Posted April 14, 2010 Posted April 14, 2010 (edited) Hi Cary, I might approach it like this: (defun CloseReactor nil (vl-load-com) ;; Lee Mac ~ 14.04.10 ( (lambda ( data / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor) ) ) (cdar (vlr-reactors :vlr-editor-reactor) ) ) ) (if (vlr-added-p react) (vlr-remove react) (vlr-add react) ) (setq react (vlr-editor-reactor data (list (cons :vlr-beginclose 'CloseCallBack) ) ) ) ) (princ (if (vlr-added-p react) "\n** Reactor Activated **" "\n** Reactor Deactivated **" ) ) react ) "Close-Reactor" ) (princ) ) (defun CloseCallBack (reactor arguments) (vla-put-ActiveSpace (setq doc (vla-get-ActiveDocument (setq acad (vlax-get-acad-object)) ) ) acModelSpace ) (vla-ZoomExtents acad) (vla-put-ActiveLayer doc (vla-item (vla-get-layers doc) "0" ) ) (vla-put-ActiveUCS doc (vla-add (vla-get-usercoordinatesystems doc) (vlax-3D-point '(0. 0. 0.)) (vlax-3D-point '(1. 0. 0.)) (vlax-3D-point '(0. 1. 0.)) "TempWord_UCS" ) ) (if (not (eq "" (vla-get-FullName doc))) (vla-saveas doc (vla-get-FullName doc)) ) (princ) ) Here, the reactor function is a toggle, and can be toggled on and off whilst the drawing is open. The reactor will only save the drawing if the drawing has been saved previously. Its untested, but hopefully should work for you. Lee Edited July 5 by Lee Mac 1 Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 I'll give it a shot, thanks. How do you toggle it (what command, I don't see how you did that...)? Quote
Lee Mac Posted April 14, 2010 Posted April 14, 2010 Issuing (CloseReactor) Will toggle the reactor on and off Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 I see. I don't understand it... but I see it Quote
alanjt Posted April 14, 2010 Posted April 14, 2010 Just add something simple... (defun c:Test (/) (CloseReactor)) Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 Just add something simple... (defun c:Test (/) (CloseReactor)) ...so that would assign a normal command line command to the reactor toggle then? (so it didn't need to be written in parenthesis?) Quote
alanjt Posted April 14, 2010 Posted April 14, 2010 ...so that would assign a normal command line command to the reactor toggle then? (so it didn't need to be written in parenthesis?) Correct. Quote
Lee Mac Posted April 14, 2010 Posted April 14, 2010 I find its better to have a toggle/off function with a reactor, with your original function, there was no inherent way to stop the reactor functioning. Quote
Lee Mac Posted April 14, 2010 Posted April 14, 2010 You're welcome, does my code function as expected? Quote
alanjt Posted April 14, 2010 Posted April 14, 2010 I find its better to have a toggle/off function with a reactor, with your original function, there was no inherent way to stop the reactor functioning. ditto 90% of the time. Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 It's ALIVE!!! It works. Thanks However, it is not activated by default - how would I make it activate automatically by default? Quote
Lee Mac Posted April 14, 2010 Posted April 14, 2010 Put (CloseReactor) In your ACADDOC.lsp (make sure the LISP is loaded also). Quote
alanjt Posted April 14, 2010 Posted April 14, 2010 It's ALIVE!!! It works. Thanks However, it is not activated by default - how would I make it activate automatically by default? DANGEROUS!!! :cry: This is something I would recommend you have to turn on. Quote
Lee Mac Posted April 14, 2010 Posted April 14, 2010 DANGEROUS!!! :cry: This is something I would recommend you have to turn on. Cary likes to live life on the edge Quote
alanjt Posted April 14, 2010 Posted April 14, 2010 Cary likes to live life on the edge I seriously do not recommend you have this set to auto on. If you open a file, just to take something from it, print, etc. you will have to remember to turn the reactor off; otherwise, you will be changing the edit date of the file. This may not be a big deal to you, but you really should be aware it. 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.