Seek a lisp for Layer turn off for Prefix "A002"

Seek a lisp for Layer turn off for Prefix "A002"

skchui6159
Advocate Advocate
663 Views
7 Replies
Message 1 of 8

Seek a lisp for Layer turn off for Prefix "A002"

skchui6159
Advocate
Advocate

if I want to turn off layer prefix of "A002". How to do?

0 Likes
Accepted solutions (2)
664 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor

Do you mean la off A002* Enter Enter

0 Likes
Message 3 of 8

skchui6159
Advocate
Advocate

I am reference the below lisp.

(defun C:LAYERS_OFF (/ layobj)
(vl-load-com) ; 
(foreach layname '("A002_A" "A002_B" "A002_C" "A002_D") ; 
(if
(setq layobj (tblobjname "layer" layname)) ; 
(progn

(vla-put-LayerOn (vlax-ename->vla-object layobj) 0) ; 
(princ (strcat "\nLayer " layname " has been turned Off."))
)
)
)

(princ) ; 
)

0 Likes
Message 4 of 8

komondormrex
Mentor
Mentor

switch off either layer with the name in the list '("A002_A" "A002_B" "A002_C" "A002_D").

 

(defun C:LAYERS_OFF nil
	(vl-load-com) 
	(vlax-map-collection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (layer) (if (and (wcmatch (vla-get-name layer) "A002*")
								  (minusp (vlax-get layer 'layeron))
							 )
								(vlax-put layer 'layeron 0)
						 )
		 )
	)
	(princ) 
)

 

updated

0 Likes
Message 5 of 8

skchui6159
Advocate
Advocate

I want to switch off like below:

"A002___A"

"A002_13"

"A002"

"A00200"....etc

0 Likes
Message 6 of 8

komondormrex
Mentor
Mentor
Accepted solution

#4 updated

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

I agree with @Sea-Haven in Message 2 -- and in AutoLisp terms, nothing more than this is needed:

 

(defun C:YourCommandName ()

  (command "_.layer" "_off" "A002*" "")

  (prin1)

)

Kent Cooper, AIA
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor
Accepted solution

Thanks Kent, I just typed, -la off a002* enter, took what 4 seconds do we need code ? The command name as suggested by Kent "A002",  say 1 second to type. 

0 Likes