Author Topic: Reactor Circle and Text  (Read 4144 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Reactor Circle and Text
« on: May 02, 2010, 10:56:53 PM »
I got still problem to run a code reactor,I headache with the notifier-object, here my code
Code: [Select]
(defun c:rcat (/ c1 el1 el2 ht objlst obj_reactor
       p1 rad tex txt vevo1 vveo2 vgad vgao vgms)
  (vl-load-com)
  (setq vgao (vlax-get-acad-object))
  (setq vgad (vla-get-activedocument vgao))
  (setq vgms (vla-get-modelspace vgad))
  (setq p1 (getpoint "\nClick any location for first circle <0,0,0>: "))
  (if (= p1 nil)(setq p1 '(0 0 0)))
  (setq rad (getdist "\nEnter value radius for circle <5>: "))
  (if (= rad nil)(setq rad 5))
  (setq c1 (vla-addCircle vgms (vlax-3d-point p1) rad))
  (setq el1 (entlast))
  (vla-put-color c1 acred)
  (setq txt (itoa rad))
  (setq ht (* rad 0.2))
  (setq tex (vla-addtext vgms txt (vlax-3d-point p1) ht))
  (setq el2 (entlast))
  (vla-put-color tex acblue) 
  (setq vevo1 (vlax-ename->vla-object el1))
  (setq vevo2 (vlax-ename->vla-object el2))
  (setq objlst (list vevo1 vevo2))
  (setq obj_reactor (vlr-object-reactor
      objlst
      nil
      '((:vlr-modified . callback))))
  )

(defun callback (notifier-object obj_reactor parameter-list
/ obj rad1 tex)
  (setq obj1 (car (vlr-owners obj_reactor))) ; #<VLA-OBJECT IAcadText2 08fbc804>
  (if
    obj1
    (setq tex (vlax-get-property notifier-object 'TextString))
    ) ; if
  (setq obj2 (cadr (vlr-owners obj_reactor))); #<VLA-OBJECT IAcadCircle 08fbb024>
  (if
    obj2
    (setq rad1 (vlax-get-property notifier-object 'radius))
    ) ; if
  (vlax-put-property obj2 'radius tex)
  (vlax-put-property obj1 'TextString rad1)   
  )   ; defun



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #1 on: May 02, 2010, 11:06:45 PM »
What is the problem ?
What is it doing that you don't expect ?
What isn't it doing that you expect ?
Which version of AutoCAD ?

You say STILL have a problem ..
Is it the same problem or a different one ?
What was the original problem ?

Some of us aren't mindreaders :)



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Reactor Circle and Text
« Reply #2 on: May 02, 2010, 11:14:28 PM »
I'm very sorry Kerry my question not yet clear,if I edit a cicle and text inner circle should be change to as circle edit,as example I edit radius become "3" and text should follow it, but this object not there is rection
I hope this enough.

What is the problem ?
What is it doing that you don't expect ?
What isn't it doing that you expect ?
Which version of AutoCAD ?

You say STILL have a problem ..
Is it the same problem or a different one ?
What was the original problem ?

Some of us aren't mindreaders :)





Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #3 on: May 02, 2010, 11:59:44 PM »

I'll have a look .. be a little while
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #4 on: May 03, 2010, 12:45:30 AM »
You're trying to get properties that don't exist in the callback.
For instance
if the notifier is Circle, you're trying to
(setq tex (vlax-get-property notifier-object 'TextString))
which will error.
I also think you'd get a circular reference ... but perhaps not ..

Also, you are not showing due consideration for the TYPE of the properties
... you are trying to allocate a double(real) in place of a string  and a string in place of a double.

Have a look at the sample code in :-
C:\Program Files\Autodesk\ACAD whatever\Sample\VisualLISP\reactors\a-mtext.lsp and rutils.lsp
which does essentially what you want.


also as a general note: the name (defun callback is not good.
rcat_callback would be better and less likely to be reproduced.
« Last Edit: May 03, 2010, 01:15:57 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Reactor Circle and Text
« Reply #5 on: May 03, 2010, 09:22:48 PM »
That right Kerry you are was info to me very clear and this information would open my brain to know more, very sorry my code to many wrong, I would learn as you reference.

You're trying to get properties that don't exist in the callback.
For instance
if the notifier is Circle, you're trying to
(setq tex (vlax-get-property notifier-object 'TextString))
which will error.
I also think you'd get a circular reference ... but perhaps not ..

Also, you are not showing due consideration for the TYPE of the properties
... you are trying to allocate a double(real) in place of a string  and a string in place of a double.

Have a look at the sample code in :-
C:\Program Files\Autodesk\ACAD whatever\Sample\VisualLISP\reactors\a-mtext.lsp and rutils.lsp
which does essentially what you want.


also as a general note: the name (defun callback is not good.
rcat_callback would be better and less likely to be reproduced.


Adesu

  • Guest
Re: Reactor Circle and Text
« Reply #6 on: May 04, 2010, 12:21:19 AM »
Hi Kerry, I just adopted reactor code from sample as your reference, here my new code and it's ok
Quote
(defun c:rcat (/ c1 el1 el2 ht objlst obj_reactor
          p1 rad tex txt  vla-circle vla-text vgad vgao vgms)
  (vl-load-com)
  (setq vgao (vlax-get-acad-object))
  (setq vgad (vla-get-activedocument vgao))
  (setq vgms (vla-get-modelspace vgad))
  (setq p1 (getpoint "\nClick any location for first circle <0,0,0>: "))
  (if (= p1 nil)(setq p1 '(0 0 0)))
  (setq rad (getdist "\nEnter value radius for circle <5>: "))
  (if (= rad nil)(setq rad 5))
  (setq c1 (vla-addCircle vgms (vlax-3d-point p1) rad))
  (setq el1 (entlast))
  (vla-put-color c1 acred)
  (setq txt (itoa rad))
  (setq ht (* rad 0.2))
  (setq tex (vla-addtext vgms txt (vlax-3d-point p1) ht))
  (setq el2 (entlast))
  (vla-put-color tex acblue) 
  (setq vla-circle (vlax-ename->vla-object el1))
  (setq vla-text (vlax-ename->vla-object el2))   
  (setq r1 (vlr-object-reactor
        (list vla-circle)
        vla-text
        '((:vlr-modified . reactor-circle->text))))
  (setq r2  (vlr-object-reactor
         (list vla-text)
         vla-circle
         '((:vlr-modified . reactor-text->circle)))) 
  ) ; defun

(defun reactor-circle->text (notifier reactor arg-list)
  (update-tex-for-circle (vlr-data reactor) notifier)
  ) ; defun


(defun reactor-text->circle (notifier reactor arg-list)
  (update-circle-for-text (vlr-data reactor) notifier)
  ) ; defun

(defun update-tex-for-circle (vla-text vla-circle / inspoint width height text)
  (setq inspoint (vlax-get-property vla-text 'InsertionPoint))
  (setq inspoint (vlax-safearray->list (vlax-variant-value inspoint)))
  ;(setq width (vlax-get-property vla-mTxT 'InsertionPoint)) 
  (setq height (vlax-get-property vla-text 'Height))
  (setq text (vlax-get-property vla-text 'TextString)) 
  (if
    (set-text-params-for-circle vla-circle)
    (progn
      (update-parameter vla-text "InsertionPoint" inspoint)
      ;(update-parameter vla-mtext "width" width)
      (update-parameter vla-text "height" height)
      (update-parameter vla-text "TextString" text)
      ) ; progn
    )   ; if
  )     ; defun


(defun update-circle-for-text (vla-circle vla-text / rad center)
  (if
    (set-circle-params-for-text vla-text)
    (progn
      (if
   (and rad (> rad 0))
   (update-parameter vla-circle "Radius" rad)
   ) ; if
      (update-parameter vla-circle "Center" center)
      )   ; progn
    )     ; if
  )       ; defun


(defun update-parameter   (vla-obj par-name par-value /)
  (if
    (eq (type par-value) 'VARIANT)
    (if
      (> (vlax-variant-type par-value) 8192)
      (setq par-value (vlax-safearray->list (vlax-variant-value par-value)))
      ) ; if
    )   ; if
  (if
    (and (= (type vla-obj) 'VLA-OBJECT)
    (vlax-write-enabled-p vla-obj)
    (not (equal (vlax-get vla-obj par-name) par-value)))
    (vlax-put vla-obj par-name par-value)
    ) ; if
  )   ; defun

(defun set-text-params-for-circle (vla-circle)
  (if
    (and (= (type vla-circle) 'VLA-OBJECT)(vlax-read-enabled-p vla-circle))
    (progn
      (setq inspoint (vla-get-center vla-circle))
      (setq width (vla-get-radius vla-circle))
      (setq text (rtos width))
      (setq height (/ width 3))
      (setq width (/ width 4))
      ) ; progn
    )   ; if
  )     ; defun

(defun set-circle-params-for-text (vla-text)
  (if
    (and (= (type vla-text) 'VLA-OBJECT)(vlax-read-enabled-p vla-text))
    (setq rad (atof (vla-get-textstring vla-text)))
    (setq center (vla-get-insertionpoint vla-text))
    ) ; if
  )   ; defun



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #7 on: May 04, 2010, 09:23:11 AM »

I think you may have some problems with that.

I'll run a test and come back.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #8 on: May 04, 2010, 09:34:06 AM »
Looks like the TextSize (height)  won't update when the text is changed
and errors occur if the text is erased.


I'll have a play.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #9 on: May 04, 2010, 10:10:56 AM »


Try this :

I changed the text justification but can't get it to stick when the text is revised.

Otherwise, the Text Height will update, and the circle or text can be erased without an error.

Code: [Select]
(defun c:rcat_2 (/ p1 rad vla-circle vla-text vgms)
  (vl-load-com)
  (setq
    vgms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  )
  (or (setq p1 (getpoint "\nClick any location for first circle <0,0,0>: "))
      (setq p1 '(0 0 0))
  )
  (or (setq rad (getdist p1 "\nEnter value radius for circle <5>: "))
      (setq rad 5)
  )
  (setq P1         (vlax-3d-point p1)
        vla-circle (vla-addcircle vgms P1 rad)
  )
  (vla-put-color vla-circle acred)
  ;;
  (setq vla-text (vla-addtext vgms (rtos rad) P1 (* rad 0.4)))
  (vla-put-color vla-text acblue)
  (vla-put-alignment vla-text acalignmentmiddlecenter)
  (vla-put-textalignmentpoint vla-text P1)
  ;;
  ;; save the reactor in case we want to disable it later
  ;;
  (setq *gv-reactor-circle->text (vlr-object-reactor
                                   (list vla-circle)
                                   vla-text
                                   '((:vlr-modified . reactor-circle->text))
                                 )
  )
  (setq *gv-reactor-text->circle (vlr-object-reactor
                                   (list vla-text)
                                   vla-circle
                                   '((:vlr-modified . reactor-text->circle))
                                 )
  )
  (princ)
)
;;;-------------------------------------------------------------------------------
(defun reactor-circle->text (notifier reactor arg-list)
  ;; (setq xx (vlr-data reactor))
  (update-text-for-circle (vlr-data reactor) notifier)
)
;;;-------------------------------------------------------------------------------
(defun reactor-text->circle (notifier reactor arg-list)
  (update-circle-for-text (vlr-data reactor) notifier)
)
;;;-------------------------------------------------------------------------------
(defun update-text-for-circle (vla-text vla-circle / width height text)
  (if (and (vlax-write-enabled-p vla-text)
           (vlax-read-enabled-p vla-circle)
           (setq rad (vla-get-radius vla-circle))
           (setq P1 (vla-get-center vla-circle))
      )
    (progn (vla-put-insertionpoint vla-text P1)
           (vla-put-height vla-text (* rad 0.4))
           (vla-put-textstring vla-text (rtos rad))
           (vla-put-alignment vla-text acalignmentmiddlecenter)
           (vla-put-textalignmentpoint vla-text P1)
    )
  )
)
;;;-------------------------------------------------------------------------------
(defun update-circle-for-text (vla-circle vla-text / rad center)
  (if (and (vlax-write-enabled-p vla-circle)
           (vlax-read-enabled-p vla-text)
           (setq rad (atof (vla-get-textstring vla-text)))
           (setq P1 (vla-get-insertionpoint vla-text))
      )
    (progn (if (and rad (> rad 0) (/= rad (vla-get-radius vla-circle)))
             (vla-put-Radius vla-circle rad)
           )
           (vla-put-center vla-circle P1)
    )
  )
)
;;;-------------------------------------------------------------------------------
(princ)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Reactor Circle and Text
« Reply #10 on: May 05, 2010, 09:09:08 PM »
Your code revised still problem at text, if you text edit height and posisition text not on place.
but your code is good for my idea and many thanks for your help.



Try this :

I changed the text justification but can't get it to stick when the text is revised.

Otherwise, the Text Height will update, and the circle or text can be erased without an error.

Code: [Select]
(defun c:rcat_2 (/ p1 rad vla-circle vla-text vgms)
  (vl-load-com)
  (setq
    vgms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  )
  (or (setq p1 (getpoint "\nClick any location for first circle <0,0,0>: "))
      (setq p1 '(0 0 0))
  )
  (or (setq rad (getdist p1 "\nEnter value radius for circle <5>: "))
      (setq rad 5)
  )
  (setq P1         (vlax-3d-point p1)
        vla-circle (vla-addcircle vgms P1 rad)
  )
  (vla-put-color vla-circle acred)
  ;;
  (setq vla-text (vla-addtext vgms (rtos rad) P1 (* rad 0.4)))
  (vla-put-color vla-text acblue)
  (vla-put-alignment vla-text acalignmentmiddlecenter)
  (vla-put-textalignmentpoint vla-text P1)
  ;;
  ;; save the reactor in case we want to disable it later
  ;;
  (setq *gv-reactor-circle->text (vlr-object-reactor
                                   (list vla-circle)
                                   vla-text
                                   '((:vlr-modified . reactor-circle->text))
                                 )
  )
  (setq *gv-reactor-text->circle (vlr-object-reactor
                                   (list vla-text)
                                   vla-circle
                                   '((:vlr-modified . reactor-text->circle))
                                 )
  )
  (princ)
)
;;;-------------------------------------------------------------------------------
(defun reactor-circle->text (notifier reactor arg-list)
  ;; (setq xx (vlr-data reactor))
  (update-text-for-circle (vlr-data reactor) notifier)
)
;;;-------------------------------------------------------------------------------
(defun reactor-text->circle (notifier reactor arg-list)
  (update-circle-for-text (vlr-data reactor) notifier)
)
;;;-------------------------------------------------------------------------------
(defun update-text-for-circle (vla-text vla-circle / width height text)
  (if (and (vlax-write-enabled-p vla-text)
           (vlax-read-enabled-p vla-circle)
           (setq rad (vla-get-radius vla-circle))
           (setq P1 (vla-get-center vla-circle))
      )
    (progn (vla-put-insertionpoint vla-text P1)
           (vla-put-height vla-text (* rad 0.4))
           (vla-put-textstring vla-text (rtos rad))
           (vla-put-alignment vla-text acalignmentmiddlecenter)
           (vla-put-textalignmentpoint vla-text P1)
    )
  )
)
;;;-------------------------------------------------------------------------------
(defun update-circle-for-text (vla-circle vla-text / rad center)
  (if (and (vlax-write-enabled-p vla-circle)
           (vlax-read-enabled-p vla-text)
           (setq rad (atof (vla-get-textstring vla-text)))
           (setq P1 (vla-get-insertionpoint vla-text))
      )
    (progn (if (and rad (> rad 0) (/= rad (vla-get-radius vla-circle)))
             (vla-put-Radius vla-circle rad)
           )
           (vla-put-center vla-circle P1)
    )
  )
)
;;;-------------------------------------------------------------------------------
(princ)


Adesu

  • Guest
Re: Reactor Circle and Text
« Reply #11 on: May 05, 2010, 09:59:15 PM »
Hi Kerry, I hope you don't bore to help me to understand about reactor, I'm still confuse at
Quote
(defun reactor-text->circle (notifier reactor arg-list)
  (update-circle-for-text (vlr-data reactor) notifier)
)
Is there a way to easy understand about "(vlr-data reactor)" and  "notifier"

This code is good and I understand
Quote
(defun update-text-for-circle (vla-text vla-circle / width height text)
  (if (and (vlax-write-enabled-p vla-text)
           (vlax-read-enabled-p vla-circle)
           (setq rad (vla-get-radius vla-circle))
           (setq P1 (vla-get-center vla-circle))
      )
    (progn (vla-put-insertionpoint vla-text P1)
           (vla-put-height vla-text (* rad 0.4))
           (vla-put-textstring vla-text (rtos rad))
           (vla-put-alignment vla-text acalignmentmiddlecenter)
           (vla-put-textalignmentpoint vla-text P1)
    )
  )
)
;;;-------------------------------------------------------------------------------
(defun update-circle-for-text (vla-circle vla-text / rad center)
  (if (and (vlax-write-enabled-p vla-circle)
           (vlax-read-enabled-p vla-text)
           (setq rad (atof (vla-get-textstring vla-text)))
           (setq P1 (vla-get-insertionpoint vla-text))
      )
    (progn (if (and rad (> rad 0) (/= rad (vla-get-radius vla-circle)))
             (vla-put-Radius vla-circle rad)
           )
           (vla-put-center vla-circle P1)
    )
  )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Reactor Circle and Text
« Reply #12 on: May 07, 2010, 11:11:44 PM »

Adesu,

For some good Reactor info refer Chapter 12 in David Stein's The Visual LISP Developers Bible.pdf
You should be able to find a copy easily on the Internet.

Simply put:
The 'notifier' is the object being modified .. the one that the reactor is attached to.

(vlr-data reactor)  returns the application specific data saved as the second parameter in the (vlr-object-reactor call
ie;
(vlr-object-reactor
        (list vla-text)      ;; <<== notifier the reactor is attached to
        vla-circle            ;; <<== THIS is the data returned by (vlr-data   .. could be a "ReactorName" string       
       '((:vlr-modified . reactor-text->circle))
)


note:
The code I posted is not production-code .. it requires error trapping, a facility to remove the reactors when the drawing is closed, better handling for when either circle or text is erased, testing to see if the reactor callback function exists before defining it etc etc etc ....



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Adesu

  • Guest
Re: Reactor Circle and Text
« Reply #13 on: May 08, 2010, 10:24:14 PM »
Hi Kerry,
Thanks you for your help, you much help to solve my problem  and you to make open my brain to know about reactor, then information from you very clear to understand.


Adesu,

For some good Reactor info refer Chapter 12 in David Stein's The Visual LISP Developers Bible.pdf
You should be able to find a copy easily on the Internet.

Simply put:
The 'notifier' is the object being modified .. the one that the reactor is attached to.

(vlr-data reactor)  returns the application specific data saved as the second parameter in the (vlr-object-reactor call
ie;
(vlr-object-reactor
        (list vla-text)      ;; <<== notifier the reactor is attached to
        vla-circle            ;; <<== THIS is the data returned by (vlr-data   .. could be a "ReactorName" string       
       '((:vlr-modified . reactor-text->circle))
)


note:
The code I posted is not production-code .. it requires error trapping, a facility to remove the reactors when the drawing is closed, better handling for when either circle or text is erased, testing to see if the reactor callback function exists before defining it etc etc etc ....