Toggle between two layers

Toggle between two layers

Anonymous
Not applicable
1,340 Views
3 Replies
Message 1 of 4

Toggle between two layers

Anonymous
Not applicable

Hello all, I was wondering if there was a way to create a custom button that will toggle between two layers

(preferably freeze and thaw)? I know this can be done with macros but that would require 2 to 4 different buttons to turn each layer on and off. I would love if someone had some insight on my problem or could point me in the right direction.

0 Likes
1,341 Views
3 Replies
Replies (3)
Message 2 of 4

cadffm
Consultant
Consultant

For a macro solution, what cannot working smart a program in Lisp or another API way.

 

You can use DIESEL functions IF 

I will describe one way, you can figure out the right syntax for it 😉

 

IF,

variableX is set to 1,

Freeze Layer1 and thaw&on Layer2 + set VariableX to 0,

otherwise Freeze Layer2 and thaw&on Layer1 + set VariableX to 1

 

that's it.

 

 

as VaruableX you can use USERR1-5 USERI1-5 or USERS1-5 for example.

 

You need DIESEL  functions

IF and GETVAR 

and commands 

-LAYER and USERI1 for example.

 

Sebastian

0 Likes
Message 3 of 4

ChicagoLooper
Mentor
Mentor

You can certainly do it with a script but I prefer the Tool Palette.

 

Enter CUI on command line then click-and-drag a command from the Command List to a blank area of your tool palette. To keep organized, you can create your own 'Tool Palette Group' (I named my group MyCustom) and you can have multiple TABS in your TP Group (I have a separate Tabs named LAYERS, CREATE, ANNO).

 

Since there's no specific command to turn OFF an existing named layer, you can drag an arbitrary command from the CUI and drop it directly onto a blank area of your Tool Palette (I choose the command 'Layer,Layer Off' from the CUI (use the Search function in the CUI) and dropped it directly onto my Layers Tab because I liked this command's icon--your choice of icon may vary). Next, I copied the new command and pasted a duplicate on the same tab directly below the first one. 

 

Once the two commands were placed on the TP 'Layers' Tab, you can right-click the new icon, choose Properties and make edits to the Name, Description etc, etc. The most important edit though, is replacing the existing macro with your customized macro so you can achieve your specific task. Here's a view of the two commands on the Tool Palette and the customization that make them work.

^C^C^C-LAYER;ON;BLDG;;

^C^C^C-LAYER;OFF;BLDG;;

 

 

101.jpg

 

  

Notes:

  1. To see how the command works, enter -LAYER (you must enter the 'dash' before the L) on command line and follow the prompts.
  2. You need separate commands to turn a specific layer on and off.
  3. If you need the same on/off action on another layer, e.g. ROAD layer, copy-and-paste the command then edit the command's name, description and macro in properties so it reflects the ROAD layer instead of BLDG layer. 
  4. From the CUI you may drag-and-drop the polyline command and keep all Default values in Properties except for LAYER: change it from --use current to BLDG. When you execute this new polyline command you'll be drawing on the BLDG layer no matter what the current layer happens to be. (Make sure the BLDG layer is thawed or the pline won't be visible until BLDG is thawed.)
  5. The Tool Palette will 'travel' from drawing-to-drawing so if you work on mulitple at the same time the commands will be available as long as you don't close the palette. If you do  close it simply reopen it, the commands don't go away.

Chicagolooper

EESignature

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... to create a custom button that will toggle between two layers (preferably freeze and thaw)? ....


Try this [minimally tested]:

 

(defun C:LST (); = Layer Swap Toggle
  (command "_.layer" "_new" "LayerA,LayerB" "")
    ; to ensure both Layer names exist [won't care if they do already]
  (if (= (logand (cdr (assoc 70 (tblsearch "layer" "LayerA"))) 1) 1); LayerA frozen?
    (command "_.layer" "_thaw" "LayerA" "_set" LayerA" "_freeze" "LayerB" ""); then
    (command "_.layer" "_thaw" "LayerB" "_set" LayerB" "_freeze" "LayerA" ""); else
  ); if
  (command "_.regen")
  (princ)
); defun

 

Substitute your desired Layer names for "LayerA" and "LayerB".  It sets the one it Thaws to be the current Layer, in case the one it's about to Freeze is current at the time, because you can't Freeze the current Layer.  But it could be made to check whether or not the one it's about to Freeze is current, and only if so, set a different one current [whether the one it just Thawed, or some other, such as Layer 0].  The Set option will turn the Layer On if it happens to be Off as well as Frozen [an advantage of using a Layer command rather than (setvar 'clayer)].

 

You can put that command name into a Tool Palette button, but one advantage of doing it with an AutoLisp command definition is that you have the option to type in the command name even if it's also in a button.

Kent Cooper, AIA
0 Likes