mdbdesign Posted June 5, 2009 Posted June 5, 2009 Need macro or lisp that will keep only one of two layers on. If layer "APPROVED" is on layer "PRELIMINARY" is off and vice versa. Use AutoCAD 2002. Thank you. Quote
Commandobill Posted June 5, 2009 Posted June 5, 2009 Hmm well i could write a lisp to toggle between the two of them... is that what your looking for? Quote
mdbdesign Posted June 5, 2009 Author Posted June 5, 2009 Yes sir! That exactly is. If one is on other is off Quote
Lee Mac Posted June 5, 2009 Posted June 5, 2009 Something like this? (not pretty) (defun c:laysw (/ lay1 lay2) (vl-load-com) (and (setq lay1 (tblobjname "LAYER" "APPROVED") lay1 (vlax-ename->vla-object lay1)) (setq lay2 (tblobjname "LAYER" "PRELIMINARY") lay2 (vlax-ename->vla-object lay2)) (cond ((eq :vlax-true (vla-get-layeron lay1)) (vla-put-layeron lay1 :vlax-false) (vla-put-layeron lay2 :vlax-true)) (t (vla-put-layeron lay2 :vlax-false) (vla-put-layeron lay1 :vlax-true)))) (princ)) Quote
Lee Mac Posted June 5, 2009 Posted June 5, 2009 Thanks Lee, beer on me.Perfect. Make it a Kronenbourg (1664 - not blanc) Quote
Commandobill Posted June 5, 2009 Posted June 5, 2009 Trust me Lee what you have is much better than what i was coming up with but you said it wasnt pretty so i cleaned it up a little. (defun c:laysw (/ lay1 lay2) (vl-load-com) (setq lay1 (vlax-ename->vla-object (tblobjname "LAYER" "APPROVED")) lay2 (vlax-ename->vla-object (tblobjname "LAYER" "PRELIMINARY"))) (if (eq :vlax-true (vla-get-layeron lay1)) (progn (vla-put-layeron lay1 :vlax-false) (vla-put-layeron lay2 :vlax-true)) (progn (vla-put-layeron lay2 :vlax-false) (vla-put-layeron lay1 :vlax-true))) (princ)) Quote
Commandobill Posted June 5, 2009 Posted June 5, 2009 Lee is there a site explaining what tables there are? i.e. "Blocks" "Layers" etc? Quote
Lee Mac Posted June 5, 2009 Posted June 5, 2009 Trust me Lee what you have is much better than what i was coming up with but you said it wasnt pretty so i cleaned it up a little. (defun c:laysw (/ lay1 lay2) (vl-load-com) (setq lay1 (vlax-ename->vla-object (tblobjname "LAYER" "APPROVED")) lay2 (vlax-ename->vla-object (tblobjname "LAYER" "PRELIMINARY"))) (if (eq :vlax-true (vla-get-layeron lay1)) (progn (vla-put-layeron lay1 :vlax-false) (vla-put-layeron lay2 :vlax-true)) (progn (vla-put-layeron lay2 :vlax-false) (vla-put-layeron lay1 :vlax-true))) (princ)) I prefer mine, as vlax-ename->vla-object will return an error if provided with nil (hence if the layer is not found), wherease mine will stop at the first nil return in the AND statement. As for what Tables there are, look at the help in the VLIDE on tblnext Quote
Commandobill Posted June 5, 2009 Posted June 5, 2009 Except your code error'd out when i ran it with no layer in it. Hmm. perhaps if it was more like this. (defun c:laysw (/ lay1 lay2) (vl-load-com) (and (setq lay1 (tblobjname "LAYER" "APPROVED") lay2 (tblobjname "LAYER" "PRELIMINARY")) (setq lay1 (vlax-ename->vla-object lay1) lay2 (vlax-ename->vla-object lay2)) (if (eq :vlax-true (vla-get-layeron lay1)) (progn (vla-put-layeron lay1 :vlax-false) (vla-put-layeron lay2 :vlax-true)) (progn (vla-put-layeron lay2 :vlax-false) (vla-put-layeron lay1 :vlax-true)))) (princ)) Thank you for the direction i will have to look into that. Always a pleasure learning from you Quote
Lee Mac Posted June 5, 2009 Posted June 5, 2009 Except your code error'd out when i ran it with no layer in it. Hmm. perhaps if it was more like this. (defun c:laysw (/ lay1 lay2) (vl-load-com) (and (setq lay1 (tblobjname "LAYER" "APPROVED") lay2 (tblobjname "LAYER" "PRELIMINARY")) (setq lay1 (vlax-ename->vla-object lay1) lay2 (vlax-ename->vla-object lay2)) (if (eq :vlax-true (vla-get-layeron lay1)) (progn (vla-put-layeron lay1 :vlax-false) (vla-put-layeron lay2 :vlax-true)) (progn (vla-put-layeron lay2 :vlax-false) (vla-put-layeron lay1 :vlax-true)))) (princ)) Thank you for the direction i will have to look into that. Always a pleasure learning from you Oh, yes, sorry, got setq's the wrong way round - I knew what I meant Quote
TimSpangler Posted June 5, 2009 Posted June 5, 2009 This maybe better suited for a reactor. What if someone uses the Layer drop down to turn on a layer, Then they will both be on. With a reactor you can check for the layer status after every command or after a certain command, etc.... just sayin, thats all.... Quote
Lee Mac Posted June 5, 2009 Posted June 5, 2009 This maybe better suited for a reactor. What if someone uses the Layer drop down to turn on a layer, Then they will both be on. With a reactor you can check for the layer status after every command or after a certain command, etc.... just sayin, thats all.... Good point, but with them both on - the code will just default to switching one off. Quote
TimSpangler Posted June 5, 2009 Posted June 5, 2009 Need macro or lisp that will keep only one of two layers on. If layer "APPROVED" is on layer "PRELIMINARY" is off and vice versa. True but you could still have both on/off. Quote
Lee Mac Posted June 5, 2009 Posted June 5, 2009 Tim, I tried creating this, but I can't seem to get it too function... (defun c:MacON () (vl-load-com) (if (not lay:react) (progn (setq lay:react (vlr-command-reactor nil (list (cons :vlr-commandWillStart 'ChkLay)))) (princ "\n<< LAYER REACTOR INITIATED >>"))) (princ)) (defun ChkLay (/ lay1 lay2) (and (setq lay1 (tblobjname "LAYER" "APPROVED") lay2 (tblobjname "LAYER" "PRELIMINARY")) (setq lay1 (vlax-ename->vla-object lay1) lay2 (vlax-ename->vla-object lay2)) (cond ((vl-every (function (lambda (x) (eq :vlax-true (vla-get-layeron x)))) (list lay1 lay2)) (vla-put-layeron lay2 :vlax-false)) ((vl-every (function (lambda (x) (eq :vlax-false (vla-get-layeron x)))) (list lay1 lay2)) (vla-put-layeron lay1 :vlax-true)))) (princ)) (defun c:MacOFF () (if lay:react (progn (vlr-remove lay:react) (setq lay:react nil) (princ "\n<< LAYER REACTOR DEACTIVATED >>"))) (princ)) Quote
mdbdesign Posted June 5, 2009 Author Posted June 5, 2009 Make it a Kronenbourg (1664 - not blanc) Hope, can find it in Canada Quote
alanjt Posted June 5, 2009 Posted June 5, 2009 i know i'm behind, since we switched to a reactor, but i thought i'd indulge. (defun c:laysw (/ lay1 lay2) (vl-load-com) (and (setq lay1 (tblobjname "LAYER" "APPROVED") lay2 (tblobjname "LAYER" "PRELIMINARY") ) ;_ setq (setq lay1 (vlax-ename->vla-object lay1) lay2 (vlax-ename->vla-object lay2) ) ;_ setq (mapcar '(lambda (x y) (vla-put-layeron x y) ) ;_ lambda (if (eq :vlax-true (vla-get-layeron lay1)) (list lay1 lay2) (list lay2 lay1) ) ;_ if '(:vlax-false :vlax-true) ) ;_ mapcar ) ;_ and (princ) ) ;_ defun Quote
TimSpangler Posted June 5, 2009 Posted June 5, 2009 This seems to work. Command: LSW to switch layers if both layers are on or off the when any command is called it will turn on the approved layer. ;;; Construct the Command Reactors ; (defun TGS:LayerSwitchReactor (/) (or LayerSwitchReactorBE (setq LayerSwitchReactorBE (VLR-Command-Reactor "Layer Switch Command Reactor" '((:vlr-commandWillStart . TGS:LS_Begin)))) ) (or LayerSwitchReactorEn (setq LayerSwitchReactorEn (VLR-Command-Reactor "Layer Switch Command Reactor" '((:vlr-commandEnded . TGS:LS_Begin)))) ) (or LayerSwitchReactorCa (setq LayerSwitchReactorCa (VLR-Command-Reactor "Layer Switch Command Reactor" '((:vlr-commandCancelled . TGS:LS_Begin)))) ) (or LayerSwitchReactorFa (setq LayerSwitchReactorFa (VLR-Command-Reactor "Layer Switch Command Reactor" '((:vlr-commandFailed . TGS:LS_Begin)))) ) ) ;; COMMAND CALLBACK FUNCTIONS ;; ;; Begin event (defun TGS:LS_Begin (Robject Plist / StatusApproved StatusPrelim LayerApproved LayerPrelim) ;; Get the current properties of each layer (setq StatusApproved (vla-get-layeron (setq LayerApproved (vlax-ename->vla-object (tblobjname "LAYER" "APPROVED"))))) (setq StatusPrelim (vla-get-layeron (setq LayerPrelim (vlax-ename->vla-object (tblobjname "LAYER" "PRELIMINARY"))))) ;; Check the status of each layer (if (= StatusApproved StatusPrelim) (progn (vla-put-layeron LayerApproved ':vlax-true) (vla-put-layeron LayerPrelim ':vlax-false)(setq StatusApproved ':vlax-true) (setq StatusPrelim ':vlax-false) ) ) ;; Quiet Exit (princ) ) ;; MAIN LAYER SWITCH COMMAND ;; (defun c:LSW (/ StatusApproved StatusPrelim) ;; Get the current properties of each layer (setq StatusApproved (vla-get-layeron (setq LayerApproved (vlax-ename->vla-object (tblobjname "LAYER" "APPROVED"))))) (setq StatusPrelim (vla-get-layeron (setq LayerPrelim (vlax-ename->vla-object (tblobjname "LAYER" "PRELIMINARY"))))) ;; Check the status of each layer (if (= StatusApproved ':vlax-true) (progn (vla-put-layeron LayerApproved ':vlax-false) (vla-put-layeron LayerPrelim ':vlax-true) ) (progn (vla-put-layeron LayerApproved ':vlax-true) (vla-put-layeron LayerPrelim ':vlax-false) ) ) ) ;; Autoload the Layer Switch Reactors (TGS:LayerSwitchReactor) ;; Quiet Load (princ "\n -Layer Switch Reactor Loaded \n") (princ) I have very limited knowledge with reactor so take it for what it is worth Quote
TimSpangler Posted June 5, 2009 Posted June 5, 2009 Notice: the above does not take into account for the existence of the layers.. 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.