Applying Material or Color to Group
-
How does one apply a color or material to a group? I can't seem to find a simple explanation or example in the SketchUp API documentation.
-
a group is a drawing element so look at
Drawingelement.material=
in the API
john
-
group.material=materialWhere the given
materialis a reference to a material already available in the model, or perhaps it's the name of an existing material, or the name of one of the standard 'color' - that might be not yet loaded:
So e.g.
material=Sketchup.active_model.materials['truss_wood']Where material returns 'nil' if it's not found, or a reference to that named material otherwise.
Or alternatively:
material='truss_wood'
which will work if you know that the material named 'truss_wood' is already in the model,
or perhaps...
material='brown'
Which uses the material named 'brown', or it makes the new material then uses it otherwise.
There is a preset list of 'colors' [à la html]:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/color
If you want a material with another color or transparent, or a texture, then you must add it to themodel.materialsbefore referencing it.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/materials#add
You then create a new color and apply it to that new material, which by default would be black with no transparency [0,0,0,0]
http://www.sketchup.com/intl/en/developer/docs/ourdoc/material#color=
If you also want to add a texture to the material, use http://www.sketchup.com/intl/en/developer/docs/ourdoc/material#texture=
Which specifies the image file to use, then you can edit the texture's details with texture=material.textureUsing:http://www.sketchup.com/intl/en/developer/docs/ourdoc/texture#size=
etc...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement