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_colorSketchup::Color?

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:

  • (Sketchup::Color, nil)

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

Version:

  • SketchUp 6.0

#filenameString

Note:

Since SketchUp 2021.0 this method will append a file extension matching the image format if the file extension is missing from stored filepath.

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

Examples:

model = Sketchup.active_model
materials = model.materials
material = materials.add("Test Color")
material.texture = "c:\\Materials\\Carpet.jpg"
texture = material.texture
filename = texture.filename

Returns:

  • (String)

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

Version:

  • SketchUp 6.0

#heightInteger

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

Examples:

height = texture.height

Returns:

  • (Integer)

    the height, in inches, of the texture pattern

Version:

  • SketchUp 6.0

#image_heightInteger

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:

  • (Integer)

    the height, in pixels, of the texture pattern

Version:

  • SketchUp 6.0

#image_rep(colorized = false) ⇒ Sketchup::ImageRep

The #image_rep method returns a copy of a ImageRep object representing the texture pixel data.

Examples:

texture = Sketchup.active_model.materials[0].texture
image_rep = texture.image_rep

Parameters:

  • colorized (Boolean) (defaults to: false)

    Set to true to obtain the colorized version.

Returns:

Version:

  • SketchUp 2018

#image_widthInteger

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:

  • (Integer)

    the width, in pixels, of the texture pattern

Version:

  • SketchUp 6.0

#size=(size) ⇒ Integer, Array(Integer, Integer)

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

Parameters:

  • size (Integer, Array(Integer, Integer))

    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:

  • (Integer, Array(Integer, Integer))

    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?Boolean

The valid? method ensures that a texture is valid.

Examples:

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

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#widthInteger

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

Examples:

width = texture.width

Returns:

  • (Integer)

    the width, in inches, of the texture pattern

Version:

  • SketchUp 6.0

#write(path, colorize = false) ⇒ Boolean

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)
path = File.join(Sketchup.temp_dir, basename)
material.texture.write(path)

Parameters:

  • path (String)

    The file path to write the texture to.

  • colorize (Boolean) (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