Lisp to turn on and off - Working drawing layers and black line

Lisp to turn on and off - Working drawing layers and black line

Anonymous
Not applicable
2,602 Views
5 Replies
Message 1 of 6

Lisp to turn on and off - Working drawing layers and black line

Anonymous
Not applicable

hello all,

I am new to lisp think. i want to create  lisp and use to turn on and turn off Construction drawing layers  verse to black line layers.

brouchure layer /black line layer starts with "B" and Working drawing layer starts with "W"

 

i want to show only working drawing layer when i type "WD" and Brouchure layer to show up when type "BD".

please help.

 

 

0 Likes
Accepted solutions (3)
2,603 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

hi,

 

there is no need in lisp for that, study layer properties filter (in layer property manager)

 

moshe

 

Message 3 of 6

Shneuph
Collaborator
Collaborator
Accepted solution

Here is a function that just toggles layers using the layer command.  When you pass it a layer name filter as a text string it uses it in the layer command to turn on or off that set of layers.  The commands below (defined with a C:  e.g. C:WD) pass the filter string and prefix string to save the status to the toggle function.

 

(Defun Layer_Toggle (layerFilter stname)
  (setq stname (strcat stname "_STATUS"))
  (if (not (eval (read stname)))
    (set (read stname) "OFF")
    (progn
      (if (= (eval (read stname)) "OFF")
	(progn
	  (command "layer" "on" layerfilter "")
	  (set (read stname) "ON")
	  );progn
	(progn
	  (command "layer" "off" layerfilter "")
	  (set (read stname) "OFF")
	  );progn
	);if
      );progn
    );if
  );defun

(Defun C:BD ()
  (layer_toggle "B*" "BD")
  (princ)
  );defun
(Defun C:WD ()
  (layer_toggle "W*" "WD")
  (princ)
  );defun

Hope this helps.

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 6

john.uhden
Mentor
Mentor

Are you sure you want to just turn layers on and off, rather than freezing and thawing?

There can be a great difference when dealing with blocks that have attributes.

For example if you have a block inserted on layer BLACK but it has attributes on layers RED, YELLOW, and GREEN then turning layer BLACK off will undisplay any linework or text it contains, but the attributes will still show if they are on different layers.  Whereas if you freeze layer BLACK, then the attributes will be undisplayed as well

John F. Uhden

Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@john.uhden wrote:

.... if you have a block inserted on layer BLACK but it has attributes on layers RED, YELLOW, and GREEN then turning layer BLACK off will undisplay any linework or text it contains, but the attributes will still show if they are on different layers.  ….


 

Not only linework or text, but anything  on either Layer BLACK or Layer 0, will be "undisplayed" by turning off the BLACK Layer in that situation.  Likewise anything  [not just Attributes] in the Block definition that is drawn on other Layers will remain visible.

Kent Cooper, AIA
Message 6 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

brouchure layer /black line layer starts with "B" and Working drawing layer starts with "W" 

i want to show only working drawing layer when i type "WD" and Brouchure layer to show up when type "BD".  ….



Try something like these, using the wildcard * to get all Layers starting with the letter that precedes it, in both the On and Off options:

 

(defun C:WD ()

  (command "_.layer"

    "_thaw" "0" "_set" "0" ;;; assuming that can be on in any case

    "_on" "W*" "_off" "B*" ""

  )

  (princ)

)

 

(defun C:BD ()

  (command "_.layer"

    "_thaw" "0" "_set" "0" ;;; assuming that can be on in any case

    "_on" "B*" "_off" "W*" ""

  )

  (princ)

)

 

If you want to have one of the W... Layers set current in the WD command, rather than Layer 0, there would need to be either:

1) a way of giving it a Layer name starting with W that you know will always be in the drawing, or;

2) more complex code, to find  such a Layer name [certainly possible].

And likewise with a B... Layer in the BD command.

 

They thaw Layer 0 before setting it current, in case it may be frozen at the time [in which case it would not be able to be made current].  They don't deal with whatever you may want to do, if anything, with any additional Layers that may exist starting with other characters.

Kent Cooper, AIA