MastroLube Posted September 30, 2016 Posted September 30, 2016 Hi there, I've this little lisp with some reactors of command events.. the problem is that, when you've finished the command, it doesn't go back to the old layer. Where is the error? Thanks, Dennis (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 "XLINE") (setvar "CLAYER" "_Assi")) ((= thecommandstart "DIMLINEAR") (setvar "CLAYER" "DIMS")) );cond (princ) );defun ;**************************************************** (defun endCommand (calling-reactor endcommandInfo / thecommandend) (setq thecommandend (nth 0 endcommandInfo)) (cond ((= thecommandend "XLINE") (setvar "CLAYER" OldLayer)) ((= thecommandstart "DIMLINEAR") (setvar "CLAYER" OldLayer)) );cond (princ) );defun ;******************************************************** (defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel) (setq thecommandcancel (nth 0 cancelcommandInfo)) (cond ((= thecommandcancel "XLINE") (setvar "CLAYER" OldLayer)) ((= thecommandstart "DIMLINEAR") (setvar "CLAYER" OldLayer)) );cond (princ) );defun ;********************************************************* (princ) Quote
halam Posted September 30, 2016 Posted September 30, 2016 Do you happen to look at LM:layerdirector for starters? I think I have this problem when the layer is turned off or frozen. Anyway, sounds familiar..(not behind destop right now) kind regards Quote
MastroLube Posted September 30, 2016 Author Posted September 30, 2016 I've checked the value of oldlayer and discovered that it changes to the new one! The problem seems that it enters in the cycle for 2 times! Have a look there: I've performed the XLine command All layers are on Thanks Quote
Tharwat Posted September 30, 2016 Posted September 30, 2016 Hi, Try this; (vl-load-com) ;; Tharwat - 30.09.2016 ;; (vlr-command-reactor "test" '((:vlr-commandWillStart . startCommand) (:vlr-commandEnded . endCommand) (:vlr-commandCancelled . endCommand) ) ) (defun startCommand (r c) (and (eq (vlr-data r) "test") (wcmatch (strcase (car c)) "XLINE,DIMLINEAR") (tblsearch "LAYER" "_Assi") (setq *currentlayer* (getvar "CLAYER")) (setvar "CLAYER" "_Assi") ) (princ) ) ;; ;; (defun endCommand (r c) (and (eq (vlr-data r) "test") *currentlayer* (tblsearch "LAYER" *currentlayer*) (setvar "CLAYER" *currentlayer*) (setq *currentlayer* nil) ) (princ) ) Quote
MastroLube Posted September 30, 2016 Author Posted September 30, 2016 Hi! thank for your reply! It doesn't change the layer.. I've loaded it and tried to make an Xline and a quote, but they are in the current layer.. anyway I've noticed that it goes in the cycle lots time as well.. I can't understand why.. the command should start only a time, the code should be run only one time.. Thanks for your help ! EDIT, ok it changed it.. I didn't create the layer _Assi.. as mine it doesn't turn back to the old layer.. Maybe it's because it runs several times Quote
Tharwat Posted September 30, 2016 Posted September 30, 2016 There must have been a conflict between your and my codes So just start with a new drawing or close and reopen current drawing or change the name of my functions (startCommand & endCommand) as well in the reactor command. Quote
MastroLube Posted September 30, 2016 Author Posted September 30, 2016 You're right Mr!!! Thank you very much! Can you give me a little advice to have more cases? (defun startCommand (r c) (and (eq (vlr-data r) "test") (cond ((wcmatch (strcase (car c)) "XLINE") (tblsearch "LAYER" "_Assi") (setq *currentlayer* (getvar "CLAYER")) (setvar "CLAYER" "_Assi") ) ((wcmatch (strcase (car c)) "DIMLINEAR") (tblsearch "LAYER" "DIMS") (setq *currentlayer* (getvar "CLAYER")) (setvar "CLAYER" "DIMS") ) ) ) (princ) ) This look very ugly and I think it doesn't work properly.. Thanks Quote
Tharwat Posted September 30, 2016 Posted September 30, 2016 Shot this; (defun startCommand (r c) (and (eq (vlr-data r) "test") (vl-some '(lambda (com lay) (and (eq (strcase (car c)) com) (tblsearch "LAYER" lay) (setq *currentlayer* (getvar "CLAYER")) (setvar "CLAYER" lay) ) ) '("XLINE" "DIMLINEAR") '("_Assi" "DIMS") ) ) (princ) ) Quote
MastroLube Posted September 30, 2016 Author Posted September 30, 2016 Thanks you! very clever solution! I've lot to study from this code.. thanks! PS. a little question.. is it possible with points to let the command stay active until I've finished? Now it changes the layer for each point :S ... '("XLINE" "DIMLINEAR" "DIM" "MTEXT" "POINT") '("_Assi" "DIMS" "DIMS" "_Testi" "_Appoggi centri") ... Quote
Tharwat Posted September 30, 2016 Posted September 30, 2016 Thanks you! very clever solution! I've lot to study from this code.. thanks! You are most welcome. 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.