Layer Thaw Unfreeze and Unlock and Setbylayer LISP

Layer Thaw Unfreeze and Unlock and Setbylayer LISP

Anonymous
Not applicable
7,642 Views
16 Replies
Message 1 of 17

Layer Thaw Unfreeze and Unlock and Setbylayer LISP

Anonymous
Not applicable

The thread title is what it is... 

 

I need a lisp that will do the following commands in order.  Lando7189 was able to que me into the following code which would do commands in order and here's what I got so far:

(defun C:SB
  nil
  (command "LAYON" "LAYTHW" "SELECT" "ALL" "SETBYLAYER" "Y" "Y")
  (princ) ;clean exit
)

 

I come up with the following error in the command line:

Command: SB
LAYON
All layers have been turned on.
Command: LAYTHW
All layers have been thawed.
Command: SELECT
Select objects: ALL 320 found

Select objects: SETBYLAYER

*Invalid selection*
Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SIngle/SUbobject/Object

Select objects:

 

It's as if it doesn't accept the selection set before performing the setbylayer command.  Maybe there is better lisp code to do this?

 

I also would like to know if there is a lisp or command out there for unlocking all layers in a drawing similar to how laythw or layon work.  I know of LAYULK which gives you a picker to click a locked layer, but end goal is just to unlock all layers for editing.  This would probably be the first command in the list or just before selecting all and doing SETBYLAYER if possible.

 

Thanks,

Warren

 

 

0 Likes
Accepted solutions (3)
7,643 Views
16 Replies
Replies (16)
Message 2 of 17

john.uhden
Mentor
Mentor

I am unfamiliar with SETBYLAYER.  Is that to set the color and linetype of objects to "Bylayer?"

If so, then the solution is easier than what you have started.

Also, do you really want to set all=everything to Bylayer?  How about nested objects?

John F. Uhden

0 Likes
Message 3 of 17

Ranjit_Singh
Advisor
Advisor

Maybe something like this

(command "._-layer" "_u" "*" "_t" "*" "_on" "*" "" "SETBYLAYER" "_all" "" "_y" "_y")

Use the layer transparent command which allows unlock, thaw and on option and then go in the setbylayer command.

 

0 Likes
Message 4 of 17

Anonymous
Not applicable

John,

 

This is for architectural backgrounds that we have to clean up for XREF purposes and the goal is to essentially perform a set of operations to them in order to make them usable for our Mechanical / Electrical / Plumbing drawing purposes.  Other things include modifying colors for our .CTB plot settings.

 

One of the initial steps in adapting these files for our use would be to set all the colors to ByLayer which is what the SETBYLAYER command achieves.  If you start the SETBYLAYER command you can type S for Settings and you get the following options in the screenshot below:

SETBYLAYER SETTINGS.PNG

 

The only one we leave unchecked is Linetype as we want that to be controlled per object for hidden lines etc. that need to remain so.  These seem to save to your default settings so it only has to be set once.  After that you can do a CTRL+A for selecting all prior to performing the SETBYLAYER command, then accepting the defaults of "Change By Block to By Layer?" <Yes> , and then "Include Blocks?" <Yes>.  Maybe this in lies a problem with my code as it might not like the select all, maybe I have to do:

"SETBYLAYER" "ALL" "Y" "Y"

 

 

0 Likes
Message 5 of 17

john.uhden
Mentor
Mentor

There can be a huge difference between an AutoCAD command and an AutoLisp command function.  AutoLisp command functions almost always don't take any arguments, and you can't programmatically feed them responses as you can with an AutoCAD command.

 

Someone else here can probably answer this without even looking, but I recommend you check whether SETBYLAYER is an AutoCAD command, or an AutoLisp command function.

 

At the command prompt, enter !C:setbylayer.  If it returns anything other that nil, then it is an AutoLisp command function, which would mean that you can't call it via (command "SETBYLAYER").  But it may be written to act on an implied selection set, in which case you could try using...

 

(sssetfirst nil (ssget "X"))

before calling the command function.
And after the command function try... (C:SETBYLAYER)

Sorry, but I am just guessing.  I hope it helps somehow.

John F. Uhden

0 Likes
Message 6 of 17

Anonymous
Not applicable

