123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::Texture

Relationships
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Entity
Instance Chain:
self, Entity
Inherits: Sketchup::Entity

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 Attribute Summary

Entity - Inherited

#deleted?

The deleted? method is used to determine if your entity is still valid (not deleted by another script, for example.).

#valid?

The #valid? method is used to determine if your entity is still valid (not deleted by another script, for example).

Instance Method Summary

Entity - Inherited

#add_observer

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

#attribute_dictionaries

The attribute_dictionaries method is used to retrieve the AttributeDictionaries collection attached to the entity.

#attribute_dictionary

The attribute_dictionary method is used to retrieve an attribute dictionary with a given name that is attached to an Entity.

#delete_attribute

The #delete_attribute method is used to delete an attribute from an entity.

#entityID

The entityID method is used to retrieve a unique ID assigned to an entity.

#get_attribute

The #get_attribute method is used to retrieve the value of an attribute in the entity’s attribute dictionary.

#inspect

The #inspect method is used to retrieve the string representation of the entity.

#model

The model method is used to retrieve the model for the entity.

#parent

The parent method is used to retrieve the parent of the entity.

#persistent_id

The #persistent_id method is used to retrieve a unique persistent id assigned to an entity.

#remove_observer

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

#set_attribute

The set attribute is used to set the value of an attribute in an attribute dictionary with the given name.

#to_s

The #to_s method is used to retrieve the string representation of the entity.

#typename

The typename method retrieves the type of the entity, which will be a string such as “Face”, “Edge”, or “Group”.

Instance Attribute Details

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

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 (readonly)

The valid? method ensures that a texture is valid.

Examples:

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

Version:

  • SketchUp 6.0

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.

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

#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