TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ronjonp on April 29, 2005, 05:04:03 PM

Title: reactor linking objects
Post by: ronjonp on April 29, 2005, 05:04:03 PM
I was parusing the help file and saw reactors. My question is, how do I get an object to react when another object is modified? Example:

text is linked to object with area when area changes text updates to new area value. I've seen a vlx that does this but wanted to know how it works.

Here is my feeble attempt:

Code: [Select]
(defun c:react (/)

  (defun print-radius (notifier-object reactor-object parameter-list)
    (vl-load-com)
    (cond
      (
       (vlax-property-available-p
notifier-object
"Area"
       )
       (princ "\n The area is ")
       (princ (vla-get-area notifier-object))
       (princ)
      )
    )
  )

  (defun print-text (notifier-object reactor-object parameter-list)
    (vl-load-com)
    (cond
      (
     (setq x (vlax-property-available-p
notifier-object
"TextString"
       ))
(vla-put-TextString obj  x)
      )
    )
  )

  (setq myCircle (car (entsel)))
  (setq obj (vlax-ename->vla-object myCircle))
  (setq circleReactor
(vlr-object-reactor
  (list obj)
  "Circle Reactor"
  '((:vlr-modified . print-radius))
)
  )
  (princ)

  (setq mytext (car (entsel)))
  (setq obj (vlax-ename->vla-object mytext))
  (setq textReactor
(vlr-object-reactor
  (list obj)
  "Text Reactor"
  '((:vlr-modified . print-text))
)
  )
  (princ)
)


Thanks for your help.

Ron
Title: reactor linking objects
Post by: SMadsen on April 30, 2005, 11:41:34 AM
Some quick ideas:
XData: Have the area object refer to a text object by handle (a 1005 group).
Dictionary: Maintain arrays of referencing objects as XRecords (just like groups do it).
The object reactor itself: Use the data field of the reactor to refer to a text object.
Groups: Self-explanatory.

In any case, make sure that you verify the referenced objects before using them. You don't want an error due to handling non-existing objects during a reactor callback. Also, AUDIT has a problem with handles in 1005 groups if they are lost.
Title: reactor linking objects
Post by: MP on April 30, 2005, 12:24:25 PM
Good advice Stig. If I'm not mistaken you can set the 1005 group data to "0" for objects that have gone to hades and audit won't balk.
Title: reactor linking objects
Post by: Crank on May 01, 2005, 07:02:50 AM
It's a nice exercise...

But if you only need a linked text to display the area, then you can better use a field to do just that.
Title: reactor linking objects
Post by: ronjonp on May 02, 2005, 09:15:57 AM
Quote
then you can better use a field to do just that.


That is true...but then the field will only work in Acad 2005+.

Ron