|
SketchUp Ruby API Reference |
A collection of Materials objects.
Parent:Entity
Methods: [], add, add_observer, at, count, current, current =, each, length, purge_unused, remove_observer
Example Code: materialstests.rb
The [] method is used to retrieve a material by index or name.
material = materials[index]
material = materials "name"
index - a number representing the material's index in an array of Material objects
"name" - the name of the material
material - a Material object
model = Sketchup.active_model
materials = model.materials
# Adds a material to the "in-use" material pallet.
m = materials.add "Joe"
# Returns nil if not successful, path if successful. Should return a texture object
m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg"
UI.messagebox $!.message
texture = m.texture
mat = materials[0]
The add method is used to add a material.
materials.add
material = materials.add "name"
"name" - the name of the added Material object
material - the newly added Material object
When called with no arguments, this will generate a new unique name for the new Material. If a name is given, it will check to see if there is already a material with that name. If there is already a material with the given name, then a new unique name is gnerated using the given name as a base.
The add_observer method is used to add an observer to the current object.
status = object.add_observer observer
observer - an observer
true if successful, false if unsuccessful.
The at method is an alias for []. See [].
The count method is an alias for length. See length.
The each method is used to iterate through all of the materials.
materials.each {| material | ...}
material - a variable that will hold each Material object as they are found.
model = Sketchup.active_model
materials = model.materials
# Adds a material to the "in-use" material pallet.
m = materials.add "Joe"
# Returns nil if not successful, path if successful. Should return a texture object
m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg"
UI.messagebox $!.message
texture = m.texture
materials.each {| material | UI.messagebox material}
The current method is used to get the current material.
material = materials.current
material - a Material object
The current= method is used to set the current material.
status = materials.current= material
material - a Material object.
true if successful, false if unsuccessful.
The length method retrieves the number of materials.
length = materials.length
length - the number of entities in the collection of entities if successful
model = Sketchup.active_model
materials = model.materials
# Adds a material to the "in-use" material pallet.
m = materials.add "Joe"
# Returns nil if not successful, path if successful. Should return a texture object
m.texture="c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg"
UI.messagebox $!.message
texture = m.texturelength = materials.length
The purge_unused method is used to remove unused materials.
status = materials.purge_unused
status - true if successful, false if unsuccessful.
The remove_observer method is used to remove an observer from the current object.
status = object.remove_observer observer
observer - an observer
true if successful, false if unsuccessful.