Jump to content

Switch for layers


mdbdesign

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • Commandobill

    5

  • mdbdesign

    4

  • TimSpangler

    4

Top Posters In This Topic

Hmm well i could write a lisp to toggle between the two of them... is that what your looking for?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

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 :D

 

Oh, yes, sorry, got setq's the wrong way round - I knew what I meant :P

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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