Author Topic: disabling object reactor  (Read 3124 times)

0 Members and 1 Guest are viewing this topic.

Red Nova

  • Newt
  • Posts: 69
disabling object reactor
« on: May 03, 2017, 11:23:00 AM »
So I managed to create an object reactor that is changing the width of the frame of a dynamic block based n the size of the attribute inside it.
Now I am trying to disable it when necessary for some blocks.
Somehow I cannot make it work for me.

I am trying to use vlr-owner-remove, but fail to understand how I should define reactor's name within vlr-owner-remove function.
My first try was:

Quote
(vlr-owner-remove '#<VLR-Object-Reactor> ownerobj)
Error: bad argument type: Object reactor: #<VLR-OBJECT-REACTOR>

Here is the example from help:
Quote
(vlr-owner-remove circleReactor archie)
#<VLA-OBJECT IAcadArc 03ad0bcc>

But how that "circleReactor" variable had to be defined previously? Within the same function, or maybe in the initial function that was creating this reactor?

I am creating a reactor called TagFieldReactor in a separate command.
If I try to make TagFieldReactor a global variable, and use same variable name in future, I have following error.

Quote
(setq TagFieldReactor (vlr-object-reactor (reverse (cons vlaobj vlaattobj))
"TagFieldReactor" '((:vlr-modified . UpdateTagField))))

Quote
(vlr-owner-remove TagFieldReactor ownerobj)
Error: bad argument type: Object reactor: nil

I know I do something stupid somewhere, could you please point out what exactly ?  :-)


Grrr1337

  • Swamp Rat
  • Posts: 812
Re: disabling object reactor
« Reply #1 on: May 03, 2017, 01:43:43 PM »
Read carefully:
https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-EE5ABE92-4589-482A-95B3-EC52497C3C5F-htm.html
"Removes an object from the list of owners of an object reactor"

to disable a reactor you have to actually delete it, like so:
Code: [Select]
(foreach rtr (cdar (vlr-reactors :vlr-object-reactor)) (if (= "myreactorname" (vlr-data rtr)) (vlr-remove rtr)) )
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: disabling object reactor
« Reply #2 on: May 03, 2017, 02:56:36 PM »
to disable a reactor you have to actually delete it, like so:
Code: [Select]
(foreach rtr (cdar (vlr-reactors :vlr-object-reactor)) (if (= "myreactorname" (vlr-data rtr)) (vlr-remove rtr)) )

Try to use vl-some instead of foreach function in that case.

Red Nova

  • Newt
  • Posts: 69
Re: disabling object reactor
« Reply #3 on: May 03, 2017, 03:09:16 PM »
Grrr1337 - OK, this way I was able to remove all reactors with same name in the file.
How can I remove reactors that are only attached to certain objects?




Grrr1337

  • Swamp Rat
  • Posts: 812
Re: disabling object reactor
« Reply #4 on: May 03, 2017, 03:59:02 PM »
Grrr1337 - OK, this way I was able to remove all reactors with same name in the file.
How can I remove reactors that are only attached to certain objects?

Code - Auto/Visual Lisp: [Select]
  1. (defun RemoveReactorAttacheToCertainObjects ( GivenRtr ListOfCertainObjects )
  2.   (if (vl-some (function (lambda (x) (vl-position x ListOfCertainObjects))) (vlr-owners GivenRtr))
  3.     (vlr-remove GivenRtr)
  4.   )
  5. )
  6.  
  7. (defun ListOfCertainObjects ( / SS i L )
  8.   (if (and (princ "\nSelect objects to remove their owner reactors:") (setq SS (ssget)) )
  9.     (repeat (setq i (sslength SS)) (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L)) )
  10.   )
  11. )
  12.  

Then:
Code: [Select]
(if (setq L (ListOfCertainObjects))
  (mapcar (function (lambda (x) (RemoveReactorAttacheToCertainObjects x L))) (cdar (vlr-reactors :VLR-Object-Reactor)))
)

I guess.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: disabling object reactor
« Reply #5 on: May 03, 2017, 05:29:37 PM »
to disable a reactor you have to actually delete it, like so:
Code: [Select]
(foreach rtr (cdar (vlr-reactors :vlr-object-reactor)) (if (= "myreactorname" (vlr-data rtr)) (vlr-remove rtr)) )

Try to use vl-some instead of foreach function in that case.

What if there is more than one instance of the reactor?

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: disabling object reactor
« Reply #6 on: May 03, 2017, 05:57:07 PM »
What about something in between vl-some and foreach :
Code - Auto/Visual Lisp: [Select]
  1. ; (_RemoveRtr "myreactorname" :vlr-object-reactor)
  2. (defun _RemoveRtr ( rtrnm rtrtyp / rtrs rtr )
  3.   (if (setq rtrs (cdar (vlr-reactors rtrtyp)))
  4.     (while (setq rtr (vl-some (function (lambda (x) (if (= rtrnm (vlr-data x)) x))) rtrs))
  5.       (vlr-remove rtr)
  6.       (setq rtrs (cdar (vlr-reactors rtrtyp)))
  7.     )
  8.   )
  9. )
:-)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Red Nova

  • Newt
  • Posts: 69
Re: disabling object reactor
« Reply #7 on: May 04, 2017, 09:49:45 AM »
Thank you Grrr1337. All I can say right now is that your code from  Reply #4 works for me. There are though some vl- / vlr- functions that I will need to digest yet to understand the entire logic.  :-)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: disabling object reactor
« Reply #8 on: May 04, 2017, 11:45:30 AM »
Thank you Grrr1337. All I can say right now is that your code from  Reply #4 works for me. There are though some vl- / vlr- functions that I will need to digest yet to understand the entire logic.  :-)

No problem, I'm glad it works.
 To understand better how to structure a reactor with On/Off/Callback defuns, refer to Lee Mac's properties reactor - due my request here.
And perhaps read all of the comments - if you really want to understand whats happening in the reactor's code (without memorising it).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg