Author Topic: Object Reactors  (Read 1553 times)

0 Members and 1 Guest are viewing this topic.

jtoverka

  • Newt
  • Posts: 127
Object Reactors
« on: February 11, 2020, 08:49:29 AM »
Gentlemen,

I am developing an application for AutoCAD Electrical. These AutoCAD verticals have a limitation where you can't simply use standard AutoCAD commands if you don't how everything works with the vertical side. For example, if you delete a wire, the wire number needs to be deleted as well. This can be overlooked if you "hide" the wire number (hide means frozen).

So I am trying to use reactors for my problem. In xData, there are pointers to other objects in the drawing. If you delete the object, in some cases, those other pointers must be deleted as well. Especially panel footprints and their item balloons.

However, I can't seem to find a way to read the object being deleted, so I can find those pointers. The object is deleted prior to the reactor function being called.

Help is much appreciated!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Object Reactors
« Reply #1 on: February 11, 2020, 09:51:58 AM »

ribarm

  • Gator
  • Posts: 3272
  • Marko Ribar, architect
Re: Object Reactors
« Reply #2 on: February 11, 2020, 10:03:52 AM »
There is some related things for you to look for in this topic :
https://www.cadtutor.net/forum/topic/68098-reactor-when-entity-copied-how-to-pass-the-ss

I just haven't posted there more codes, but I've mod. my version that operates like command functions - custom erase and custom copy like this :

