[Code] material.delete
17 posts
• Page 1 of 1
[Code] material.deleteThis adds a new Method to Sketchup's Material Class - 'delete'
Usage: material.delete It changes any entities use that material to the default-material, and then removes that material from the model and the materials-browser. It has been streamlined as much as possible but will search potentially thousands of entities to remove that material... Edit: v1.1 has simplified defn changing and respond_to? material test - thanks to thomthom. v1.2 materials made into array to remove self. v1.3 empty temp groups used without detriment. v1.4 operation removed as it should be used with another one. Last edited by TIG on Wed Jun 24, 2009 10:28 am, edited 9 times in total.
TIG
Re: [Code] material.deleteIf read the code right, you iterate all the entities of each component instance and group?
A quicker way would be to just run over the entities in the model.definitions collection and then the model.entities. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.deleteIt has to deal with nested groups and instances etc... It processes every instance as each could have different materials, if it hasn't processed an instance's definition (i.e. it's not in @done) it does that too, otherwise it skips it... Not sure if the other way'd be quicker ?
TIG
Re: [Code] material.deleteYou don't need to dig into the nesting.
Simplified example:
This will strip the material of ALL entities that has a material property. Including the materials applied to ComponentInstances and Groups. No need to keep track of which definitions has already been processed. (of course, back_material will have to be accounted for. Other notes: won't your version choke if it runs into entities that doesn't have material property? And would it be quicker if the dummy geometry was a single edge instead of a face (four edges and a face)? Or even just empty dummy groups? Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.deleteJust to illustrate with some high-tech ASCII art:
If you have a model with a entity tree like this: (Excluding edges)
The you can see how you get all entities when you loop over model.entities. and model.definitions...entities:
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.deleteWhere does the face.copy method derive from? I can't find it in the API docs.
The self_to_nil method, is that embedded in .delete? Local to that method only? Never seen that method nesting before. Didn't even know it was possible. Feels very much like Javascript that way. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.delete
The 'face.copy' is simply 'group.copy' - the group was called 'face' !!! You can embed a def locally within another def - useful if you want to 'loop until' etc. Having taken on board your comments I have tweaked the method... here's the updated one viewtopic.php?p=166978#p166978 TIG
Re: [Code] material.delete
Ah. didn't see that. Thought it maybe wes undocumented.
That sure is. Will have to remember that. I think this method, and the layer version would fit well into the Skx library. Would you mind if this was included? I can add it to the repository for you if you don't want to bother with setting up Mercurial. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.deleteJust had a though. What happens if this method is called from another method that already has done a model.start_operation?
can operations be nested? Or will it interrupt the previous? Maybe one of the transparency flags (SU7 only) can be used? Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.deleteThat's a good point, Thom. I'm not sure start_operation belongs in specific methods.
I asked somewhere here if nesting start_operations was allowed, or what happens if they are nested. It's possible to write some "guards" for start_operation that prevent nesting - which may be interesting to do just to see what is really happening with all the scripts you have already installed. Hi
Re: [Code] material.deleteI'm wondering if trans or prev_trans flag can be used to inject these types of methods. But I don't fully understand the difference between the two. And I'm also unsure of the warning for trans apply to prev_trans.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.delete
Please add them for me... TIG
Re: [Code] material.deleteAs Jim says, perhaps best to remove the start/commit_operations unless 'we' can work out how best to 'transparencify' them... Advice welcome...
TIG
Re: [Code] material.deleteOk. I'll add it to the Skx. Thanks for sharing the snippet.
After this week I'll have some time to do some experiment with start operation. It'd be interesting if we could find a best practice. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Code] material.deleteUse v1.2: fixed an array bug.
viewtopic.php?p=166978#p166978 Last edited by TIG on Wed Jun 24, 2009 10:30 am, edited 1 time in total.
TIG
Re: [Code] material.deletev1.3 now uses empty temp groups without detriment and so must be a little quicker too ... viewtopic.php?p=166985#p166985
TIG
Re: [Code] material.deletev1.4 - now has operation properly removed ! ... viewtopic.php?p=166985#p166985
TIG
17 posts
• Page 1 of 1
|
Who is online
Users browsing this forum: No registered users and 14 guests