Can't get material of a model

I am struggling with exporting the model: sofa.skp (1.4 MB)

I could not get its texture from traversing all entities. No material found at all. Then I exploded it and grouped it again. Its material was found when traversing all entities in its component definitions. Strange. What’s the difference between the 2 models.

The 2 models look same:
sofa-origin
(the original model)

sofa-explode-and-group-again
(the exploded and grouped model)

The model you posted have a material applied to the two groups.
To get the material of the groups you have to use: Drawingelement#material-instance_method

E.g. If you copy-paste this snippet of code into the Ruby Console

model = Sketchup.active_model
entities = model.active_entities
materials = entities.grep(Sketchup::Group){|g| g.material}

The result is:
[#<Sketchup::Material:0x0000017836ed8078>, #<Sketchup::Material:0x0000017836ed8078>]

If you explode the groups, the materials will be inherited to the children Drawingelemens (faces, edges) inside…

It looks like! But it’s not.
Now you have the material applied to each Drawingelements …
That could be the reason for bigger file size.

(Edit: the secondly uploaded model contains only one group, but my finding is similar.:wink: )

1 Like

Thank you so much! Yes, exactly. I thought only face and edge could have material. Now I understand that group and componentInstance are Drawingelement, can have material also. Thanks again.

Sort of…e.g.: Methods inherited
image

…further down

1 Like