SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Materials class

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

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

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
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.

 

 


add_observer

The add_observer method is used to add an observer to the current object.

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


at

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


count 

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


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.

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}  

 

 


current  

The current method is used to get the current material.

Syntax

material = materials.current

Return Value

material - a Material object

Example

 

 


current=  

The current= method is used to set the current material.

Syntax

status = materials.current= material

Arguments

material - a Material object.

Return Value

true if successful, false if unsuccessful.

Example

 

 


length      

The length method retrieves the number of materials.

Syntax

length = materials.length 

Return Value

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

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

 

 


purge_unused 

The purge_unused method is used to remove unused materials.

Syntax

status = materials.purge_unused

Return Value

status - true if successful, false if unsuccessful.

Example

 

 


remove_observer

The remove_observer method is used to remove an observer from the current object.

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

SketchUp  Ruby API Reference: Materials

© Google Inc. 2007 sketchup.google.com