Ranjit,

 

I tried your code and got back the following:

Command: SB
._-layer
Current layer:  "0"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: _u
Enter name list of layer(s) to unlock or <select objects>: * Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: _t
Enter name list of layer(s) to thaw: * Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: _on
Enter name list of layer(s) to turn on: * Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: SETBYLAYER
Current active settings: Color Lineweight Transparency Material
Select objects or [Settings]: _all 3 found
3 were not in current space.

Select objects or [Settings]:
Command: _y Unknown command "Y".  Press F1 for help.

Command: _y Unknown command "Y".  Press F1 for help.

Command:
0 Likes
Message 7 of 17

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

The thread title is what it is... 

 

I need a lisp that will do the following commands in order.  Lando7189 was able to que me into the following code which would do commands in order and here's what I got so far:

(defun C:SB
  nil
  (command "LAYON" "LAYTHW" "SELECT" "ALL" "SETBYLAYER" "Y" "Y")
  (princ) ;clean exit
)

.... 


You're not completing the selection.  Even after saying "ALL", you need to tell it you're done, because there are still choices, such as the Remove option, and it's awaiting further input.  And [I haven't used SETBYLAYER, and I'm at an older-version location right now, so I can't verify] you very likely need to then give it that as the Previous selection.

 

(command "LAYON" "LAYTHW" "SELECT" "ALL" "" "SETBYLAYER" "P" "" "Y" "Y")

Or maybe do the selection within the SETBYLAYER command?

(command "LAYON" "LAYTHW" "SETBYLAYER" "ALL" "" "Y" "Y")
Kent Cooper, AIA
Message 8 of 17

Ranjit_Singh
Advisor
Advisor
Accepted solution

I am not sure how that is possible. As you can see the selection has ended with a ""

(command "._-layer" "_u" "*" "_t" "*" "_on" "*" "" "SETBYLAYER" "_all" "" "_y" "_y")

Are you sure you typed it out correctly?

 

 It works at my end.Set_by_layer.gif

EDIT: I see now that the error is the 3 objects are not in current space? You will need to switch to the right space before calling that "set by layer" command. If you want to change all object in all space then cycle through all the spaces or add a custom list to grab the selection and process each entity. The below one cycles through all layouts. There may be better options available.

