Lee Mac Posted January 4, 2010 Posted January 4, 2010 IMO, it's easier to manage individual object reactors than a single one with the objects stored in the 'owners' argument of the reactor, for example if the objet is erased. I would disagree with you there Gile, one reactor is easier to handle than what could be thousands. And, if the object is erased, there is a simple check: (if (vlax-erased-p obj) (vlr-owner-remove <reactor obj> obj)) Lee Quote
gile Posted January 4, 2010 Posted January 4, 2010 OK, the example wan't so good... Sorry, I can't remember the exact situation(s) where I found it was easier to deal with one reactor by object... Quote
ollie Posted January 4, 2010 Author Posted January 4, 2010 I would disagree with you there Gile, one reactor is easier to handle than what could be thousands. And, if the object is erased, there is a simple check: (if (vlax-erased-p obj) (vlr-owner-remove <reactor obj> obj)) Lee Hehe that 'Vlax-erased-p' method makes more sense than the method I tried earlier. Roughly (defun AddReactors(objectList) (if(= (listp objectList ) nil) (setq objectList(list ObjectList)) ) (setq ModifiedReactor (vlr-object-reactor ObjectList "SAMPLE Modified" '((:vlr-modified . SomeFunction)))) (setq ErasedReactor (vlr-object-reactor ObjectList "SAMPLE Erased" '((:vlr-erased. EraseMe)))) ) (defun EraseMe(ent reactor params) (vlr-owner-remove ModifiedReactor ent) (vlr-owner-remove ErasedReactor ent) (if (= nil UnErased) (setq UnErased (vlr-object-reactor (list ent) "SAMPLE Unerased" '((:vlr-unerased. AddReactors )))) (vlr-owner-add UnErased ent) ) ) Some times I am amazed at how unnecessarily complicated the solution seems at first glance. Reflecting on the above code however, the ModifiedReactor takes precedent over the ErasedReactor regardless of the order of creation. Anyone know if there is a reactor priority order? EDIT: In the initial code I posted I used the :vlr-object-closed reactor which it turns out automatically is carried out upon running the capture function that adds the reactors. This didn't happen with the single reactor to single object method posted in the original code only when the objects where in list format. It probably still carried out the function right enough but it wasn't noticeable Ollie Quote
Lee Mac Posted January 5, 2010 Posted January 5, 2010 Some times I am amazed at how unnecessarily complicated the solution seems at first glance. I would normally overthink the solution in most cases... But with LISP there is an opportunity for conciseness. Quote
LEsq Posted January 5, 2010 Posted January 5, 2010 I would disagree with you there Gile, one reactor is easier to handle than what could be thousands. And, if the object is erased, there is a simple check: (if (vlax-erased-p obj) (vlr-owner-remove <reactor obj> obj)) Lee Agree. I once used something like the code below: (defun rwiz-isreactor (sym) (and sym (vl-position (read (strcat ":" (vl-symbol-name (type sym)))) (vlr-types)))) (defun rwiz-added-p (reactor) (and reactor (rwiz-isreactor reactor) (vlr-added-p reactor))) (defun rwiz-data-set (reactor notifier dependants) (vlr-data-set reactor (cons (append (list notifier) dependants) (vlr-data reactor)))) (defun rwiz-owner-data-add (reactor notifier dependants) (vlr-owner-add reactor notifier) (rwiz-data-set reactor notifier dependants)) ... And a function to attatch the required objects to the reactor (defun rcmd-vGridBubbles2-attach (vla_line vla_bubble1) (if (and vla_line vla_bubble1 (= (type vla_line) 'vla-object) (= (type vla_bubble1) 'vla-object) (not (vlax-erased-p vla_line)) (not (vlax-erased-p vla_bubble1)) (vlax-read-enabled-p vla_line) (vlax-read-enabled-p vla_bubble1) ) (progn (if (rwiz-added-p rwiz_vgridbubbles2_reactor_line_bubble1) ;; add owner and new data to the reactor (rwiz-owner-data-add ;; reactor rwiz_vgridbubbles2_reactor_line_bubble1 ;; notifier vla_line ;; dependents (list vla_bubble1)) ;; make the reactor the first time and once (setq rwiz_vgridbubbles2_reactor_line_bubble1 ;; notify the reactor to the active document (vlr-set-notification ;; type of reactor: object (vlr-object-reactor ;; notifier (list vla_line) ;; dependents (list (list vla_line vla_bubble1)) ' ((:vlr-modified . rcmd-vgridbubbles2-line-modified) (:vlr-erased . rcmd-vgridbubbles2-erased) (:vlr-copied . rcmd-vgridbubbles2-line-copied))) 'active-document-only))) (if (rwiz-added-p rwiz_vgridbubbles2_reactor_bubble1_line) ;; add owner and new data to the reactor (rwiz-owner-data-add ;; reactor rwiz_vgridbubbles2_reactor_bubble1_line ;; notifier vla_bubble1 ;; dependents (list vla_line)) ;; make the reactor the first time and once (setq rwiz_vgridbubbles2_reactor_bubble1_line ;; notify the reactor to the active document (vlr-set-notification ;; type of reactor: object (vlr-object-reactor ;; notifier (list vla_bubble1) ;; dependents (list (list vla_bubble1 vla_line)) ' ((:vlr-modified . rcmd-vgridbubbles2-bubble1-modified) (:vlr-subObjModified . rcmd-vgridbubbles2-bubble1-subObjModified) (:vlr-erased . rcmd-vgridbubbles2-erased))) 'active-document-only))) (rwiz-attach ;; custom command name "vgridbubbles2" ;; dictionary name, key and objects list ;; note: the objects list is saved in order we want it to be read (list "RCMD-REACTORS" "VGRID-BUBBLES-2" (list vla_line vla_bubble1))) (rcmd-append-ldata "RCMD-REACTORS" "VGRID-BUBBLE-DATA-2" (list vla_bubble1)) ))) 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.