Code - Auto/Visual Lisp: [Select]
  1. (defun XD_readX ( ename AppName )
  2.   (reverse (cdr (reverse (cddr (assoc AppName (cdr (assoc -3 (entget ename (list "*")))))))))
  3. )
  4.  
  5. (defun SS_getappid ( AppName / filtr ss )
  6.  
  7.   (setq
  8.     AppName (cdr (assoc 2 (tblsearch "APPID" AppName)))
  9.     filtr   (append filtr (list (list -3 (list AppName))))
  10.     ss      (ssget "_X" filtr)
  11.   )
  12.  
  13.   ss
  14. )
  15.  
  16. (defun SS_getallappids ( / a app appl ss )
  17.  
  18.   (setq app (cdr (assoc 2 (setq a (tblnext "APPID" t)))))
  19.   (setq appl (cons app appl))
  20.   (while (setq a (tblnext "APPID"))
  21.     (setq app (cdr (assoc 2 a)))
  22.     (setq appl (cons app appl))
  23.   )
  24.   (setq ss (ssadd))
  25.   (foreach app appl
  26.     (foreach e (if (SS_getappid app) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (SS_getappid app)))))
  27.       (ssadd e ss)
  28.     )
  29.   )
  30.  
  31.   ss
  32. )
  33.  
  34. (defun SS_SSgetXD ( filtr XdChkLst RetFmt AppNameLst / sss ss i ss1 ssl xdl cnt ename Lst )
  35.  
  36.   (setq sss (ssadd))
  37.   (foreach AppName AppNameLst
  38.     (setq
  39.       AppName (cdr (assoc 2 (tblsearch "APPID" AppName)))
  40.       filtr   (append filtr (list (list -3 (list AppName))))
  41.       ss      (ssget "_X" filtr)
  42.     )
  43.     (if ss
  44.       (repeat (setq i (sslength ss))
  45.         (if (not (ssmemb (ssname ss (setq i (1- i))) sss))
  46.           (ssadd (ssname ss i) sss)
  47.         )
  48.       )
  49.     )
  50.   )
  51.  
  52.   (if (= RetFmt 0)
  53.     (setq ss1 (ssadd))
  54.   )
  55.  
  56.   (if sss
  57.     (progn
  58.       (setq
  59.         ssl      (sslength sss)
  60.         cnt      0
  61.       )
  62.       (repeat ssl
  63.         (setq
  64.           ename (ssname sss cnt)
  65.           cnt   (1+ cnt)
  66.         )
  67.         (foreach AppName AppNameLst
  68.           (setq xdl (cons (XD_readX ename AppName) xdl))
  69.         )
  70.         (setq xdl (reverse xdl))
  71.         (if xdl
  72.           (progn
  73.             (if (equal xdl XdChkLst)
  74.               (if (= RetFmt 0)
  75.                 (ssadd ename ss1)
  76.                 (setq Lst (cons ename Lst))
  77.               )
  78.             )
  79.             (setq xdl nil)
  80.           )
  81.         )
  82.       )
  83.     )
  84.   )
  85.  
  86.   (if (= RetFmt 0)
  87.     (if (> (sslength ss1) 0)
  88.       ss1
  89.       nil
  90.     )
  91.     Lst
  92.   )
  93. )
  94.  
  95.  
  96.  
  97. (defun c:copyent-txtlinks ( / ent txtss bp dp entn i txt )
  98.   (while
  99.     (or
  100.       (not (setq ent (car (entsel "\nPick curve entity to copy along with text links..."))))
  101.       (if ent
  102.         (or
  103.           (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendpoint (list ent)))
  104.           (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 (entget ent))))))))
  105.         )
  106.       )
  107.     )
  108.     (prompt "\nMissed or picked wrong entity type or picked curve on locked layer...")
  109.   )
  110.   (setq txtss (SS_SSgetXD '((0 . "TEXT")) (list (list (cons 1005 (cdr (assoc 5 (entget ent)))))) 0 '("txt2entlnks")))
  111.   (initget 1)
  112.   (setq bp (getpoint "\nPick or specify base point : "))
  113.   (initget 1)
  114.   (setq dp (getpoint bp "\nPick or specify destination point : "))
  115.   (vl-cmdf "_.COPY" ent "" "_non" bp "_non" dp)
  116.   (setq entn (entlast))
  117.   (repeat (setq i (sslength txtss))
  118.     (setq txt (ssname txtss (setq i (1- i))))
  119.     (vl-cmdf "_.COPY" txt "" "_non" bp "_non" dp)
  120.     (entupd (cdr (assoc -1 (entmod (subst (cons 1 (if (= (cdr (assoc 1 (entget (entlast)))) (cdr (assoc 5 (entget ent)))) (cdr (assoc 5 (entget entn))) (cdr (assoc 1 (entget txt))))) (assoc 1 (entget (entlast) '("*"))) (subst (list -3 (list "txt2entlnks" '(1002 . "{") (cons 1005 (cdr (assoc 5 (entget entn)))) '(1002 . "}"))) (assoc -3 (entget (entlast) '("*"))) (entget (entlast) '("*"))))))))
  121.   )
  122.   (vlr-remove *TheObjReactor*)
  123.   (setq *TheObjReactor*
  124.       (
  125.         (lambda ( / SS i L )
  126.           (if (setq SS (ssget "_X" (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  127.             (repeat (setq i (sslength SS))
  128.               (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  129.             )
  130.           )
  131.           (reverse L)
  132.         )
  133.       )
  134.       "Curves Object Reactor"
  135.       '((:VLR-modified . CUR:ObjReactor))
  136.     )
  137.   )
  138.   (vl-cmdf "_.REGEN")
  139.   (princ)
  140. )
  141.  
  142. (defun c:eraseent-txtlinks ( / ent txtss )
  143.   (while
  144.     (or
  145.       (not (setq ent (car (entsel "\nPick curve entity to delete along with text links..."))))
  146.       (if ent
  147.         (or
  148.           (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendpoint (list ent)))
  149.           (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 (entget ent))))))))
  150.         )
  151.       )
  152.     )
  153.     (prompt "\nMissed or picked wrong entity type or picked curve on locked layer...")
  154.   )
  155.   (setq txtss (SS_SSgetXD '((0 . "TEXT")) (list (list (cons 1005 (cdr (assoc 5 (entget ent)))))) 0 '("txt2entlnks")))
  156.   (ssadd ent txtss)
  157.   (acet-ss-entdel txtss)
  158.   (vlr-remove *TheObjReactor*)
  159.   (setq *TheObjReactor*
  160.       (
  161.         (lambda ( / SS i L )
  162.           (if (setq SS (ssget "_X" (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  163.             (repeat (setq i (sslength SS))
  164.               (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  165.             )
  166.           )
  167.           (reverse L)
  168.         )
  169.       )
  170.       "Curves Object Reactor"
  171.       '((:VLR-modified . CUR:ObjReactor))
  172.     )
  173.   )
  174.   (princ)
  175. )
  176.  
  177. (defun CUR:ObjReactor ( owner reactor lstename / txtss i txt txtx )
  178.   (if (and (not (vlax-erased-p owner)) (vl-position owner (vlr-owners *TheObjReactor*)))
  179.     (progn
  180.       (if (not (tblsearch "APPID" "txt2entlnks"))
  181.         (regapp "txt2entlnks")
  182.       )
  183.       (setq txtss (SS_SSgetXD '((0 . "TEXT")) (list (list (cons 1005 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))))) 0 '("txt2entlnks")))
  184.       (if txtss
  185.         (repeat (setq i (sslength txtss))
  186.           (setq txt (ssname txtss (setq i (1- i))))
  187.           (setq txtx (entget txt '("*")))
  188.           (if (or (and (/= (cdr (assoc 1 txtx)) "hand") (/= (cdr (assoc 1 txtx)) (cdr (assoc 5 (entget (vlax-vla-object->ename owner)))))) (= (cdr (assoc 1 txtx)) "dist"))
  189.             (setq txtx (subst (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0))) (assoc 11 txtx) (subst (cons 1 (rtos (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2 2)) (assoc 1 txtx) txtx)))
  190.             (setq txtx (subst (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0))) (assoc 11 txtx) (subst (cons 1 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))) (assoc 1 txtx) txtx)))
  191.           )
  192.           (entupd (cdr (assoc -1 (entmod txtx))))
  193.         )
  194.         (progn
  195.           (entmake
  196.             (list
  197.               '(0 . "TEXT")
  198.               '(100 . "AcDbEntity")
  199.               (cons 67 (getvar 'tilemode))
  200.               (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model"))
  201.               '(100 . "AcDbText")
  202.               (cons 10 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  203.               (cons 40 (if (not (zerop (getvar 'textsize))) (getvar 'textsize) (getvar 'dimtxt)))
  204.               (cons 1 (cdr (assoc 5 (entget (vlax-vla-object->ename owner)))))
  205.               '(50 . 0.0)
  206.               '(41 . 1.0)
  207.               '(51 . 0.0)
  208.               (cons 7 (getvar 'textstyle))
  209.               '(71 . 0)
  210.               '(72 . 1)
  211.               (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  212.               '(210 0.0 0.0 1.0)
  213.               '(100 . "AcDbText")
  214.               '(73 . 1)
  215.             )
  216.           )
  217.           (entupd (cdr (assoc -1 (entmod (append (entget (entlast)) (list (list -3 (list "txt2entlnks" '(1002 . "{") (cons 1005 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))) '(1002 . "}")))))))))
  218.           (entmake
  219.             (list
  220.               '(0 . "TEXT")
  221.               '(100 . "AcDbEntity")
  222.               (cons 67 (getvar 'tilemode))
  223.               (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model"))
  224.               '(100 . "AcDbText")
  225.               (cons 10 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  226.               (cons 40 (if (not (zerop (getvar 'textsize))) (getvar 'textsize) (getvar 'dimtxt)))
  227.               (cons 1 (rtos (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2 2))
  228.               '(50 . 0.0)
  229.               '(41 . 1.0)
  230.               '(51 . 0.0)
  231.               (cons 7 (getvar 'textstyle))
  232.               '(71 . 0)
  233.               '(72 . 1)
  234.               (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  235.               '(210 0.0 0.0 1.0)
  236.               '(100 . "AcDbText")
  237.               '(73 . 3)
  238.             )
  239.           )
  240.           (entupd (cdr (assoc -1 (entmod (append (entget (entlast)) (list (list -3 (list "txt2entlnks" '(1002 . "{") (cons 1005 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))) '(1002 . "}")))))))))
  241.         )
  242.       )
  243.       (princ "\nReaction Modify executed")
  244.     )
  245.   )
  246.   (princ "\nReaction Modify occured")
  247. )
  248.  
  249. (setq *TheObjReactor*
  250.     (
  251.       (lambda ( / SS i L )
  252.         (if (setq SS (ssget "_X" (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  253.           (repeat (setq i (sslength SS))
  254.             (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  255.           )
  256.         )
  257.         (reverse L)
  258.       )
  259.     )
  260.     "Curves Object Reactor"
  261.     '((:VLR-modified . CUR:ObjReactor))
  262.   )
  263. )
  264.  
  265. (setvar 'textsize (* 10.0 (/ (getvar 'viewsize) (cadr (getvar 'screensize)))))
  266. (setvar 'copymode 0)
  267.  
  268.  

But if you want to use built-in erase and copy or grip-edit (modify), you'll probably have to go with storing entity handles in global list for usage with Object Reactor... Here is version that does that with combination of Object and DeepClone Reactor :

Code - Auto/Visual Lisp: [Select]
  1. (defun XD_readX ( ename AppName )
  2.   (reverse (cdr (reverse (cddr (assoc AppName (cdr (assoc -3 (entget ename (list "*")))))))))
  3. )
  4.  
  5. (defun SS_getappid ( AppName / filtr ss )
  6.  
  7.   (setq
  8.     AppName (cdr (assoc 2 (tblsearch "APPID" AppName)))
  9.     filtr   (append filtr (list (list -3 (list AppName))))
  10.     ss      (ssget "_X" filtr)
  11.   )
  12.  
  13.   ss
  14. )
  15.  
  16. (defun SS_getallappids ( / a app appl ss )
  17.  
  18.   (setq app (cdr (assoc 2 (setq a (tblnext "APPID" t)))))
  19.   (setq appl (cons app appl))
  20.   (while (setq a (tblnext "APPID"))
  21.     (setq app (cdr (assoc 2 a)))
  22.     (setq appl (cons app appl))
  23.   )
  24.   (setq ss (ssadd))
  25.   (foreach app appl
  26.     (foreach e (if (SS_getappid app) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (SS_getappid app)))))
  27.       (ssadd e ss)
  28.     )
  29.   )
  30.  
  31.   ss
  32. )
  33.  
  34. (defun SS_SSgetXD ( filtr XdChkLst RetFmt AppNameLst / sss ss i ss1 ssl xdl cnt ename Lst )
  35.  
  36.   (setq sss (ssadd))
  37.   (foreach AppName AppNameLst
  38.     (setq
  39.       AppName (cdr (assoc 2 (tblsearch "APPID" AppName)))
  40.       filtr   (append filtr (list (list -3 (list AppName))))
  41.       ss      (ssget "_X" filtr)
  42.     )
  43.     (if ss
  44.       (repeat (setq i (sslength ss))
  45.         (if (not (ssmemb (ssname ss (setq i (1- i))) sss))
  46.           (ssadd (ssname ss i) sss)
  47.         )
  48.       )
  49.     )
  50.   )
  51.  
  52.   (if (= RetFmt 0)
  53.     (setq ss1 (ssadd))
  54.   )
  55.  
  56.   (if sss
  57.     (progn
  58.       (setq
  59.         ssl      (sslength sss)
  60.         cnt      0
  61.       )
  62.       (repeat ssl
  63.         (setq
  64.           ename (ssname sss cnt)
  65.           cnt   (1+ cnt)
  66.         )
  67.         (foreach AppName AppNameLst
  68.           (setq xdl (cons (XD_readX ename AppName) xdl))
  69.         )
  70.         (setq xdl (reverse xdl))
  71.         (if xdl
  72.           (progn
  73.             (if (equal xdl XdChkLst)
  74.               (if (= RetFmt 0)
  75.                 (ssadd ename ss1)
  76.                 (setq Lst (cons ename Lst))
  77.               )
  78.             )
  79.             (setq xdl nil)
  80.           )
  81.         )
  82.       )
  83.     )
  84.   )
  85.  
  86.   (if (= RetFmt 0)
  87.     (if (> (sslength ss1) 0)
  88.       ss1
  89.       nil
  90.     )
  91.     Lst
  92.   )
  93. )
  94.  
  95.  
  96. (setq *owners-hnd-lst* nil)
  97.  
  98. (defun COP:DeepCloneReactor ( reactor lst )
  99.   (vlr-remove *TheObjReactor*)
  100.   (setq *TheObjReactor*
  101.       (
  102.         (lambda ( / SS i L )
  103.           (if (setq SS (ssget "_X" (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  104.             (repeat (setq i (sslength SS))
  105.               (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  106.             )
  107.           )
  108.           (setq *owners-hnd-lst* (mapcar '(lambda ( x ) (list x (cdr (assoc 5 (entget (vlax-vla-object->ename x)))))) (reverse L)))
  109.           (reverse L)
  110.         )
  111.       )
  112.       "Curves Object Reactor"
  113.       '((:VLR-modified . CUR:ObjReactor))
  114.     )
  115.   )
  116.   (princ "\nReaction Copy occured")
  117. )
  118.  
  119. (defun CUR:ObjReactor ( owner reactor lstename / txtss i txt txtx )
  120.   (cond
  121.     ( (and (not (vlax-erased-p owner)) (vl-position owner (vlr-owners *TheObjReactor*)))
  122.       (if (not (tblsearch "APPID" "txt2entlnks"))
  123.         (regapp "txt2entlnks")
  124.       )
  125.       (setq txtss (SS_SSgetXD '((0 . "TEXT")) (list (list (cons 1005 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))))) 0 '("txt2entlnks")))
  126.       (if txtss
  127.         (repeat (setq i (sslength txtss))
  128.           (setq txt (ssname txtss (setq i (1- i))))
  129.           (setq txtx (entget txt '("*")))
  130.           (if (or (and (/= (cdr (assoc 1 txtx)) "hand") (/= (cdr (assoc 1 txtx)) (cdr (assoc 5 (entget (vlax-vla-object->ename owner)))))) (= (cdr (assoc 1 txtx)) "dist"))
  131.             (setq txtx (subst (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0))) (assoc 11 txtx) (subst (cons 1 (rtos (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2 2)) (assoc 1 txtx) txtx)))
  132.             (setq txtx (subst (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0))) (assoc 11 txtx) (subst (cons 1 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))) (assoc 1 txtx) txtx)))
  133.           )
  134.           (entupd (cdr (assoc -1 (entmod txtx))))
  135.         )
  136.         (progn
  137.           (entmake
  138.             (list
  139.               '(0 . "TEXT")
  140.               '(100 . "AcDbEntity")
  141.               (cons 67 (getvar 'tilemode))
  142.               (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model"))
  143.               '(100 . "AcDbText")
  144.               (cons 10 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  145.               (cons 40 (if (not (zerop (getvar 'textsize))) (getvar 'textsize) (getvar 'dimtxt)))
  146.               (cons 1 (cdr (assoc 5 (entget (vlax-vla-object->ename owner)))))
  147.               '(50 . 0.0)
  148.               '(41 . 1.0)
  149.               '(51 . 0.0)
  150.               (cons 7 (getvar 'textstyle))
  151.               '(71 . 0)
  152.               '(72 . 1)
  153.               (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  154.               '(210 0.0 0.0 1.0)
  155.               '(100 . "AcDbText")
  156.               '(73 . 1)
  157.             )
  158.           )
  159.           (entupd (cdr (assoc -1 (entmod (append (entget (entlast)) (list (list -3 (list "txt2entlnks" '(1002 . "{") (cons 1005 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))) '(1002 . "}")))))))))
  160.           (entmake
  161.             (list
  162.               '(0 . "TEXT")
  163.               '(100 . "AcDbEntity")
  164.               (cons 67 (getvar 'tilemode))
  165.               (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model"))
  166.               '(100 . "AcDbText")
  167.               (cons 10 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  168.               (cons 40 (if (not (zerop (getvar 'textsize))) (getvar 'textsize) (getvar 'dimtxt)))
  169.               (cons 1 (rtos (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2 2))
  170.               '(50 . 0.0)
  171.               '(41 . 1.0)
  172.               '(51 . 0.0)
  173.               (cons 7 (getvar 'textstyle))
  174.               '(71 . 0)
  175.               '(72 . 1)
  176.               (cons 11 (vlax-curve-getpointatdist owner (/ (vlax-curve-getdistatparam owner (vlax-curve-getendparam owner)) 2.0)))
  177.               '(210 0.0 0.0 1.0)
  178.               '(100 . "AcDbText")
  179.               '(73 . 3)
  180.             )
  181.           )
  182.           (entupd (cdr (assoc -1 (entmod (append (entget (entlast)) (list (list -3 (list "txt2entlnks" '(1002 . "{") (cons 1005 (cdr (assoc 5 (entget (vlax-vla-object->ename owner))))) '(1002 . "}")))))))))
  183.         )
  184.       )
  185.       (princ "\nReaction Modify executed")
  186.     )
  187.     ( (vlax-erased-p owner)
  188.       (foreach own-hnd *owners-hnd-lst*
  189.         (if (eq owner (car own-hnd))
  190.           (progn
  191.             (setq txtss (SS_SSgetXD '((0 . "TEXT")) (list (list (cons 1005 (cadr own-hnd)))) 0 '("txt2entlnks")))
  192.             (if txtss
  193.               (acet-ss-entdel txtss)
  194.             )
  195.           )
  196.         )
  197.       )
  198.       (princ "\nReaction Modify executed")
  199.     )
  200.   )
  201.   (princ "\nReaction Modify occured")
  202. )
  203.  
  204. (setq *TheObjReactor*
  205.     (
  206.       (lambda ( / SS i L )
  207.         (if (setq SS (ssget "_X" (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  208.           (repeat (setq i (sslength SS))
  209.             (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  210.           )
  211.         )
  212.         (setq *owners-hnd-lst* (mapcar '(lambda ( x ) (list x (cdr (assoc 5 (entget (vlax-vla-object->ename x)))))) (reverse L)))
  213.         (reverse L)
  214.       )
  215.     )
  216.     "Curves Object Reactor"
  217.     '((:VLR-modified . CUR:ObjReactor))
  218.   )
  219. )
  220.  
  221. (setq *TheDeepCloneReactor*
  222.     "Curves Deep Clone Reactor"
  223.     '((:VLR-enddeepclone . COP:DeepCloneReactor))
  224.   )
  225. )
  226.  
  227. (setvar 'textsize (* 10.0 (/ (getvar 'viewsize) (cadr (getvar 'screensize)))))
  228. (setvar 'copymode 1)
  229.  
  230.  

This is all related with topic I gave you link at CadTutor site and IMHO, you should be able to find what you're looking for with using XDATA and entity HANDLES, but be aware that second code operates with global list and if list is altered in any way you may experience unpredicted behaviour... What is the main point as far as my investigation explains, the trick is in Object Reactor - when you want to add/remove owners, you should avoid using (vlr-owner-add) and (vlr-owner-remove) - this is buggy - you have to redefine Reactor with complete newly owner list like you are firstly defining it - AFAIK this is the only way to make it operate as desired IMHO...

HTH., M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

jtoverka

  • Newt
  • Posts: 127
Re: Object Reactors
« Reply #3 on: February 11, 2020, 11:17:56 AM »
Thank you,

There was a lot of useful information related to this topic there.

I ended up storing the attributes and xData as reactor data. Every time it is modified, I update the reactor data. Then if it is deleted, I use that reactor data instead of reading the object. It works like a charm!