(foreach i (layoutlist)
(setvar 'ctab i)
(command "._-layer" "_u" "*" "_t" "*" "_on" "*" "" "SETBYLAYER" "_all" "" "_y" "_y"))
Message 9 of 17

lando7189
Advocate
Advocate

Now you have to get into a little more logic than just passing commands.  You will need to see if anything was actually selected -- this is done by setting a variable to a selection set.  If there is anything in the selection set, then proceed:

 

(defun C:SB
  ( / ss) ;args/vars
(princ "\nSelect objects to set to bylayer... ") (if (setq ss (ssget)) ;if selection set exists (command "LAYON" "LAYTHW" "SETBYLAYER" ss "" "Y" "Y") ) (princ) ;clean exit )

HTH - Lanny

0 Likes
Message 10 of 17

lando7189
Advocate
Advocate

I'm guessing that you want to probably turn on and thaw the layers before you select -- then split up the 'command' portion.  This way, the command will always run the 'LAYON' & 'LAYTHW' commands.

 

(defun C:SB
  ( / ss) ;args/vars
  (command "LAYON" "LAYTHW")
(princ "\nSelect objects to set to bylayer... ") (if (setq ss (ssget)) ;if selection set exists (command "SETBYLAYER" ss "" "Y" "Y") ) (princ) ;clean exit )
0 Likes
Message 11 of 17

gccdaemon
Collaborator
Collaborator
Accepted solution

You just needed the return after the "all" which is represented by double quotes "", and by using the selection already inside the setbylayer command you get an easier work flow.

 

Here is your example without getting too far into additional coding:

 

(defun C:SB
  nil
  (command "LAYON" "LAYTHW" "SETBYLAYER" "ALL" "" "Y" "Y")
  (princ) ;clean exit
)
Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 12 of 17

Anonymous
Not applicable

Thanks all,

 

I was just missing the " " character to denote a return/enter in the string.  Wasn't sure what that character was in LISP, because I was able to get the command to work to that point but just having to hit enter manually 2 times afterward for the two prompts that come up.  We are typically only doing this to the current work space when in the drawing.  It could be in model space if an architectural background clean up, or paper space if we are cleaning up an existing title block for our use.  

 

Still wondering what there might be as far as unlocking all layers that may appear in the current workspace of a drawing or the entire drawing for that matter.  Similar to LAYON or LAYTHW.  Seems from Ranjit's reply that there is the "-layer" command which can be followed with "u" for unlock and then it needs a selection set.... "ALL" doesn't seem to work here though.  But it would work if I maybe do a "SELECT" "ALL" before initiating the layer and unlock.  Both of these options would only get everything in the current workspace obviously, but otherwise than this method, would I have to do some sort of ssget selection set and get further into the code?

 

Sorry for not getting back sooner, been trying to keep above water here at work.

0 Likes
Message 13 of 17

Anonymous
Not applicable

I think it lies in the unlock layers as the SETBYLAYER seems to work.  I tried adding in strings for the -layer, unlock, commands but after you choose the option to select objects instead of a named selection set, it goes to a picker mode vs a bounding box or typical selection mode.

 

0 Likes
Message 14 of 17

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

...

Still wondering what there might be as far as unlocking all layers that may appear in the current workspace of a drawing or the entire drawing for that matter.  Similar to LAYON or LAYTHW.  Seems from Ranjit's reply that there is the "-layer" command which can be followed with "u" for unlock and then it needs a selection set....


The Unlock option in a Layer command doesn't want a selection set, nor selection of a single object like the LAYULK command for one Layer, but a Layer name or names.  [Do it manually and watch the prompts.]  You can use * as a wildcard for all  Layers.

 

(command "_.layer" "_unlock" "*" "")

Kent Cooper, AIA
0 Likes
Message 15 of 17

gccdaemon
Collaborator
Collaborator

Actually, using the "-layer" command, you can unlock all layers by adding a "*" in the layer name. This will unlock ALL layers, not just the ones in current view.

 

Here is that adjustment in your routine:

 

(defun C:SB nil
  (command "-LAYER" "U" "*" "" "")
  (command "LAYON" "LAYTHW" "SETBYLAYER" "ALL" "" "Y" "Y")
  (princ) ;clean exit
)

Kent, you replied before I could finish, lol. Oh, and for -layer it's double return at the end 😉

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
0 Likes
Message 16 of 17

Ranjit_Singh
Advisor
Advisor

@Anonymous wrote:

I think it lies in the unlock layers as the SETBYLAYER seems to work.  I tried adding in strings for the -layer, unlock, commands but after you choose the option to select objects instead of a named selection set, it goes to a picker mode vs a bounding box or typical selection mode.

 


Post #3 and Post #8, both use -layer followed with _u and * to unlock all? I am not sure if you just missed that or maybe I am missing something?

0 Likes
Message 17 of 17

Kent1Cooper
Consultant
Consultant

@gccdaemon wrote:

.... Oh, and for -layer it's double return at the end 😉


... only if the last option you used took the default Layer name, typically when the last option is assigning a color or linetype to the current Layer, the first of the two Enters being to accept the current Layer name for that assignment.  But in this case, the "*" says to Unlock all Layers, then it goes back to the base prompt, and one  last Enter "" concludes the command.  As you have it, the last Enter will recall the latest command used outside the routine, which could be anything, and might want user input for which "LAYON" will be fed in and probably will not be an acceptable response.  [If you're lucky, it might have been something like REDRAW or REGEN that won't ask for anything, and you won't notice.]

 

By the way, the hyphen is not needed before the Layer command name to suppress the dialog-box operation and use the command-line version, when in an AutoLisp (command) function, because in those, command-line operation is the default [you have to deliberately force it to use the dialog box if you do  want it].  However, some overlay programs such as Architectural Desktop undefine  the native Layer command and make their own specialty version, in which case just plain "LAYER" won't be recognized in a (command) function.  "-LAYER" with the hyphen may  be in such a case, but to be universal, I always include the period prefix, to force it to dig down to the native command operation, and skip the hyphen.

 

Kent Cooper, AIA
0 Likes