RubberDinero Posted March 13, 2019 Share Posted March 13, 2019 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! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 13, 2019 Share Posted March 13, 2019 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) Quote Link to comment Share on other sites More sharing options...
RubberDinero Posted March 13, 2019 Author Share Posted March 13, 2019 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 13, 2019 Share Posted March 13, 2019 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")) Quote Link to comment Share on other sites More sharing options...
RubberDinero Posted March 13, 2019 Author Share Posted March 13, 2019 (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 March 13, 2019 by RubberDinero Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 13, 2019 Share Posted March 13, 2019 No worries, just replace what I have described in my last reply then try again. Quote Link to comment Share on other sites More sharing options...
RubberDinero Posted March 13, 2019 Author Share Posted March 13, 2019 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? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 13, 2019 Share Posted March 13, 2019 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")) Quote Link to comment Share on other sites More sharing options...
RubberDinero Posted March 13, 2019 Author Share Posted March 13, 2019 Nice! Thanks! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 13, 2019 Share Posted March 13, 2019 You're welcome anytime. Quote Link to comment Share on other sites More sharing options...
RubberDinero Posted March 16, 2019 Author Share Posted March 16, 2019 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 . Quote Link to comment Share on other sites More sharing options...
dlanorh Posted March 16, 2019 Share Posted March 16, 2019 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") ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 17, 2019 Share Posted March 17, 2019 @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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.