Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

command for switching off all but one layer in a group

7 REPLIES 7
Reply
Message 1 of 8
neeboy74
337 Views, 7 Replies

command for switching off all but one layer in a group

I prostrate myself before the altar of the CodeGeeks with a quandry:

I have 5 layers (called 1,2,3,4,5). I need an expression for switching off all but one of them. What I am going to do eventually is have 5 buttons on a custom toolbar that will switch just one of these layers out of the five on at a time.

Can someone give me an expression (invoked with a text command) that will accomplish this? I'm guessing I'll need 5 different lsp routines and that's fine. I can write the other 4 if someone can give me the first one. I know how to map to a button, just need help with the mechanics of the switchin.' Thanks!
7 REPLIES 7
Message 2 of 8
bob.at
in reply to: neeboy74

Not tested, but maybe something like this to swich layer "5" on:

(command "_layer" "_off" "1,2,3,4" "_on" "5" "")

--
bob.at
CAD & GIS Services, Graz, Austria


schrieb im Newsbeitrag news:6035387@discussion.autodesk.com...
I prostrate myself before the altar of the CodeGeeks with a quandry:

I have 5 layers (called 1,2,3,4,5). I need an expression for switching off
all but one of them. What I am going to do eventually is have 5 buttons on
a custom toolbar that will switch just one of these layers out of the five
on at a time.

Can someone give me an expression (invoked with a text command) that will
accomplish this? I'm guessing I'll need 5 different lsp routines and that's
fine. I can write the other 4 if someone can give me the first one. I know
how to map to a button, just need help with the mechanics of the switchin.'
Thanks!
Message 3 of 8
andrew_nao
in reply to: neeboy74

there is probably a easier way to code this but i use this
it sets to layer 0 and turns off my layers called 2 and 3

(defun c:LOFF ()
(Command "LAYER" "S" "0" "")
(setvar "cmdecho" 0)
(command "LAYER" "OFF" "3" "OFF" "2" "")
(PRINC)
)


wrote in message news:6035387@discussion.autodesk.com...
I prostrate myself before the altar of the CodeGeeks with a quandry:

I have 5 layers (called 1,2,3,4,5). I need an expression for switching off
all but one of them. What I am going to do eventually is have 5 buttons on
a custom toolbar that will switch just one of these layers out of the five
on at a time.

Can someone give me an expression (invoked with a text command) that will
accomplish this? I'm guessing I'll need 5 different lsp routines and that's
fine. I can write the other 4 if someone can give me the first one. I know
how to map to a button, just need help with the mechanics of the switchin.'
Thanks!
Message 4 of 8
Anonymous
in reply to: neeboy74

Another way, that takes care of the possibility that one of the Layers you want to turn Off might be
the *current* Layer:

(command "_.layer" "_set" "1" "_off" "*" "_no" "")

A nice thing about Layer inside a (command) function, or -Layer at the Command: prompt, is that
Setting a Layer current that way will turn it On if it's Off, so you don't need to turn it On
explicitly.

Or, if there are also other Layers in the drawing that you don't want to be affected, then you would
want specify just the ones you want off, rather than turn off all but the current one:

(command "_.layer" "_set" "1" "_off" "2,3,4,5" "")

If there's any chance the Layer in question might be Frozen:

(command "_.layer" "_thaw" "1" "_set" "1" "_off" "*" "_no" "")

In a Toolbar button, they could be in Macro format:

'-LAYER Set 1 Off * No ;
or
'-LAYER Set 1 Off 2,3,4,5 ;
or
'-LAYER Thaw 1 Set 1 Off * No ;

That has the advantage that it can be *transparent* -- you can do it in the middle of another
command.
--
Kent Cooper


neeboy74 wrote...
I prostrate myself before the altar of the CodeGeeks with a quandry:

I have 5 layers (called 1,2,3,4,5). I need an expression for switching off all but one of them.
What I am going to do eventually is have 5 buttons on a custom toolbar that will switch just one of
these layers out of the five on at a time.

