Class: Sketchup::Texture

Inherits:
Entity
  • Object
show all

Overview

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 “tile” when painted on a surface.

Version:

  • SketchUp 6.0

Instance Method Summary # collapse

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #parent, #persistent_id, #remove_observer, #set_attribute, #to_s, #typename

Instance Method Details

#average_colorObject

The average_color method retrieves a color object with the average color found in the texture.

Examples:

model = Sketchup.active_model
materials=model.materials
# Adds a material as an in model material
m = materials.add "Test Color"
begin
  # Returns nil if not successful, path if successful
  m.texture = "c:\\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

Returns:

  • color - a color object (if successful), nil if unsuccessful.

Version:

  • SketchUp 6.0

#filenameObject

The filename method retrieves the entire path, including the file, for a texture object.

Examples:

model = Sketchup.active_model
materials=model.materials
# Adds a material as an in model material
m = materials.add "Test Color"
begin
  # Returns nil if not successful, path if successful
  m.texture = "c:\\Materials\\Carpet.jpg"
rescue
  UI.messagebox $!.message
end
texture = m.texture
filename = texture.filename
if (filename)
  UI.messagebox filename
else
  UI.messagebox "Failure"
end

Returns:

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

Version:

  • SketchUp 6.0

#heightObject

The height method is used to get the height of a repeatable texture image, in inches.

Examples:

height = texture.height

Returns:

  • height - the height, in inches, of the texture pattern

Version:

  • SketchUp 6.0

#image_heightObject

The image_height method retrieves the height of the repeatable texture image, in pixels.

Examples:

imageheight = texture.image_height
if (imageheight)
  UI.messagebox imageheight
else
  UI.messagebox "Failure"
end

Returns:

  • imageheight - the height, in pixels, of the texture pattern

Version:

  • SketchUp 6.0

#image_widthObject

The image_width method retrieves the width of the repeatable texture image, in pixels.

Examples:

imagewidth = texture.image_width
if (imagewidth)
  UI.messagebox imagewidth
else
  UI.messagebox "Failure"
end

Returns:

  • imagewidth - the width, in pixels, of the texture pattern

Version:

  • SketchUp 6.0

#size=(size) ⇒ Object

The size= method allows you to set the size of the repeatable texture image, in inches,

Examples:

size = texture.size = 60
imagewidth = texture.width

if (imagewidth)
  UI.messagebox imagewidth
else
  UI.messagebox "Failure"
end

# Using two values which will not preserve ratio
width_height = texture.size = [10,100]
if (width_height)
  UI.messagebox width_height
else
  UI.messagebox "Failure"
end

Returns size - the size, in inches, of the texture. This number will apply to height and width to keep aspect ratio. If you have passed in an array of two numbers for width and height, the same array will be returned if successful.

Parameters:

  • size

    The size, in inches, of the texture. This number will apply to height and width to keep aspect ratio. You can also pass as a parameter an array of two numeric values which will set width and height regardless of maintaining the height/width ratio.

Returns:

  • size - the size, in inches, of the texture. This number will apply to height and width to keep aspect ratio. If you have passed in an array of two numbers for width and height, the same array will be returned if successful.

Version:

  • SketchUp 6.0

#valid?Object

The valid? method ensures that a texture is valid.

Examples:

status = texture.valid?
if (status)
  UI.messagebox status
else
  UI.messagebox status
end

Returns:

  • status - true if valid, false if invalid.

  • (Boolean)

Version:

  • SketchUp 6.0

#widthObject

The width method is used to get the width of a repeatable texture image, in inches.

Examples:

width = texture.width

Returns:

  • width - the width, in inches, of the texture pattern

Version:

  • SketchUp 6.0

#write(filename, colorize = false) ⇒ Object

Writes the texture to file with option to preserve the color adjustments made by the material.

Examples:

material = Sketchup.active_model.materials[0]
basename = File.basename(material.texture.filename)
filename = File.join(Sketchup.temp_dir, basename)
material.texture.write(filename)

Returns Boolean - true if the method succeeded

Parameters:

  • filename

    String - The filename to write the texture to.

  • colorize (defaults to: false)

    Boolean - Allows for the texture to be exported with the color adjustments.

Returns:

  • Boolean - true if the method succeeded

Version:

  • SketchUp 2016