The Material class represents a texture or color that can be applied to
Drawingelements. It is most often applied to Faces.
You can pass any object that can be used as a material to a method that
requires a material. Objects include actual materials, color, and classes
that can be converted to a color.
The following are valid (assuming the existence of a Material mat1.)
face.material = mat1
face.material = "red"
face.material = 0xff0000The <=> method is used to compare two materials based on name. The number returned relates to the "string distance" between the names.
Arguments:
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" status = m <=> m2 # Yields a 1 if (status) UI.messagebox status else UI.messagebox "Failure" end # Yields a -1 status = m2 <=> m if (status) UI.messagebox status else UI.messagebox "Failure" end
The == method is used to test if two materials are the same.
Arguments:
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" status = m == m2 # Yields a False if (status) UI.messagebox status else UI.messagebox "The Materials are not Equal" end
The alpha method is used to get the opacity of the material.
The value will be between 0 and 1. A value of 0 means that the material is
completely transparent. A value of 1 means that the Material is completely
opaque.
Returns:
alpha_value = Sketchup.active_model.materials[0].alpha
The alpha= method is used to set the opacity of the material.
The value must be between 0 and 1. A value of 0 means that the material is
completely transparent. A value of 1 means that the Material is completely
opaque.
Arguments:
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" alpha = m.alpha=0 if (alpha) UI.messagebox alpha else UI.messagebox "Failure" end
The color method is used to retrieve the color of the material.
If it uses a Texture, this will return the average color.
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" color = m.color if (color) UI.messagebox color else UI.messagebox "Failure" end
The color= method is used to set the color of the material.
If the Material has a Texture, then this turns it into a colorized
Texture.
To reset the color of a Material with a Texture, set the color
to nil.
Arguments:
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" color = m.color ="Blue" if (color) UI.messagebox color else UI.messagebox "Failure" end
The display_name method retrieves the name that is displayed within SketchUp
for the material.
This should be used in most cases rather than using the name method.
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" name = m.display_name if (name) UI.messagebox name else UI.messagebox "Failure" end
The materialType method retrieves the type of the material. Types include:
Returns:
material = Sketchup.active_model.materials[0] type = material.materialType
The name method retrieves the name of the material.
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" name = m.name if (name) UI.messagebox name else UI.messagebox "Failure" end
The texture method retrieves the texture of the material.
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" texture = m.texture if (texture) UI.messagebox texture else UI.messagebox "Failure" end
The texture= method sets the texture for the material.
Setting the Texture to nil will turn it into a solid color
Arguments:
Returns:
model = Sketchup.active_model materials = model.materials # Adds a material to the "in-use" material pallet. m = materials.add "Joe" m2 = materials.add "Fred" # Returns nil if not successful, path if successful. # Should return a texture object. m.texture = "c:\\Materials\\Carpet.jpg" m2.texture = "c:\\Materials\\BlueTile.jpg" texture = m.texture = "c:\\Materials\\BlueTile.jpg" if (texture) UI.messagebox texture else UI.messagebox "Failure" end
The use_alpha? method tells if the material uses transparency.
Returns:
material = Sketchup.active_model.materials[0] is_alpha = material.use_alpha?