SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Texture class

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.

Parent: Entity 

Methods: average_color, filename, height, image_height, image_width, size=, valid?, width

Example Code: texturetests.rb

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

Return Value

color – a color object (if successful), nil if unsuccessful.

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

Return Value

filename – a string representation of the path and filename used for the texture.

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

Return Value

height – the height, in inches, of the texture pattern

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

Return Value

imageheight – the height, in pixels, of the texture pattern

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

Return Value

imagewidth – the width, in pixels, of the texture pattern

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.

Example

size = texture.size=60
if (imagewidth)

UI.messagebox imagewidth

else

UI.messagebox “Failure”

end

 

 


valid? 

The valid? method ensures that a texture is valid.

Syntax

status = texture.valid?

Return Value

status – true if valid, false if invalid.

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

Return Value

width – the width, in inches, of the texture pattern

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

 

SketchUp  Ruby API Reference: Texture

© Google Inc. 2007 sketchup.google.com