Jump to content

Change Nested and Unested object layer


RubberDinero

Recommended Posts

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!

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"))

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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")
)

 

Link to comment
Share on other sites

@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
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...