Jump to content

Properties Reactor


Grrr

Recommended Posts

Hi,

I was trying to create a properties reactor:

If there are selected objects then invoke the properties command,

if there aren't any objects selected then invoke the propertiesclose command.

Well it should work the same way as quickproperties appears upon selection.

 

I know how to do this with plain lisp:

(defun checkselection ()
 (if (ssget "_I")
 (command "_.properties")
 (command "_.propertiesclose")
 )
);defun

 

But I have no experience with reactors and I don't know what event-name to use, what should be the callback function.

Heres my raw start:

;*********************************************************************
(vlr-command-reactor 

"TurnPropertiesOnSelection" '((:vlr-XXXX . XXXXXX ))) ; what event-name to use and what should be the callback function?
;*********************************************************************
(vl-load-com)

(defun checkselection () ; data
 (if (ssget "_I")
 (...)
 )
);defun

(defun doProperties () ; callback
 (command "_.properties")
);defun

(defun undoProperties () ; callback
 (command "_.propertiesclose")
);defun

As I understand it should check if there is a selection to invoke properties

and if there is no selection to invoke propertiesclose.

But does that mean building two reactors?

Link to comment
Share on other sites

Here's a basic form of such a reactor - type 'autopropson' and 'autopropsoff' to enable & disable the reactor respectively:

([color=BLUE]setq[/color] autoprops:reactorid [color=MAROON]"autoprops:reactor"[/color])

([color=BLUE]defun[/color] c:autopropson [color=BLUE]nil[/color]
   (autoprops:remove autoprops:reactorid)
   ([color=BLUE]vlr-miscellaneous-reactor[/color] autoprops:reactorid '(([color=BLUE]:vlr-pickfirstmodified[/color] . autoprops:callback)))
   ([color=BLUE]princ[/color] [color=MAROON]"\nAutoProperties Reactor enabled."[/color])
   ([color=BLUE]princ[/color])
)
([color=BLUE]defun[/color] c:autopropsoff [color=BLUE]nil[/color]
   (autoprops:remove autoprops:reactorid)
   ([color=BLUE]princ[/color] [color=MAROON]"\nAutoProperties Reactor disabled."[/color])
   ([color=BLUE]princ[/color])
)
([color=BLUE]defun[/color] autoprops:remove ( key )
   ([color=BLUE]foreach[/color] rtr ([color=BLUE]cdar[/color] ([color=BLUE]vlr-reactors[/color] [color=BLUE]:vlr-miscellaneous-reactor[/color]))
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] key ([color=BLUE]vlr-data[/color] rtr)) ([color=BLUE]vlr-remove[/color] rtr))
   )
)
([color=BLUE]defun[/color] autoprops:callback ( rtr arg )
   ([color=BLUE]if[/color] ([color=BLUE]cadr[/color] ([color=BLUE]ssgetfirst[/color]))
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] 0 ([color=BLUE]getvar[/color] 'opmstate))
           (autoprops:sendcommand [color=MAROON]"_.properties "[/color])
       )
       ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'opmstate))
           (autoprops:sendcommand [color=MAROON]"_.propertiesclose "[/color])
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]defun[/color] autoprops:sendcommand ( com )
   ([color=BLUE]eval[/color]
       ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'autoprops:sendcommand '( com )
           ([color=BLUE]list[/color] '[color=BLUE]vla-sendcommand[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) 'com)
       )
   )
   (autoprops:sendcommand com)
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Note that you cannot invoke a command call from within a reactor callback function, therefore a post-process evaluation using the sendcommand method is required.

 

Be advised that Reactors are generally considered an advanced area of Visual LISP, and consequently the supporting code needs to be watertight, accounting for every possibly eventuality to ensure uninterrupted operation. I would therefore suggest that you study the various tutorials and resources available before writing your program, so that you have a good understanding of the 'rules' of Reactors.

Link to comment
Share on other sites

Hi Lee,

 

Note that you cannot invoke a command call from within a reactor callback function, therefore a post-process evaluation using the sendcommand method is required.

I remember someone asked that question, so the global answer for calling a command within a reactor is:

(autoprops:sendcommand "_.commandname ")

I'm happy to get that answer!

 

 

Be advised that Reactors are generally considered an advanced area of Visual LISP, and consequently the supporting code needs to be watertight, accounting for every possibly eventuality to ensure uninterrupted operation.

I see, reactors seem the hardest to learn as you mentioned "advanced area of Visual LISP", but in some cases they're the most comfortable method to use (as I've seen in many examples - your LayerDirector routine and some other hide/lock objects routines).

 

 

To be fair I checked the reactor tutorials from afralisp, but I couldn't find an example for performing this attempt, which brings me to my question:

Where did you find/read about these functions:

vlr-miscellaneous-reactor
:vlr-pickfirstmodified

Usually to look for some VL VLA functions I check in AutoCAD's ActiveX Reference, but I didn't found any "VLR" anywhere (only the few examples from afralisp).

 

 

I'm still thinking about this part your comment, as I'm used to get examples to modify and learn from with the bad habbit of always exiting every command with ESC key - as you said this won't do with reactors.

have a good understanding of the 'rules' of Reactors.
Link to comment
Share on other sites

The Reactor functions (vlr-*) are quite well documented in the standard developer documentation - if you search Google for any of the functions I have used in the above posted code, you should find references from the standard documentation which describe the purpose & format of each function, and also give examples.

Link to comment
Share on other sites

Usually to look for some VL VLA functions I check in AutoCAD's ActiveX Reference, but I didn't found any "VLR" anywhere (only the few examples from afralisp).

 

There are already existed in AutoLISP functions in their related start character [V]. HERE

Link to comment
Share on other sites

Thanks, Tharwat! :)

You are welcome. :)

 

Your thread encouraged me to search for a solution and the only thing that blocked me is that how to find out if there is already selected object(s) so I have searched the System variables for a horse to ride but I come up with empty handed until Lee amazed us as always with the answer and honestly I did not know about the ssgetfirst function before.

 

Nice work Lee.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...