[Plugin] MaterialConsolidator
-
First things last...
You cannot 'rename' materials via the Ruby API unless you have Sketchup >= v8M1 [OR my SKMtools installed] because
material.name=string
doesn't exist as a method otherwise. If the method is available then this one-liner will rename ALL materials in the model using CAPITAL letters - otherwise you'll get an error message!Sketchup.active_model.materials.each{|m|m.name=m.name.upcase}
The accuracy idea would apply to what exactly ? I expect Red, Green, Blue, Alpha
At the moment the code has several tests of equivalence like
next if mat.color.red != m0.color.red
You can edit the code [using a plain text editor like Notepad/Notepad++ etc] to apply an accuracy thus, where you'll define the accuracy as sayper=0.01
[i.e. we'll accept it as a match if it's within 1%]. You can either hardcode the 'per' or you could get this from an added dialog as the tool runs... [see below]
So now tweak the test[s]next if mat.color.red > m0.color.red*(1+per) or mat.color.red < m0.color.red*(1-per)
Repeat this for RGB and A...
To get the accuracy from a dialog add this at the start of the code on a new line immediately after '
initialize()
'results=inputbox(["0.NNN; "],[0.01],"Material Consolidator Accuracy") return nil unless results per=results[0]
you then enter the required accuracy in the format 0.01 =1%, 0.1 =10%, 0.5 =50% etc.
Obviously if you use the dialog to set the accuracy you do not need a line that saysper=...
elsewhere in the code!
If you cancel the dialog the material-consolidation is aborted.This accuracy dialog could act as your startup prompt... BUT if you don't implement it then add this line at the start of the code instead
return nil if UI.messagebox("Consolidate All Materials ?",MB_YESNO,"")==7
-
thank you for the plugin
-
Really a great plugin!
Thank you TIG! -
Came down in the best moment. I had a horrible mess in the materials of a collaborative model. its a blessing
-
Hey, TIG. How about adding some "fuzzy" logic to this? I mean, sometimes you have very similar materials that have only slightly different properties. For example, half a dozen of glasses with only slightly different tints, or slightly different alpha values, and it would be useful to consolidate them.
-
A mighty handy plugin. Thanks!
-
is there somebody out there who can compile the above mentioned "accuracy" code addon into the plugin and share it with us ?
would be awesome!!
thanks
-
Here's v2.0 which includes optional 'tolerances' for RGBA values.
So you can now consolidate colors which are almost a match !
Use it with thought...
But it is one-step undo-able !
https://sketchucation.com/pluginstore?pln=materialconsolidator
Please read the updated usage notes in the first post: http://sketchucation.com/forums/viewtopic.php?p=295290#p295290 -
Thanks TIG. This will be a very useful addition to an often-used plugin.
-
Thank you!
-
Sorry, for any inconvenience !
Here's v3.0
https://sketchucation.com/pluginstore?pln=materialconsolidator
It tweaks any options checking - to avoid unexpected results ! -
WOW super many muchas gracias
heavily appreciated!edit:
of course one is never satisfied for long ...plugin works as expected now, but its kind of slow on scenes with many many polygons and the report does not state the progress or if the plugin is still working or if the app is frozen and also there are some crucial options missing...
for example: work in only on entities in active context or vice versa, ignore entities and materials of active objects
dont know if anyone is aware of the age old plugin material maintance - this one is quite fast with what it does ..
maybe someone in the future can combine them and make a proper plugin, i personally would be happy to pay for something like that
-
Need help with installation or use of this plugin.
'materialconsolidator' shows in my extension manager although there is no version, author etc information.
It is not showing in the 'extensions' tabWhat do I need to do to get it to work?
-
@1010 gunner said:
What do I need to do to get it to work?
First thing I'd do is look in the Tools Menu where the instructions say it will be located. See the first post.
If it's not there, then we need to look at how you went about installing it.
What version of SketchUp are you using? Your profile indicates version 7 but it had no Extension Manager.
-
That's it, thank you.
-
Hey TIG, so I'm running your program on my 150MB file with many materials (~150) and components. It seems to 'freeze' on the "Making Nested Entities List." step. Takes up a lot of CPU processing power but not seeing any progress. I'm leaving it 'running' for a few hours to give it a chance to finish. If it's not frozen and working as intended, could I suggest making some form of a progress bar or status updates, maybe even a pause option. If it's not working as intended, well, consider yourself informed.
-
Returned to these error messages within Ruby Console (I'm using Sketchup Pro 2019)
Material Consolidator: Tolerances: R=15 G=15 B=15 A=0
Material Consolidator: Making Material Lists
Material Consolidator: Making Entities List
Material Consolidator: Making Nested Entities List
Material Consolidator: Consolidating Materials
Error: #<NoMethodError: undefined methoddisplay_name' for nil:NilClass> C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:202:in
block (3 levels) in new'
C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:195:ineach' C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:195:in
block (2 levels) in new'
C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:191:ineach' C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:191:in
block in new'
C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:189:ineach' C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:189:in
new'
C:/Users/###/AppData/Roaming/SketchUp/SketchUp 2019/SketchUp/Plugins/materialconsolidator.rb:71:in `block in module:MaterialConsolidator' -
I see the issue and will issue an update shortly...
-
Here's v4.0
https://sketchucation.com/pluginstore?pln=materialconsolidator
It should fix the display_name error for nil-materials... -
Is it possible to get some kind of progress bar with this plugin? I usually use it toward the end of a project, where I have imported a bunch of components and have a lot of materials. I ran this yesterday and I wasn't sure if SketchUp had crashed or it was still working. I let it sit overnight and it was just working away. It would be nice to know how far it has to go. Thomthoms Cleanup does a great job of doing this.
Advertisement