Can someone give me an expression (invoked with a text command) that will accomplish this? I'm
guessing I'll need 5 different lsp routines and that's fine. I can write the other 4 if someone can
give me the first one. I know how to map to a button, just need help with the mechanics of the
switchin.' Thanks!
Message 5 of 8
neeboy74
in reply to: neeboy74

Hello Kent; here's exactly what I'll be using this for:

I will have 9 layers. Each of these layers will have guidelines on them. These guidelines will be used as "snap lines" when I draw elevations. That way, I can draw an elevation, then dimension it across the bottom and snap the dimensions to these guidelines. You can see why only 1 layer should be on at a time, otherwise I'd have a jumble of un-needed lines on the screen at once.

The layers will be different in that the spacing between the lines will shrink as the annotation scale changes, with the "Full-Scale Layer" having the lines closest together in Model Space.

I really like your idea of being able to invoke this command while in the middle of something else (because I know I'll forget to set this before dimensioning)

The layers will not be frozen but I will have them locked so that the lines can't be moved. I will also not be drawing anythng on these layers after setting up the guidelines.

If you could write code for this that'd be super. Each layer could be labeled sequentially 1-9 for this purpose. Thanks so very much!
Message 6 of 8
Anonymous
in reply to: neeboy74

Then bob.at's suggestion should do well for you:

(command "_layer" "_off" "1,2,3,4" "_on" "5" "")

[except that for me in ADT [this may not be true for you], I have to put the decimal place in front
of "_.layer" for it to work.]

Or, converted to macro language so you can do it in mid-command, and expanded up to 9 Layers:

[GuideLines1]'-LAYER Off 2,3,4,5,6,7,8,9 On 1 ;

[GuideLines2]'-LAYER Off 1,3,4,5,6,7,8,9 On 2 ;

[GuideLines3]'-LAYER Off 1,2,4,5,6,7,8,9 On 3 ;

[GuideLines4]'-LAYER Off 1,2,3,5,6,7,8,9 On 4 ;

[GuideLines5]'-LAYER Off 1,2,3,4,6,7,8,9 On 5 ;

[GuideLines6]'-LAYER Off 1,2,3,4,5,7,8,9 On 6 ;

[GuideLines7]'-LAYER Off 1,2,3,4,5,6,8,9 On 7 ;

[GuideLines8]'-LAYER Off 1,2,3,4,5,6,7,9 On 8 ;

[GuideLines9]'-LAYER Off 1,2,3,4,5,6,7,8 On 9 ;

If you're putting them into Toolbars or something with icons, you can porbably dispense with the
[bracketed] headings, but you would need them for a Screen menu or Pull-down menu. You could also
leave them there even where they're not needed, for identifying what the menu items are for when you
get back into the menu later.
--
Kent Cooper


neeboy74 wrote...
Hello Kent; here's exactly what I'll be using this for:

I will have 9 layers. Each of these layers will have guidelines on them. These guidelines will be
used as "snap lines" when I draw elevations. That way, I can draw an elevation, then dimension it
across the bottom and snap the dimensions to these guidelines. You can see why only 1 layer should
be on at a time, otherwise I'd have a jumble of un-needed lines on the screen at once.

The layers will be different in that the spacing between the lines will shrink as the annotation
scale changes, with the "Full-Scale Layer" having the lines closest together in Model Space.

I really like your idea of being able to invoke this command while in the middle of something else
(because I know I'll forget to set this before dimensioning)

The layers will not be frozen but I will have them locked so that the lines can't be moved. I will
also not be drawing anythng on these layers after setting up the guidelines.

If you could write code for this that'd be super. Each layer could be labeled sequentially 1-9 for
this purpose. Thanks so very much!
Message 7 of 8
Anonymous
in reply to: neeboy74

Just for your information, that can be shortened somewhat, since in the Command-line Layer command,
you can designate more than one Layer name in one option, with comma separators:

(defun c:LOFF ()
(Command "LAYER" "S" "0" "")
(setvar "cmdecho" 0)
(command "LAYER" "OFF" "2,3" "")
(PRINC)
)

And, unless there's some reason you really want to leave CMDECHO on until *after* you've set Layer 0
current, you can also use multiple Layer options in one Layer command:

(defun c:LOFF ()
(setvar "cmdecho" 0)
(Command "LAYER" "S" "0" "OFF" "2,3" "")
(PRINC)
)

--
Kent Cooper


andrew_nao wrote...
there is probably a easier way to code this but i use this
it sets to layer 0 and turns off my layers called 2 and 3

(defun c:LOFF ()
(Command "LAYER" "S" "0" "")
(setvar "cmdecho" 0)
(command "LAYER" "OFF" "3" "OFF" "2" "")
(PRINC)
)
....
Message 8 of 8
chatsupakasem
in reply to: neeboy74

;;; ON one - Off all, For Layer.
;;; ****** DEFINE YOUR LAYER NAME AT ************************
;;; (setq LayerList (list "1" "2" "3" "4" "5"))
;;; ***********************************************************
;;; Toolbar Macro:
;;; ^C^CLX "1"
;;; ^C^CLX "2"
;;; ^C^CLX "3"
;;; ^C^CLX "4"
;;; ^C^CLX "5"
;;; Note:
;;; 1. Layer "0" must not be frozen and off.
;;; 2. Run LX and See the options on Dynamic Input (1,2,3,4 and 5).
;;; So no need creating new toolbar buttons.
(defun Onlayer (layername / a assoc62)
(if (setq a (tblobjname "layer" layername))
(progn
(setq a (entget (tblobjname "layer" layername))
assoc62 (assoc 62 a)
)
(if
(< (cdr assoc62) 0)
(progn
(entmod
(subst
(cons 62 (abs (cdr assoc62)))
assoc62
a
)
)
)
)
layername
) ;progn
nil
)
)
(defun Offlayer (layername / a assoc62)
(if (setq a (tblobjname "layer" layername))
(progn
(setq a (entget (tblobjname "layer" layername))
assoc62 (assoc 62 a)
)
(if
(not (< (cdr assoc62) 0))
(progn
(if (= (strcase layername) (strcase (getvar "clayer")))
(setvar "clayer" "0") ;
)
(entmod
(subst
(cons 62 (- (cdr assoc62)))
assoc62
a
)
)
)
)
layername
) ;progn
nil
)
)
(defun c:LX (/ olderr l LayerList OFFList str str2 ON OFF)
(setq olderr *error*)
(defun *error* (msg)
(if (not
(member msg (list "Function cancelled" "quit / exit abort"))
)
(princ (strcat "\nLX ERROR: " msg))
)
(setq *error* olderr)
(princ)
)
;;; ***********************************************************
;;; ****** DEFINE YOUR LAYER NAME HERE ************************
(setq LayerList (list "1" "2" "3" "4" "5"))
;;; ***********************************************************
;;; ***********************************************************
(setq ListExist T)
(foreach l LayerList
(setq ListExist (and ListExist
(and (= 'STR (type l))
(tblsearch "layer" l)
)
)
)
)
(if ListExist
(progn
(setq LayerList (mapcar 'strcase LayerList)
str ""
str2 ""
)
(foreach l Layerlist
(setq str (strcat str "/" l))
)
(setq str (strcat "Turn On Layer "
"\["
(substr str 2)
"\]:<"
(nth 0 LayerList)
">"
)
)
(foreach l LayerList
(setq str2 (strcat str2 l " "))
)
(setq str2 (substr str2 1 (1- (strlen str2))))
(initget 1 str2)
(setq ON (getkword str))
(foreach l LayerList
(if (/= ON l)
(setq OFFList (append OFFList (list l)))
)
)
;; Processing On-Off
(setq OFF "")
(foreach l OFFList
(setq OFF (strcat OFF "," l))
)
(setq OFF (substr OFF 2))
(foreach l OFFList
(OffLayer l)
)
(OnLayer On)
(princ "\nTurn ON Layer: ")
(princ ON)
(princ "\nTurn OFF Layer: ")
(princ OFF)
)
(princ
"\n***CANNOT PROCESSING!!!***CHECKED LAYERLIST VARIABLE!!!***"
)
)
(setq *error* olderr)
(princ)
)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost