How to remove attributes from materials?

This model has never had collections. The preferences materials folder is empty. As far as I can tell, everything in the model is inside the skp file.

You misunderstand.
A model never has a ‘collection’.
A model has some materials loaded into it.
A ‘collection’ is a set of external material [SKM] files that is shared across all of your models.
You can save a material or all of your model’s materials into a ‘collection’ folder.
If that ‘collection’ folder is included in the list of possible materials that are available to your models, then you can see its contents in the materials-browser…
Some materials are shipped with SketchUp - these are not ‘in’ the model, but are available to it.
Similarly your own collections of materials can be shared across models…

I didn’t make the model, my materials folder is empty, not sure if their folder is empty.

If I save a new material, it does appear in my materials folder.

You can use Aerilus’ Attribute Inspector to easily see and edit any attributes.

When it comes to external material libraries they shouldn’t matter. They are just files on a disk, not objects SketchUp should have to worry about (except when browsing them in the Material browser). The in model material collection is more likely to be relevant here.

Here’s a very simple snippet to list the materials that have attributes so you don’t need to manually go through them all:

puts Sketchup.active_model.materials.select(&:attribute_dictionaries).map(&:name)

I had [perhaps incorrectly] assumed that you had a collection of materials and you wished to remove their attributes.
If you simply want to remove all attributes from all of a model’s materials, then use something like this in the Ruby Console…

puts;puts
mod=Sketchup.active_model
mod.start_operation("del_adicts", true)
c=0
t=0
mod.materials.each{|m|
  c+=1
  if ds=m.attribute_dictionaries
    ns=[]
    ds.each{|d| ns << d.name }
    ns.each{|n| ds.delete(n) }
    puts "#{m.name} - deleted adicts #{ns}" if ns[0]
    t+=1 if ns[0]
  end
}
puts "Processed #{t} / #{c} Materials\n"
mod.commit_operation

It prints any changed materials’ names and the dictionaries it has deleted.
It also reports the number of materials processed out of the total.
It’s one step undo-able.
Note how I’ve collected the dictionaries’ names, and then removed them from the dictionaries ‘by-name’, because without testing this I’m not sure that iterating the dictionaries directly while deleting a dictionary will affect the processing - in the same way that you can’t iterate a selection directly and delete some of those selected items, because the selection then changes as you process it, causing some selected entities to get missed out !
Although the materials attribute_dictionaries are ‘emptied’ by the processing, they still exist afterwards, so that’s why I trap for an empty array on names as it iterates.

that’s an extreme number of ‘materials’ for any SU model…

are these all unique ‘materials’ [colors or textures] applied selectivley to the 10,000 faces or are they only unique due to having different attributes…

when writing ‘color’ import scripts, I found any more than 400 ‘colours in model’ had serious performance effects on a mac…

closing the ‘Colors’ panel helps, but reducing the count was far more beneficial…

if some colors aren’t being used, why not simply purge them completely?

john

Obviously you can use the Model Info > Statistics to slim down your model - including unused materials.
Or use my PurgeAll tool - which allows you to remove selected types of unused things rather than absolutely everything that’s unused…
https://sketchucation.com/pluginstore?pln=PurgeAll
But remember that unused layers and materials might be found only inside unused components etc, so unless you purge those unused components their unused layers/materials will remain in the model.

If you still have so many materials, then perhaps many of them are duplicates.
You can use a tool like my https://sketchucation.com/pluginstore?pln=materialconsolidator
to consolidate the model’s materials down to a minimum set, if they use the same color/alpha/texture etc…

I’m thinking the question may have been about unused attributes, not unused materials.

However you can’t see if an attribute is being used. If an extension writes it in the first place that extension probably expects to be able to use it later, so unless you are okay with making a model incompatible with the extension that created it, I wouldn’t recommend changing that extension’s attributes.

I think the OP got the SketchUp model from someone else, and so the renderers’ attributes attached to its materials are, in this case superfluous.
There also seems to be an inordinate number of materials in the model - hence the suggestions to purge the materials down to the ‘used’ set and then ‘consolidate’ them further.
Then he can remove the remaining materials’ attributes - if that’s still an issue…
Initially the OP did not give us all of the relevant information that we needed, so there have been several abortive forays into barren ground…

Thanks for the latest suggestions!

John, I mentioned that the goal isn’t to fix this model, but to track down exactly what it is in the model that upsets SketchUp on Mac. So that SketchUp can be fixed.

