Grab an attribute then use it to turn off a layer

Grab an attribute then use it to turn off a layer

brian_shick
Enthusiast Enthusiast
321 Views
3 Replies
Message 1 of 4

Grab an attribute then use it to turn off a layer

brian_shick
Enthusiast
Enthusiast

Good morning,

I am very new to LISP and need your help, at this point I can only make minor changes to existing code but a lot of the code still is magic to me.

 

I have a block "ULTRA INFO" with an attribute "CIRCID" that can be used to help turn off a layer with that name that has "-DATA" added to the end. What I think we need to do is to grab the attribute variable and store it, then add a wild card * to the end, lastly have it turn off a layer with that name.

 

Here is my thought:

Some how scan the drawing for an attribute named "CIRCID" if it is found store it as "LAName"

Then turn off the layer: (command "-Layer" "off" "(LAName)*" "")

If an attribute named "CIRCID" doe not exist cancel and end the lisp.

 

Any help possible is greatly appreciated.

Thank you all in advance.

Brian

0 Likes
322 Views
3 Replies
Replies (3)
Message 2 of 4

paullimapa
Mentor
Mentor
0 Likes
Message 3 of 4

hmsilva
Mentor
Mentor

One way...

 

(vl-load-com)
(defun c:demo ( / ACTLAY LANAME SS)
 (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "ULTRA INFO") (66 . 1) )))
    (foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss 0)) 'getattributes)
      (if (= (strcase (vla-get-tagstring att)) "CIRCID")
	(progn
	  (setq	LAName (vla-get-textstring att)
		*adoc* (vla-get-ActiveDocument (vlax-get-acad-object))
		actlay (vla-get-ActiveLayer *adoc*))
	  (vlax-for lay (vla-get-Layers *adoc*)
	    (if (and (wcmatch (strcase (vla-get-name lay)) (strcase (strcat LAName "*")))
		     (not (= (strcase (vla-get-name lay)) (strcase LAName )))
		     )
	      (vla-put-LayerOn lay :vlax-false)
	      )
	    )
	  )
	)
      )
   )
  (princ)
  )

 

 

HTH

Henrique

EESignature

0 Likes
Message 4 of 4

_Tharwat
Advisor
Advisor
0 Likes