class Materials

 

Parent: Entity

Class Index

Methods: [], add, at, count, each, length

 

Sample Code: materialstests.rb

 

 A collection of Materials objects.   
 

Instance Methods

 

[]

The [] method is used to retrieve a material by index or name.

Syntax:

material = materials[index]

material = materials "name"

Arguments:

index - a number representing the material's index in an array of Material objects

"name" - the name of the material

Return Value:

material - a Material object

Comments:

 

Example:

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 objec
m.texture="c:\\Program Files\\@Last Software\\SketchUp 4
\\Materials\\Carpet.jpg"
UI.messagebox $!.message
texture = m.texture
mat = materials[0]


 

add

The add method is used to add a material.

Syntax:

materials.add

material = materials.add "name"

Arguments:

"name" - the name of the added Material object

Return Value:

material - the newly added Material object

Comments:

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.

Example:

 


 

at

The at method is an alias for []. See [].

Syntax:

 

Arguments:

 

Return Value:

 

Comments:

 

Example:

 


 

count

The count method is an alias for length. See length.

Syntax:

 

Arguments:

 

Return Value:

 

Comments:

 

Example:

 


 

each

The each method is used to iterate through all of the materials.

Syntax:

materials.each {| material | ...}

Arguments:

material - a variable that will hold each Material object as they are found.

Return Value:

 

Comments:

 

Example:

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}        


 

length

The length method retrieves the number of materials.

Syntax:

length = materials.length

Arguments:

 

Return Value:

length - the number of entities in the collection of entities if successful

Comments:

 

Example:

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
length = materials.length