Class: Sketchup::Texture

Inherits:
Entity
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb

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



41
42
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 41

def average_color
end

#filenameString

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:

  • (String)

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

Version:

  • SketchUp 6.0



70
71
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 70

def filename
end

#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



82
83
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 82

def height
end

#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



100
101
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 100

def image_height
end

#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



116
117
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 116

def image_rep(colorized = false)
end

#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



134
135
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 134

def image_width
end

#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



172
173
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 172

def size=(size)
end

#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



188
189
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 188

def valid?
end

#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



200
201
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 200

def width
end

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

Parameters:

  • filename (String)

    String - The filename 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



222
223
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Texture.rb', line 222

def write(filename, colorize = false)
end