Jump to content

Grab an attribute then use it to turn off a layer


Recommended Posts

Good afternoon,

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" for later use.

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

 

Any help possible is greatly appreciated.

Thank you all in advance.

Brian

Link to post
Share on other sites
  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    10

  • Railyn

    8

  • BShick5088

    6

  • steven-g

    3

Do you plan to pick 1 block on screen otherwise it will find 1st occurence of the tag CIRCID and use that if not blank.

 

Secondly (command "-Layer" "off" LAName "") you would add the * to the layer name via the lisp (setq LAName (strcat LAName "*")).

 

Post a dwg with the block makes it easier to match 100% very easy task.

Link to post
Share on other sites

Attached is an example of one of the many drawings that will need this change.

 

The two things that need to be done are:

1) Turn on the "SHOTS" layer, I can do this with:

(Command "-layer" "O" "SHOTS" "")

 

2) Grab the ULTRA INFO block's CIRCID attribute add a * to it then turn off that layer.

 

If you turn on the Shots layer you will see that a second comment is pointing to the same point showing a number and a pipe wall thickness. The company has decided to go back to the older way of showing a circle with a number that would reference an excel spreadsheet that will show a wall thickness corrosion history for each spot.

Thank you so much for your help!!!

Example.dwg

Link to post
Share on other sites

The text and leader lines on that layer would be in different locations from drawing to drawing and I want to run this with a script file so I can apply the change to hundreds at a time without having a user do anything.If I must include a crossing pick to grab the block "ULTRA INFO" I can, at least it is in the same spot in all the drawings. "6.047,1.214" "5.689,1.291"

Link to post
Share on other sites

Yes, CIRCID is the tag of the ULTRA INFO block but what I need to do is get the attribute value from that tag. In the earlier example drawing the value is "H1-023" in the attached Example2 the value is "H2-020". By grabbing that value we could then concatenate the "*" or the actual end of layer name "-DATA" and be able to automatically turn off the layer. I just don't know LISP well enough to:

1) Grab the value from a block's tag.

2) Concatenate the "*" or "-DATA" to the tag's value

3) Then use that stored value to turn off the layer.

I want to used the tag's value in this way because it is a reduced form of the drawing number that had been used at sometime in the past to create several layers that now need to be turned off especially the one ending with DATA. I attached a second example so you can see what I mean.

Example2.dwg

Link to post
Share on other sites

This should toggle the layer on and off depends on the status of the layer name if it is matched the value of attribute value in the target block name .

 

Try it and let me know .

 

(defun c:Test (/ s i l lst e n a)
 ;;    Tharwat 12.9.2014    ;;
 (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1) (2 . "ULTRA INFO"))))
   (repeat (setq i (sslength s))
     (mapcar
       '(lambda (u)
          (if
            (eq (strcase (vla-get-tagstring u)) "CIRCID")
             (setq lst (cons (vla-get-textstring u) lst))
          )
        )
       (vlax-invoke
         (vlax-ename->vla-object (ssname s (setq i (1- i))))
         'getAttributes
       )
     )
   )
 )
 (if lst
   (while (setq a (tblnext "LAYER" (not a)))
     (foreach x lst
       (if (wcmatch (setq n (cdr (assoc 2 a))) (strcat x "*"))
         (entmod
           (subst (cons 62 (- (cdr (assoc 62 a))))
                  (assoc 62 (setq e (entget (tblobjname "LAYER" n))))
                  e
           )
         )
       )
     )
   )
 )
 (princ)
)(vl-load-com)

Link to post
Share on other sites

Now that idea will work...

I was so stuck in the LISP thinking a quick simple answer like that may never have occurred.

 

 

You've heard "You can't see the forest for the trees.." I seem to be thinking more like "You can't see the forest for the deciduous conifers..."

 

 

If anyone could still give me an example of the LISP style it will help me to understand other things that may fall more in that realm. At least for now I can finish my task.

 

 

Thank you Steven, you saved my sanity!!!

I know I would be banging away at this all weekend...

Link to post
Share on other sites

Thanks to Steve for pulling me out of the weeds and back on the path.

 

 

Thank you Tharwat, you are a Master among men. That code you attached works perfectly!!!

 

 

I can't thank you all enough!!!

Have a great weekend, I will now.

Link to post
Share on other sites

 

Thank you Tharwat, you are a Master among men. That code you attached works perfectly!!!

 

I can't thank you all enough!!!

Have a great weekend, I will now.

 

:lol:

 

You're welcome .

 

Notice that if you run the routine and the needed layer is already off , it would be on and vise versa ;)

Link to post
Share on other sites
  • 1 year later...

Hi, sorry for hijacking your tread but I was looking to do something very similar and I was hoping you could help since you managed to solve your problem :)

I was hoping for a lisp that automatically turns off a specific layer if a specific tag (the tag is not on that layer) is empty and turns it on again if that same tag contains information. Do you think this can be achieved with a similar kind of lisp?

Link to post
Share on other sites
Tharwat

I was hoping for a lisp that automatically turns off a specific layer if a specific tag (the tag is not on that layer) is empty and turns it on again if that same tag contains information. Do you think this can be achieved with a similar kind of lisp?

 

Yes it is possible but you need to show a practical example.

Link to post
Share on other sites
Tharwat
It's the Tag 'HEADER6' on 'HEADER_N13'

 

I think you mean or and not on in your sentence , right ?

 

I am sorry , I am not talking about wildcards but the Name of Attributed Block name(s).

Link to post
Share on other sites
Tharwat

Anyway try this program and let me know;

 

(defun c:Test (/ s _t)
 ;; Tharwat 14.03.2016 ;;
 (defun _t (obj / att)
 (if
   (vl-some '(lambda (x)
               (and (wcmatch (strcase (vla-get-tagstring x)) "HEADER6,HEADER_N13")
                    (setq att x))
               )
            (vlax-invoke obj 'getattributes)
            )
   (vla-put-Layeron (vlax-ename->vla-object (tblobjname "LAYER" "REACTOR LAYER"))
     (if (eq (vla-get-textstring att) "") 0 1))
   )
 )
 (cond (  (not (tblsearch "LAYER" "REACTOR LAYER"))
            (alert "Layer name <REACTOR LAYER> is not found in this drawing !")
          )
       (  (and (princ "\nPick on Attributed Block: ") (setq s (ssget "_+.:S" '((0 . "INSERT")(66 . 1)))))
            (_t (vlax-ename->vla-object (ssname s 0)))
          )
       (t (princ "\nNothing selected or selection is not attributed block !")
          )
     )
(princ)
)(vl-load-com)

Link to post
Share on other sites
I think you mean or and not on in your sentence , right ?

 

I am sorry , I am not talking about wildcards but the Name of Attributed Block name(s).

 

no... the block is named 'HEADER_N13' and the tag in question is 'HEADER6'...

or am I being confused? sorry if I am not clear.

 

I will try your lisp right away, thank you!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...