Jump to content

Reactors problem: layer doesn't set back


Recommended Posts

Posted

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)

Posted

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

Posted

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

attachment.php?attachmentid=59375&cid=1&stc=1

 

All layers are on

 

Thanks

reactors.gif

Posted

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)
 )

Posted

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 ! :beer:

 

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

Posted

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.

Posted

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

Posted

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)
)

Posted

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")
...

Posted
Thanks you! very clever solution!

 

I've lot to study from this code.. thanks! ;)

 

You are most welcome. :thumbsup:

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...