Texture

class Texture

Parent: Entity | Class Index
Methods:average_color, filename, height, image_height, image_width, size=, valid?, width |
Sample Code: texturetests.rb |

The Texture class contains methods for obtaining information about textures that are part of your materials in your model (within the In-Model section of the Materials Browser). Remember, textures are repeatable images that repeat when painted on a surface.

Instance Methods

average_color
The average_color method retrieves a color object with the average color found in the texture.
Syntax:
color = texture.average_color
Arguments:
Return Value:
color – a color object (if successful), nil if unsuccessful.
Comments:
Example:

model = Sketchup.active_model
materials=model.materials

# Adds a material to the “in-use” material browser tab
m = materials.add “Test Color”

begin
# Returns nil if not successful, path if successful
m.texture = “c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg”
rescue
UI.messagebox $!.message
end

texture = m.texture
# Returns a color object
color = texture.average_color

if (color)
UI.messagebox color
else
UI.messagebox “Failure: No average color”
end

filename
The filename method retrieves the entire path, including the file, for a texture object.
Syntax:
filename = texture.filename
Arguments:
Return Value:
filename – a string representation of the path and filename used for the texture.
Comments:
Example:

model = Sketchup.active_model
materials=model.materials

# Adds a material to the “in-use” material browser tab
m = materials.add “Test Color”

begin
# Returns nil if not successful, path if successful
m.texture = “c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg”
rescue
UI.messagebox $!.message
end

texture = m.texture
# Returns a color object
filename = texture.filename

if (filename)
UI.messagebox filename
else
UI.messagebox “Failure”
end

height
The height method is used to get the height of a repeatable texture image, in inches.
Syntax:
height = texture.height
Arguments:
Return Value:
height – the height, in inches, of the texture pattern
Comments:
Example:

model = Sketchup.active_model
materials=model.materials

# Adds a material to the “in-use” material browser tab
m = materials.add “Test Color”

begin
# Returns nil if not successful, path if successful
m.texture = “c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg”
rescue
UI.messagebox $!.message
end

texture = m.texture
# Returns a color object
height = texture.height

if (height)
UI.messagebox height
else
UI.messagebox “Failure”
end

image_height
The image_height method retrieves the height of the repeatable texture image, in pixels.
Syntax:
imageheight = texture.image_height
Arguments:
Return Value:
imageheight – the height, in pixels, of the texture pattern
Comments:
Example:

imageheight = texture.height

if (imageheight)
UI.messagebox imageheight
else
UI.messagebox “Failure”
end

image_width
The image_width method retrieves the width of the repeatable texture image, in pixels.
Syntax:
imagewidth = texture.image_width
Arguments:
Return Value:
imagewidth – the width, in pixels, of the texture pattern
Comments:
Example:

imagewidth = texture.width

if (imagewidth)
UI.messagebox imagewidth
else
UI.messagebox “Failure”
end

size=
The size= method allows you to set the size of the repeatable texture image, in inches
Syntax:
size = texture.size=size
Arguments:
size – the size, in inches, of the texture. This number will apply to height and width to keep aspect ratio.
Return Value:
size – the size, in inches, of the texture. This number will apply to height and width to keep aspect ratio.
Comments:
Example:

size = texture.size=60

if (size)
UI.messagebox size
else
UI.messagebox “Failure”
end

valid?
The valid? method ensures that a texture is valid.
Syntax:
status = texture.valid?
Arguments:
Return Value:
status – true if valid, false if invalid.
Comments:
Example:

status = texture.valid?

if (valid)
UI.messagebox valid
else
UI.messagebox valid
end

width
The width method is used to get the width of a repeatable texture image, in inches.
Syntax:
width = texture.width
Arguments:
Return Value:
width – the width, in inches, of the texture pattern
Comments:
Example:

model = Sketchup.active_model
materials=model.materials

# Adds a material to the “in-use” material browser tab
m = materials.add “Test Color”

begin
# Returns nil if not successful, path if successful\
m.texture = “c:\\Program Files\\@Last Software\\SketchUp 4\\Materials\\Carpet.jpg
rescue
UI.messagebox $!.message
end

texture = m.texture
# Returns a color object
width = texture.width

if (width)
UI.messagebox width
else
UI.messagebox “Failure”
end