Jump to content
RubberDinero

Change Nested and Unested object layer

Recommended Posts

RubberDinero

I'm looking for a lisp that will scan the entire drawing for objects that are on layers and change it to another layer

 

i.e.

drawings that have objects within and outside of blocks with "their-sewer-layer", select all those objects without exploding the blocks and change them to "my-sewer-layer" 

 

I've seen a few lisps but they don't work for objects inside a block. 

 

 

Thanks in advanced!

Share this post


Link to post
Share on other sites
Tharwat

Something like this?

(defun c:Test (/ doc)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for obj (vla-get-blocks doc)
    (or (= :vlax-true (vla-get-IsXRef obj))
        (vlax-for itm obj
          (if (= (vla-get-layer itm) "their-sewer-layer") (vla-put-layer itm "my-sewer-layer") )
        )
    )
  )
  (vla-regen doc AcAllViewports)
  (princ)
) (vl-load-com)

 

Share this post


Link to post
Share on other sites
RubberDinero

it did not work, but I'm guess it was because I am trying to use an asterisk "*sewer*" to get all related sewer entities.

Share this post


Link to post
Share on other sites
Tharwat
3 minutes ago, RubberDinero said:

it did not work, but I'm guess it was because I am trying to use an asterisk "*sewer*" to get all related sewer entities.

Actually it DOES work but you have changed your intention and wanted something different than what you have explained in the first post.

 

Anyway, if you want it with wildcard then just replace the following and be sure to have the target layer available in the drawing.

Replace this:

(if (= (vla-get-layer itm) "their-sewer-layer") (vla-put-layer itm "my-sewer-layer") )

With this:

(if (wcmatch (vla-get-layer itm) "*sewer*") (vla-put-layer itm "my-sewer-layer"))

 

Share this post


Link to post
Share on other sites
RubberDinero
Posted (edited)

I apologize for my ineptitude at explaining my intended use. 

 

I would like a lisp that can examine items like polylines, texts, circles, blocks, etc (every type of objects) that may be in model space or at the same time within a block reference(the objects in a block reference being more polylines, texts, circles, etc), and globally change the layer of individual objects who's original layer is containing the wildcard "*sewer*" to a layer of my choice. In this "Test" a layer named "My-Sewer-Layer".

 

In this scenario, as tested above, the code not was useful for my intended use, but that was my fault for not describing with more detail exactly what I was needing.

 

Thanks!

 

 

Edited by RubberDinero

Share this post


Link to post
Share on other sites
Tharwat

No worries, just replace what I have described in my last reply then try again.

Share this post


Link to post
Share on other sites
RubberDinero

That worked great! only issue was that it was case sensitive, but i fixed it by adding an additional line

(if (wcmatch (vla-get-layer itm) "*sewer*") (vla-put-layer itm "my-sewer-layer")
(if (wcmatch (vla-get-layer itm) "*Sewer*") (vla-put-layer itm "my-sewer-layer"))

Is this how you would have handled this case?

Share this post


Link to post
Share on other sites
Tharwat

Not quite but the following is to cover all cases:

(if (wcmatch (strcase (vla-get-layer itm)) "*SEWER*") (vla-put-layer itm "my-sewer-layer"))

 

Share this post


Link to post
Share on other sites
RubberDinero

Nice! Thanks!

Share this post


Link to post
Share on other sites
Tharwat

You're welcome anytime.

Share this post


Link to post
Share on other sites
RubberDinero

This has been working perfectly!

is there a way to create or statements? look for "*SEWER*" or "*SWR*" or "*Sewr*"

I don't mind creating additional lines. I have already added additional lines for water and gas with different abbreviation, but I was just curious .

Share this post


Link to post
Share on other sites
dlanorh
40 minutes ago, RubberDinero said:

This has been working perfectly!

is there a way to create or statements? look for "*SEWER*" or "*SWR*" or "*Sewr*"

I don't mind creating additional lines. I have already added additional lines for water and gas with different abbreviation, but I was just curious .

 

(if (or (wcmatch (strcase (vla-get-layer itm)) "*SEWER*")
        (wcmatch (strcase (vla-get-layer itm)) "*SWR*")
        (wcmatch (strcase (vla-get-layer itm)) "*SEWR*")
    );end_or
  (vla-put-layer itm "my-sewer-layer")
)

 

Share this post


Link to post
Share on other sites
Tharwat

@dlanorh you can use comma for the string pattern instead of the repetition of the same expression many times like this:

*SEWER*,*SWR*" and you can add as many as you want. 

 

 

 

 

 

 

  • Like 1

Share this post


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.   Paste as plain text instead

  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...