geo Posted May 22, 2008 Share Posted May 22, 2008 I would like to be able to toggle all layers off, except the current one, using a single key stroke. For example, if i were to hit 'F2' then all layers would turn off except the current one; then when i hit 'F2' again it would be nice if they all came back on again (without affecting the layers already frozen). Any ideas? Quote Link to comment Share on other sites More sharing options...
Guest Alan Cullen Posted May 22, 2008 Share Posted May 22, 2008 I've written a pretty simple routine, that will turn off layers that a selected entity is on, will turn off all layers except the current layer, and will turn on all layers, except frozen layers. If you want it, add it to your startup suite, or add the load command to your acaddoc.lsp file..... (load "C:/yourfolder/layoff.LSP") ;;LAYOFF.LSP TURN LAYERS OFF BY SELECTING AN ENTITY ON THAT LAYER ;;=========================================================================== ;; ;;WRITTEN BY: ALAN CULLEN DATE: UNKNOWN ;; ;;START COMMANDS: LO.....TURN OFF LAYER A SELECTED ENTITY IS ON ;; LOFF...TURN OFF ALL LAYERS EXCEPT THE CURRENT LAYER ;; LON....TURN ON ALL LAYERS EXCEPT FROZEN LAYERS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:LO () (setq loop T) (while loop (setq sset nil) (prompt "\n Pick object whose layer you wish to turn off...") (setq sset (ssget)) (if (= sset nil) (setq loop nil)) (if (/= loop nil) (progn (setq name (ssname sset 0)) (setq data (entget name)) (setq code8 (cdr (assoc 8 data))) (command "-LAYER" "OFF" code8 "") ))) (princ) ) (defun C:LON () (prompt "\n Turning all layers on...") (command "-LAYER" "ON" "*" "") (prompt " DONE") (princ) ) (defun C:LOFF () (prompt "\n Turning all layers off...") (command "-LAYER" "OFF" "*" "" "") (prompt " DONE") (princ) ) Quote Link to comment Share on other sites More sharing options...
geo Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks Alan, much appreciated. I have assigned shortcuts to execute the LOFF and LON commands using the F2 and F3 keys. Works great! If anyone else has ideas on how to acheive the same outcome but using only the F2 button as a toggle i'm still interested. Quote Link to comment Share on other sites More sharing options...
Guest Alan Cullen Posted May 22, 2008 Share Posted May 22, 2008 Glad it worked for you. Cheers Quote Link to comment Share on other sites More sharing options...
russell84 Posted May 22, 2008 Share Posted May 22, 2008 acad commands layoff layon layiso laythw Quote Link to comment Share on other sites More sharing options...
geo Posted May 22, 2008 Author Share Posted May 22, 2008 ......... Quote Link to comment Share on other sites More sharing options...
CAB Posted May 22, 2008 Share Posted May 22, 2008 acad commands layoff layon layiso laythw These are Express Tools commands. Quote Link to comment Share on other sites More sharing options...
CAB Posted May 22, 2008 Share Posted May 22, 2008 Here is a toggle version. ;; Toggle layers On/Off ;; CAB 05/22/08 (defun C:F2 (/ usrcmd) (or *LayerOnOff* (setq *LayerOnOff* 1)) ; 0=Off 0=On current state (setq usrcmd (getvar "CMDECHO")) (command ".undo" "begin") (setvar "CMDECHO" 0) (cond ((zerop *LayerOnOff*) (prompt "\n Turning all layers on...") (command "-LAYER" "ON" "*" "") (command) (setq *LayerOnOff* 1) ) (t (prompt "\n Turning all layers off...") (command "-LAYER" "OFF" "*" "") (command) (command "-LAYER" "ON" (getvar "clayer") "") (command) (setq *LayerOnOff* 0) ) ) (setvar "CMDECHO" usrcmd) (command ".undo" "end") (princ) ) Quote Link to comment Share on other sites More sharing options...
geo Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks CAB, but i got the following error in autocad. " Command: f2 Turning all layers off... Invalid option keyword. ; error: Function cancelled Enter an option [?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock /stAte]: " Unfortunately, i'm not real savvy with these codes so i may be missing something obvious. Is there anything i needed to modify in the code myself or should it have worked 'as is'? I have simply typed 'f2' at the command prompt, which is fine for the moment, but once its working i'll assign the shortcut to the F2 button separately. thanks, Quote Link to comment Share on other sites More sharing options...
CAB Posted May 22, 2008 Share Posted May 22, 2008 I revised the code. Give it another try. Quote Link to comment Share on other sites More sharing options...
geo Posted May 23, 2008 Author Share Posted May 23, 2008 Sweet as a nut! much appreciated CAB. Quote Link to comment Share on other sites More sharing options...
russell84 Posted May 23, 2008 Share Posted May 23, 2008 Sorry CAB i didnt realise that the commands were an addon I guess this would be a pain without them - i use them every single day Quote Link to comment Share on other sites More sharing options...
russell84 Posted May 23, 2008 Share Posted May 23, 2008 Well in that case i wrote a couple more for you.. Because i know that a lot of people set up layers with prefix (defun C:preon () (Setq prefix (getstring "\nType prefix of layer(s) to turn ON: " )) (setq pre (princ (strcat "\n" prefix"*"))) (command "-layer" "ON" pre "") (princ) );end of PREON (defun C:preiso () (Setq prefix (getstring "\nType prefix of layer(s) to ISOLATE: " )) (setq pre (princ (strcat "\n" prefix"*"))) (command "-layer" "OFF" "*" "YES" "ON" pre "") (princ) );end of PREISO Quote Link to comment Share on other sites More sharing options...
CAB Posted May 23, 2008 Share Posted May 23, 2008 Sorry CAB i didnt realise that the commands were an addon I guess this would be a pain without them - i use them every single day Some of the Express Tools commands have been included as standard ACAD commands in later versions of ACAD. I just don't know which ones. Quote Link to comment Share on other sites More sharing options...
alanjt Posted May 26, 2008 Share Posted May 26, 2008 Well in that case i wrote a couple more for you..Because i know that a lot of people set up layers with prefix (defun C:preon () (Setq prefix (getstring "\nType prefix of layer(s) to turn ON: " )) (setq pre (princ (strcat "\n" prefix"*"))) (command "-layer" "ON" pre "") (princ) );end of PREON (defun C:preiso () (Setq prefix (getstring "\nType prefix of layer(s) to ISOLATE: " )) (setq pre (princ (strcat "\n" prefix"*"))) (command "-layer" "OFF" "*" "YES" "ON" pre "") (princ) );end of PREISO . you should add a (setvar "expert" 0) for your preiso to avoid that issue. i had the same issue with my layer isolate command that will isolate by typing in a portion or all of the layer name. also, you should add an (if pre so it doesn't turn everything off if you accidentally hit enter too soon. actually, here it is (sorry it's a little sloppy, this was one of my first routines and i haven't gone back to clean it up since it works): ;isolate layers by typing in names [wild cards allowed & use a comma "," to seperate names (ie: *name1*,name2)] ;alan thompson (7.3.07) (defun c:lai(/ lays) (IF (/= GETVAR "EXPERT" 0) (SETVAR "EXPERT" 0)) (setq lays (getstring "\nLayer(s) to isolate: ")) (IF lays (IF (/= lays "") (progn (COMMAND ".LAYER" "off" "*" "y" "ON" lays "") (princ "\nThe specified layer(s) have been isolated.") ) (IF (= lays "") (princ "\nNothing has been isolated!") ) ) ) (PRINC) ) for a toggle, this is one that Walt Bedinger wrote (very useful): ;;; LYRTGL.LSP, Version 2.20 11/03/00 ;;; by Walt Bedinger ;;; 11/11/95 ;;; This routine acts as a toggle. ;;; The first time it is called, it turns off all except the selected layers ;;; (the current layer is always left on.) ;;; The second time, it turns on all layers which were on originally or ;;; have been turned on since. ; Subroutines (DEFUN LYRTGL_RESTORE (Msg) (SETVAR "cmdecho" Xecho) (SETVAR "expert" Xexpert) (SETQ *error* Xerror) (command ".undo" "end") ) ; Main Routine (DEFUN c:LYRTGL ( / Xecho Xerror Xexpert Sset Lyr Lyr_Lst1 Lyr_Name N Index Group_Codes ) (COMMAND ".undo" "begin") (GRAPHSCR) (SETQ Xecho (GETVAR "cmdecho") Xerror *error* Xexpert (GETVAR "expert") *error* LYRTGL_RESTORE ) (SETVAR "expert" 1) (SETVAR "cmdecho" 0) (IF (NOT #Lyr_Lst2) ; If no list of layers which have been turned off is found, ; determine which layers are already off, select layers to leave on, ; and turn off all others. (PROGN (PROMPT "\nSelect entities on layers you want to remain on \(return for the current layer only.\)") (SETQ Sset (SSGET) Lyr (TBLNEXT "layer" T) Lyr_Lst1 (GETVAR "clayer") #Lyr_Lst2 "" ) (WHILE Lyr (IF (< (CDR (ASSOC 62 Lyr)) 0) (SETQ Lyr_Name (CDR (ASSOC 2 Lyr)) #Lyr_Lst2 (STRCAT #Lyr_Lst2 "," Lyr_Name) ) ) (SETQ Lyr (TBLNEXT "layer")) ) (COMMAND ".layer" "off" "*" "") (IF Sset (PROGN (SETQ N (SSLENGTH Sset) Index 0 ) (REPEAT N (SETQ Group_Codes (ENTGET (SSNAME Sset Index)) Lyr_Name (CDR (ASSOC 8 Group_Codes)) Lyr_Lst1 (STRCAT Lyr_Lst1 "," Lyr_Name) Index (+ Index 1) ) ) ) ) (COMMAND ".-layer" "on" Lyr_Lst1 "") (LYRTGL_RESTORE "") ) ; If the list is found, turn on all layers which were on originally or ; which have been turned on since. (PROGN (SETQ Lyr (TBLNEXT "layer" T) Lyr_Lst1 "" ) (WHILE Lyr (IF (> (CDR (ASSOC 62 Lyr)) -1) (PROGN (SETQ Lyr_Name (CDR (ASSOC 2 Lyr)) Lyr_Lst1 (STRCAT Lyr_Name "," Lyr_Lst1) ) ) ) (SETQ Lyr (TBLNEXT "layer")) ) (COMMAND ".-layer" "on" "*" "off" #Lyr_Lst2 "on" Lyr_Lst1 "") (SETQ #Lyr_Lst2 nil) (LYRTGL_RESTORE "") ) ) (princ)) Quote Link to comment Share on other sites More sharing options...
NKG Posted November 24, 2009 Share Posted November 24, 2009 Dear alanjt, THANKS YOU! THANK YOU! THANK YOU! LYRTGL.LSP is somthing i've been looking for a longtime, and it works just fine for me. Quote Link to comment Share on other sites More sharing options...
ALKISTI Posted February 17, 2012 Share Posted February 17, 2012 It works really nice !! Quote Link to comment Share on other sites More sharing options...
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.