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=material
Where the given
material
is 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.materials
before 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...
Advertisement