Help! Lisp for layer control issue

Help! Lisp for layer control issue

mwright1971
Enthusiast Enthusiast
1,627 Views
10 Replies
Message 1 of 11

Help! Lisp for layer control issue

mwright1971
Enthusiast
Enthusiast

I have lisp that I could use some help in figuring out (see attached). I'm creating a little lisp to help our office turn layers on and off quickly when the xref has a lot of info in the base. The problem is that AutoCAD recognizes AD1 and AD2 as a command but not A1. If someone out there has experience with this and can look at what I have written to see what the problem is, I would appreciate it.

Thanks!

0 Likes
Accepted solutions (1)
1,628 Views
10 Replies
Replies (10)
Message 2 of 11

CodeDing
Advisor
Advisor

@mwright1971 ,

 

This is because in your .lsp you have it defined as "N1"

image.png

Best,

~DD

0 Likes
Message 3 of 11

mwright1971
Enthusiast
Enthusiast

Yes I know, changed it to N1 to see if A1 was not being accepted. N1 or A1 doesn't work. I'm thinking I might need two letters in front of the number for the command. I'm going to try that next.

0 Likes
Message 4 of 11

CodeDing
Advisor
Advisor
Accepted solution

@mwright1971 ,

 

In the A1 / N1 function.. remove the quotation after "DEMO"..

Currently:

..."off" "DEMO",*9*,*SWLK*...

Should be:

..."off" "DEMO,*9*,*SWLK*...

..this will solve your isue.

Best,

~DD

 

 

0 Likes
Message 5 of 11

Kent1Cooper
Consultant
Consultant

Extraneous double-quote:

....  "off" "DEMO",*9*,*SWL ....

Kent Cooper, AIA
0 Likes
Message 6 of 11

mwright1971
Enthusiast
Enthusiast

That pointed me in the direction. I had a quotation mark where I should had an asterisk! I found it and now it works. Thank you for helping out Denon!

0 Likes
Message 7 of 11

CodeDing
Advisor
Advisor

@mwright1971 ,

 

This may have been worth it.. or maybe not.. But I created a function that avoids the "command" version of what you want to accomplish.. Your current method is probably more efficient, but regardless, I learned some things. (plus, mine provides semi-nifty feedback <image below code>).

(defun c:AD1 ( / onList offList)
(setq onList '("0" "*ada clearance*" "*BASE_WALL*" "*BASE_COL" "*BASE_DOOR*" "*BASE_GLZG*" "*BASE_SILL"
	       "*BASE_STRS*" "*BASE_MFIX*" "*BASE_CNPY" "*BASE_SFFT*" "*BASE_PLBG*" "*BASE_COOLER*"
	       "CLEAR_SPACE" "DEF-CLEAR" "BORDER_TBTEXT" "BRDR" "*TBTEXT*" "*CVS_MERCH*" "*TEXT"))
(setq offList '("*NEW" "*9*" "*SWLK*" "ARCH_RF_CRKT" "ARCH_RF_CRKT_DEMO" "ARCH_RF_CRKT_NEW"
		"ARCH_RF_DIM" "ARCH_RF_DIM_DEMO" "ARCH_RF_DIM_NEW" "ARCH_RF_ROOF" "ARCH_RF_ROOF_DEMO"
		"ARCH_RF_ROOF_NEW" "ARCH_RF_SKYLIGHT" "ARCH_RF_SKYLIGHT_DEMO" "ARCH_RF_SKYLIGHT_NEW"
		"ARCH_RF_SYM" "ARCH_RF_SYM_DEMO" "ARCH_RF_SYM_NEW" "ARCH_RF_TXT" "ARCH_RF_TXT_DEMO"
		"ARCH_RF_TXT_NEW" "ARCH_RF_VENTS" "ARCH_RF_VENTS_DEMO" "ARCH_RF_VENTS_NEW" "ARCH_RF_WALK"
		"ARCH_RF_WALK_DEMO" "ARCH_RF_WALK_NEW" "*RCP*" "ARCH_RF_EQUIP" "ARCH_RF_EQUIP_DEMO"
		"ARCH_RF_EQUIP_NEW" "ARCH_RF_HATCH" "ARCH_RF_HATCH_DEMO" "ARCH_RF_HATCH_NEW" "*HVAC*"
		"*CLGD*" "*SPNKR*" "*HEDR*" "*LTG*" "*FLOORING*" "ProductHatch" "*BlkOutline*"
		"*STPL*" "Fixtures" "*Fittings*" "_PROJ_INFO" "*YMAS*" "*GROCERY*" "*OPEN*" "*HH*"
		"*NEWTABLOID*" "*PROMO*"))
(setvar 'CLAYER "0");set current layer
(LyrOnOff onList "ON");turn on
(LyrOnOff offList "OFF");turn off
(princ)
);defun

(defun LyrOnOff (layList onOff / l found e)
;layList - list of layer names as strings (can include wildcard "*")
;OnOff - string, "ON" or "OFF" to turn laylist elements on or off
(mapcar '(lambda (i)
	   (setq l (tblnext "LAYER" t))
	   (setq found nil)
	   (while (and l (not found))
	     (setq l (cdr (assoc 2 l)) e (entget (tblobjname "LAYER" l)))
	     (if (wcmatch (strcase l) (strcase i)) (setq found t))
	     (cond
	       ((and found (eq "ON" (strcase onOff)))
		 (if (< (cdr (assoc 62 e)) 0)
		   (entmod (subst (cons 62 (* -1 (cdr (assoc 62 e)))) (assoc 62 e) e)))
		 );if
	       ((and found (eq "OFF" (strcase onOff)))
		 (if (> (cdr (assoc 62 e)) 0)
		   (entmod (subst (cons 62 (* -1 (cdr (assoc 62 e)))) (assoc 62 e) e)))
		 );if
	     );cond
	     (setq l (tblnext "LAYER"))
	     );while
	   (if (not found) (prompt (strcat "\nCould not find and turn " (strcase onOff) " Layer: " i)))
	 );lambda
	layList);mapcar
);defun

image.png

Best,

~DD

Message 8 of 11

mwright1971
Enthusiast
Enthusiast

Thanks for this, I'm just scratching the surface of layer control for my office and trying to see which one will work best for everybody, whether they are newbies or been here forever, so they can easily jump into the xref and not get overwhelmed. I like the fact your's will tell if that layer is in the drawing or not.

0 Likes
Message 9 of 11

scot-65
Advisor
Advisor
An old trick I used in the past is to incorporate a known
layer as part of the comma separated quote - that way it
does not error out if none found.

layer thaw 0 set 0 freeze "defpoints,*|*" thaw "defpoints" ""

Yes, it is command line noisy, but it will not error out.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 10 of 11

Kent1Cooper
Consultant
Consultant

@scot-65 wrote:
An old trick I used in the past is to incorporate a known layer as part of the comma separated quote - that way it does not error out if none found.
….

 

That's not really necessary -- it doesn't error out in that case anyway.  It simply reports that it didn't find any matching Layers, but goes on.  This:

 

Command: (command "_.layer" "_freeze" "Peter,Paul,Mary" "")

 

[with none of those Layers existing in the drawing] results in this:


_.layer
Current layer:  "0"
Enter an option [?/Make/.../Freeze/.../rEconcile]: _freeze
Enter name list of layer(s) to freeze or <select objects>: Peter,Paul,Mary
No matching layer names found. <--simple report without error, and back to base prompt:
Enter an option [?/Make/..../rEconcile]: {Enter "" to end command}
Command:

Kent Cooper, AIA
0 Likes
Message 11 of 11

CodeDing
Advisor
Advisor

UPDATED CODE:

The code I previously posted on this thread will not produce the desired result. I'm only on mobile right now but I wanted to note it..

This line:

(while (and l (not found))

Should be:

(while l

This is because wildcards are accepted in inputs that ALL layers must be looped through every time. I believe that will produce a desired result. I would have to confirm once I get to a computer. Could be a while.

Best,

~DD

0 Likes