JackStone Posted May 20, 2020 Posted May 20, 2020 Hello everyone! I have the following situation: My drawing contains certain entities with XDATA appended do them (usually LWPOLYLINES). If the user explodes one of these entities using the EXPLODE command the new entities created will inherit the XDATA by default. But that is not the behavior I want. What I want to do is this: 1. Obtain the XDATA appended to the EXPLODED entity; 2. Do some XRECORD operations using the XDATA (this part is easy, if I have the XDATA); 3. Remove the XDATA from the newly created entities. I have been attempting to use reactors to solve this problem, but without much success. When I set up a copied reactor, for instance, the third argument (usually identified as "parameters") returns the entity name of the newly created entities. I was hoping there would be an analogous reactor for the EXPLODE command, but I have not found it. Using object reactors I don't seem to be able to retrieve the entity names of the entities created after EXPLODE. I am now considering using a different sort of reactor (maybe one attached to the EXPLODE command?) instead of the object reactor, but I'm afraid a reactor that casts too wide a net might hinder performance. So here I am, seeking help: is it necessary to monitor every instance of the EXPLODE command or is there a better way to solve this problem? I thank you all in advance! Quote
Roy_043 Posted May 20, 2020 Posted May 20, 2020 You could work with a vlr-acdb-reactor and the :vlr-objectappended event. This will monitor all new objects so the callback would have to efficient. If you are very concerned about speed you could use a vlr-command-reactor to switch on the vlr-acdb-reactor and have the callback switch it off again. 1 Quote
JackStone Posted May 25, 2020 Author Posted May 25, 2020 Thank you very much for the idea, Roy. I'll try that out, see how it goes! Quote
hanhphuc Posted June 4, 2020 Posted June 4, 2020 (edited) (setq *appid* "CORONA") (if (tblsearch "APPID" *appid*) (princ (strcat "\n" *appid* " app exists.")) (regapp *appid*) ) (or corona:vs (defun corona:vs (x) (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) x))) (defun c:covid nil (corona (trans (getvar 'viewctr) 1 0) 6 (corona:vs 20.)) (princ)) (defun c:checker (/ os ap k pt ss xd en e $ & l n p) (mapcar '(lambda (a b)(set a (getvar b))) '(os ap) '(osmode aperture)) (setvar 'osmode 0) (setq & "\r ") (terpri) (while (and (setq k (grread t 13 0)) (= (car k) 5)) (redraw) (if (and (setq p (corona:vs ap) ;-p (- p) ss (ssget "_C" (setq pt (cadr k)) (mapcar '+ pt (list (- p) p)))) (setq en (ssname ss 0) e (entget en (list *appid*))) (setq xd (assoc -3 e)) (setq $ (cdr (assoc 1000 (cdadr xd)))) ;(setq $ (cdar (cddadr xd))) ) (progn (redraw en 3) (princ (strcat "\r" $)) ) (princ (setq $ &)) ) (setq n (cos (* 0.25 pi)) l (mapcar '(lambda (x) (polar pt (* pi x) (/ (if (= $ &) (* 0.5 p) p ) n ) ) ) '(0.25 0.75 1.25 1.75) ) ) (mapcar '(lambda (a b) (grdraw a b (if (= $ &) 3 1 ))) l (append (cdr l) (list (car l)))) (princ) ) (redraw) (setvar 'osmode os) (princ) ) (defun corona ( p n r / p a a+ l w ) (setq w (* r 0.1 ) a+ (/ (+ pi pi) n ) a (- a+) ) (repeat (1+ n) (setq l (cons (polar p (setq a (+ a+ a)) r ) l)) ) (entmakex (append (vl-list* '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(70 . 1) (cons 90 (length l)) (apply 'append (mapcar '(lambda (x) (list (cons 10 x)(cons 40 w )(cons 41 w ) )) l) ) ) (list (list -3 (list *appid* '(1002 . "{") (cons 1000 (strcat *appid* " Positive")) (cons 1010 p) '(1002 . "}")))) ) ) ) (vl-load-reactors) (defun c:At-your-own-Risk ( / $) (c:covid) (deactivate '( "pandemic xdata" "action")) (princ) ) (defun c:Stay-Home (/) (if c:At-your-own-Risk (c:At-your-own-Risk) (deactivate '( "pandemic xdata" "action")) ;(vlr-remove-all) ) (vlr-acdb-reactor "pandemic xdata" '((:vlr-objectAppended . ObjectAppendedCallback))) (vlr-command-reactor "action" '((:vlr-commandwillstart . CommandWillstartCallback) (:vlr-commandEnded . CommandEndedCallback) ) ) (princ (strcat "\nBreaking "*appid*" chain!")) (princ) ) (defun CommandwillstartCallback (react callback ) (princ (strcat "\nAction : " (setq *command:explode* (vl-princ-to-string (car callback))) "\n")) ) (defun ObjectAppendedCallback (react callback / en xtype xvalue) (if (and (setq en (cadr callback)) (princ (setq appendedObject (vlax-ename->vla-object en))) (or (vla-getxdata appendedObject *appid* 'xtype 'xvalue) xtype) (setq *exploded* (or *exploded* (wcmatch (strcase (vl-princ-to-string *command:explode*)) "*EXPLODE*"))) ) (setq *appendedObjectlist* (cons appendedObject *appendedObjectlist*)) (setq *explode* nil ) ) (terpri) (princ) ) (defun CommandEndedCallback (react callback) (if (and *appendedObjectlist* (vl-consp *appendedObjectlist*)) (foreach obj *appendedObjectlist* (vl-catch-all-apply 'vla-setxdata (cons obj (mapcar '(lambda (a b) (vlax-safearray-fill (vlax-make-safearray a '(0 . 0)) (list b))) '(2 12) (list 1001 *appid*) ) ) ) ) ) (setq *exploded* nil *appendedObjectlist* nil) (princ) ) (defun c:outbreak (/ *error* ss e xd) (defun *error* (msg) (vl-cmdf "_UNDO" "_END") (princ msg) ) (if (zerop (logand 8 (getvar 'UNDOCTL))) (vl-cmdf "_UNDO" "_BEGIN") ) (c:covid) (if (setq ss (ssget "_:L" (list '(0 . "LWPOLYLINE") (list -3 (list *appid*))))) (progn (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (terpri) (if (setq e (entget x (list *appid*)) xd (assoc -3 e) ) (princ xd) ) ) (command "_EXPLODE" ss) ) (prompt "\nInvalid selection!") ) (vl-cmdf "_UNDO" "_END") (terpri) (princ) ) (defun deactivate ( l ) ;can use vlr-added-p for 'SYM (foreach x (mapcar 'cadr (vlr-reactors)) (terpri) (if (vl-some '(lambda (r) (= r (setq $ (vlr-data x)))) l ) (progn (vlr-remove x) (princ $)) ) ;(princ $) ) ) not to offence, i apologize for weird commands (IMO pandemic to describe xdata maybe easier to understand?) god bless all COVID ;create a sample polygon (LWPolyline) with xdata presents 'positive infection' *note: you can use command COPY more polygons for testing CHECKER ;user hovers cursor over the LWPolyline entities to check whether 'positive' (display xdata & aperture turns RED) ;try it to see the differences STAY-HOME & AT-YOUR-OWN-RISK OUTBREAK ;command EXPLODE with ssget LWPolyline filtered STAY-HOME ;'disinfection' mode (activates reactor) This will remove xdata after command EXPLODE (excepts inherited & exploded line) AT-YOUR-OWN-RISK ;business as usual (deactivates reactor) i.e: outbreak being contagious (EXPLODed sub-entities(LINEs) will inherit xdata) p/s: you can try BCAD reactor with entmod & entget callback, its easier than vla- method Edited June 15, 2020 by hanhphuc update deactivete function / corona:vs as global Quote
JackStone Posted June 14, 2020 Author Posted June 14, 2020 Thank you very much for the (humorous) code! I'll study it carefully. 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.