Material list

Hello!

I’m trying to create a plugin where users can define the dimensions and the material of a new component.
I used the following Ruby code to get the material list:

model = Sketchup.active_model
        materials = model.materials
        count = materials.count
        puts "Value of count is #{count}"
        szoveg = "<option selected>"+materials[0].display_name+"</option>"
        for i in 1..count-1
            puts materials[i].display_name
            szoveg = szoveg+"<option>"+materials[i].display_name+"</option>"
            thumbnail_file = File.dirname(__FILE__) +"/materials/#{materials[i].display_name}.png"
            materials[i].write_thumbnail(thumbnail_file, 280)
        end

It creates the png files, but the problem is that they are not the same as those in the software.
E.g. I can see these materials in SketchUp:
image

But in the list what I get using the previous code, I have only the 7 colors that are in the “In Model” list:
image

How should I modify the code to get all possible materials?

Thank you!

Your first image shows the collection for Brick, Cladding, and Siding, not the In Model collection! Materials are not “in model” until you paint something with them.

1 Like

Yes, but I would like to get a list of all possible materials, not just of those that are “in model”. Can I do that somehow?

I don’t see anything in the API that exposes other material collections or their contents (perhaps another developer knows of something…).

It’s already ‘invented’ - see here https://sketchucation.com/plugin/2365-material_browser

YES. I already posted the answers, … here: …

How to add all SU materials in our list? - #4 by DanRathbun

… and a few more methods later in that topic …

How to add all SU materials in our list? - #23 by DanRathbun

1 Like