Lee Chu Chu Posted July 14, 2014 Posted July 14, 2014 So I want to be able to set things inside functions when the command is called up in the command line. I tried using a command reactor. It works fine when it is outside of the function that I wanted for it to be activated but when I put it inside the function, it doesnt seem to be getting the values of the variables before the command is called up. so I have a simple function used for texting. (defun c:trec() (reactoron) (command "rectang") ) This is not the actual function I want to use in autocad but using this as my test. So this is my reactor which lives in reactoron. (defun reactoron() (vl-load-com) (vlr-command-reactor nil '((:vlr-commandWillStart . startCommand))) (vlr-command-reactor nil '((:vlr-commandEnded . endCommand))) (vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand))) (defun startCommand (calling-reactor startcommandInfo / thecommandstart) (setq OldLayer (getvar "CLAYER")) (setq thecommandstart (nth 0 startcommandInfo)) (cond ((= thecommandstart "TREC") (setvar "CLAYER" "4")) ) (princ) ) (defun endCommand (calling-reactor endcommandInfo / thecommandend) (setq thecommandend (nth 0 endcommandInfo)) (cond ((= thecommandend "TREC") (setvar "CLAYER" OldLayer)) ) (vlr-remove-all) (princ) ) (defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel) (setq thecommandcancel (nth 0 cancelcommandInfo)) (cond ((= thecommandcancel "TREC") (setvar "CLAYER" OldLayer)) ) (vlr-remove-all) (princ) ) ) I should thank afralisp for the code sample which this code here is based from. So someone help me find a way to be able to activate this command reactor inside my function TREC? Quote
7o7 Posted July 14, 2014 Posted July 14, 2014 Command reactors are used only for CAD command, not user defined command. In this case the name of command is "rectang", not "trec". If you want to use reactor in your case, use a lisp reactor. And why do you want to put reactor inside your command? It may make a nest reactor. Quote
Tharwat Posted July 15, 2014 Posted July 15, 2014 Try this . (defun _rectang:started (reac data) (if (and (wcmatch (car data) "*RECTANG") (tblsearch "LAYER" "4")) (progn (setq *oldlayer* (getvar 'CLAYER)) (setvar 'CLAYER "4")) ) (princ) ) ;; ;; (defun _rectang:ended (reac data) (if (and (wcmatch (car data) "*RECTANG") (tblsearch "LAYER" *oldlayer*)) (setvar 'CLAYER *oldlayer*) ) (princ) ) ;; ;; (vlr-command-reactor "My Reactor" '((:VLR-commandWillStart . _rectang:started) (:VLR-commandEnded . _rectang:ended) (:VLR-commandCancelled . _rectang:ended) (:VLR-commandFailed . _rectang:ended) ) ) Quote
Lee Chu Chu Posted July 15, 2014 Author Posted July 15, 2014 @707, I have used a lisp reactor however when I have placed my lisp reactor into my huge lisp file, the reactor doesnt seem to want to cancel at all even though I keep pressing the esc button to cancel the command. The lisp reactor does start but never cancels nor does it end. Quote
Lee Chu Chu Posted July 15, 2014 Author Posted July 15, 2014 @Tharwat, I will have to try this out tomorrow morning and see if it works. But just so that I can understand what you have written, what does this part of the code mean/ do? (if (and (wcmatch (car data) "*RECTANG") (tblsearch "LAYER" "4")) Edit: Actually, now I am not sure if it will work in my case when I try to implement this code for my actual functions that I want to personalise. Is there any way to use these reactors for a user-defined function? If not, how would I use a lisp reactor as 707 suggested? Quote
Tharwat Posted July 15, 2014 Posted July 15, 2014 If you do not explain your idea clearly , you would keep on receiving guesses and not useful replies . Quote
Lee Chu Chu Posted July 15, 2014 Author Posted July 15, 2014 (edited) I'm sorry but I am trying my best to explain things. I am not good at explaining nor am I good at programming. But my question to you know is with the code you wrote above, will it work on user defined functions? Edited July 15, 2014 by Lee Chu Chu Quote
7o7 Posted July 16, 2014 Posted July 16, 2014 When you press esc, the first function to be triggered is *error* function, not reactor. So if you want to handle with it, you'd better redefine the *error* function instead of reactors. Quote
Lee Chu Chu Posted July 16, 2014 Author Posted July 16, 2014 How would I do this? I have no understanding of this *error* function thingo even after reading stuff from Lee-Macs website and the stuff from afralisp. Quote
MSasu Posted July 16, 2014 Posted July 16, 2014 Basically the *ERROR* is a function that is executed by AutoLISP interpreter each time an error occurs (a code logical error or when user press ). Even if the name is reserved, the programmer is allowed to define its content. So, you need to add there everything you want to be executed when an error occurs. Quote
Recommended Posts
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.