e3, your script is useful, but it still shows over 4500 materials that have attributes after running TIGs script that deletes them.

About the number of materials, I believe that some extensions use materials as a way to interpret objects. For example, Sefaira seems to rely on the material to know whether you’re dealing with a internal wall, external wall, etc. Anything that has transparency is treated as glass.

With PlusSpecs it’s looking like it uses a small PNG, and from the materials it then knows what it is exporting. Or something like that. But, it seems not to reuse materials, every time you make something you get another unique copy of the material, and if you delete that geometry the material is still listed in colors in model.

So, the problem may end up not being that there are 4600 materials with attributes, but because there are 4600 unique PNGs that are each 64x64 pixels. If Mac preloads material bitmaps and Windows doesn’t, that could explain the difference in the time to open the file.

Have you tried the following steps?

  1. Purge unused [everything] in Model Info > Statistics.
  2. Consolidate all model.materials [using my plugin].
  3. Then finally, delete all remaining materials’ attribute_dictionaries - using the copy/paste of my code…

Note that if a material has attribute_dictionaries defined, then even when you have deleted all of them, that material still has ‘attributes_dictionaries’ attached to it - although it is 'empty - whereas materials that have never been assigned any attribute_dictionary will of course report that they have no attribute_dictionaries…

I marked your other answer as being correct, because it exactly answers what I first asked.

Maybe I should start a new topic, just about what it is wrong with the model. I mentioned in my first post that purging materials solves the slow opening problem, but I also said a couple of times that my goal is to track down exactly what it is that is upsetting SketchUp. If I do a purge, this particular model is fixed, and I can no longer track down what it was that caused the problem.

The model in question is someone else’s, and is confidential. But, I have a version where I deleted all geometry (I added a rectangle so you can see when the model has opened). Components in model has a few dozen components. I haven’t figured out how to delete those without deleting the materials. The original model did have quite a few scenes, so I deleted those too.

This file shows the slow opening problem, and also another issue where when you have the model open, and you’re just looking at it, Mac OS goes into a locked up mode with SketchUp, long periods of spinning cursor. Which is the main original issue I’m working on, the slow opening was just an easy to reproduce variation of the problem.

Here is the file if you have a Mac and are intrigued.

noscenesnogeometryslowopen.skp.zip (1.2 MB)

1 Like

There is a huge number of nearly identical materials. Do you know if they are created by PlusSpec? I don’t use it so I can’t see how it works.

it seems to me that there is an issue in PlusSpec that makes it create duplicated materials instead of fetching an existing one, as the only difference between most of them appears to be the counter.

I extracted a list of the material names to show how similar they are, but it was about 5 times as long as the forum engine allowed to be posted. I wouldn’t expect SketchUp to handle such a long material list and find such list rather unreasonable. Although I wouldn’t mind if SketchUp could handle it, I think this is first and foremost something for the plugin author to fix.

Yes, most likely PlusSpecs could stop the problem from occurring. The part I’m investigating is why it opens instantly on my Mac if I run SketchUp in a Windows 10 emulator, but completely locks up my Mac if I open it in Mac OS. There is something in Mac OS SketchUp that isn’t coping with such models, that’s the thing I’m interested in.

My MaterialConsolidator: 4598 Materials Purged
Leaving 11 unique materials !

So it is fixable - by PlusSpec et al…

Ruby is implemented differently on the two platforms…

it opens in SU Viewer instantly on my mac, but not in Pro, so it’s a SU Ruby issue,

os x does have a cap for bulk operations from sub-procceses and throttles back when this is exceeded…

it appears to ‘kick in’ when reading the excessive number of attributes some extensions add or when using ruby to create ‘to much’ geometry in a bulk operation…

it’s obviously not an issue on windows as bulk operations are actively encouraged by the many of the extensibility team [who use windows]…

I did stumble on a mac dev article about this in the past, but have never managed to re-find it…

john

I’ve been looking for ways around this for years, but as most the extension devs run windows there has never even been an acknowledgement that it is an issue…

1 Like

Thanks for the tip about Viewer opening the file ok.

The Material Consolidator was a good test to do, it gave me a way to purge materials without purging components. Once I had done that the file is fine on Mac, even though the components are still around. Is there a way to remove unused components without removing any materials? That would be to test whether the materials are only processed because they are in use by components, that are not currently in the model.

A side clue, perhaps, if on Windows I look at colors in model, with that set to list view, it does lock up Windows for a few minutes.