123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::Image

Relationships
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Sketchup::Drawingelement

Overview

An Image object represents a raster image placed in the Model.

Examples:

Create material from image (SU 2018 and later)

model = Sketchup.active_model
entities = model.active_entities
image = entities.grep(Sketchup::Image).first
img_rep = image.image_rep
material = model.materials.add("New Name")
material.texture = img_rep

Version:

  • SketchUp 6.0

Instance Attribute Summary

Drawingelement - Inherited

#casts_shadows=

The casts_shadows= method is used to set the Drawingelement to cast shadows.

#casts_shadows?

The casts_shadows? method is used to determine if the Drawingelement is casting shadows.

#hidden=

The hidden= method is used to set the hidden status for an element.

#hidden?

The hidden? method is used to determine if the element is hidden.

#layer

The layer method is used to retrieve the Layer object of the drawing element.

#layer=

The layer= method is used to set the layer for the drawing element.

#material

The material method is used to retrieve the material for the drawing element.

#material=

The material= method is used to set the material for the drawing element.

#receives_shadows=

The receive_shadows= method is used to set the Drawingelement to receive shadows.

#receives_shadows?

The receive_shadows? method is used to determine if the Drawingelement is receiving shadows.

#visible=

The visible= method is used to set the visible status for an element.

#visible?

The visible? method is used to get the visible status for an element.

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

Drawingelement - Inherited

#bounds

The #bounds method is used to retrieve the ::Geom::BoundingBox bounding a Drawingelement.

#erase!

The #erase! method is used to erase an element from the model.

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

#glued_toSketchup::Face, ... (rw)

The #glued_to method is used to retrieve the entity that this image is glued to.

Examples:

point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
model = Sketchup.active_model
entities = model.active_entities
group = entities.add_group
group.entities.add_face([[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]])
status = group.glued_to

Version:

  • SketchUp 2021.1

#glued_to=(drawing_element) ⇒ Sketchup::Face, ... (rw)

The glued_to= method glues this image to a drawing element. When moving this other drawing elment with the Move tool, the image moves with it.

Examples:

model = Sketchup.active_model
entities = model.active_entities

# Create a face
face = entities.add_face([[0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0]])

# Create a group
path = "Plugins/su_dynamiccomponents/images"
image_file = Sketchup.find_support_file("report_tool.png", path)
image = model.active_entities.add_image(image_file, ORIGIN, 300)

# Glue the group to the face.
# If you now move the face, the group will follow.
image.glued_to = face

Parameters:

Returns:

Raises:

  • ArgumentError if this would lead to cyclic gluing.

Version:

  • SketchUp 2021.1

#heightObject (rw)

The height method is used to retrieve the height of the image.

The height is given in inches.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
height = image.height
if (height)
  UI.messagebox height
else
  UI.messagebox "Failure"
end

Returns:

  • height - the height of the model if successful

Version:

  • SketchUp 6.0

#height=(height) ⇒ Object (rw)

The height= method is used to set the height of the image.

The height is set in inches.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
UI.messagebox "Before adjustment"
height = image.height = 400
if (height)
  UI.messagebox height
else
  UI.messagebox "Failure"
end

Parameters:

  • height

    The height, in inches, to set the image.

Returns:

  • height - the new height if successful

Version:

  • SketchUp 6.0

#originObject (rw)

The origin method is used to retrieve the 3D point that defines the origin of the image.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
origin = image.origin
if (origin)
  UI.messagebox origin
else
  UI.messagebox "Failure"
end

Returns:

  • point - a Point3d object containing the origin location if successful

Version:

  • SketchUp 6.0

#origin=(point) ⇒ Object (rw)

The origin= method is used to set the 3D point as the origin of the image.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
pt2 = Geom::Point3d.new 100,100,100
entities = model.active_entities
image = entities.add_image path, pt, 300
UI.messagebox "Before Move"
origin = image.origin=pt2
if (origin)
  UI.messagebox origin
else
  UI.messagebox "Failure"
end

Parameters:

  • point

    A Point3d object with the new origin.

Returns:

  • point - the Point3d object representing the newly established origin if successful

Version:

  • SketchUp 6.0

#transformationObject (rw)

The transformation method is used to retrieve the transformation for the image.

Examples:

# Add an image to the model.
model = Sketchup.active_model
entities = model.active_entities
path = Sketchup.find_support_file('report_tool.png', 'Plugins/su_dynamiccomponents/images')
point = Geom::Point3d.new(100,100,100)
image = entities.add_image(path, point, 300)

trans = image.transformation

Returns:

  • transformation - a Transformation object if successful

Version:

  • SketchUp 2014

#transformation=(transform) ⇒ Object (rw)

The transformation= method is used to set the transformation for the image.

Examples:

# Add an image to the model.
model = Sketchup.active_model
entities = model.active_entities
path = Sketchup.find_support_file('report_tool.png', 'Plugins/su_dynamiccomponents/images')
point = Geom::Point3d.new(100,100,100)
image = entities.add_image(path, point, 300)

new_transform = Geom::Transformation.new([100,0,0])
image.transformation = new_transform

Parameters:

  • transform

    The Transformation object to apply

Returns:

  • image - the newly transformed image

Version:

  • SketchUp 2014

#widthObject (rw)

The width method is used to retrieve the width of the image.

The width is given in inches.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png",
  "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
width = image.width
if (width)
  UI.messagebox width
else
  UI.messagebox "Failure"
end

Returns:

  • width - the width of the image if successful

Version:

  • SketchUp 6.0

#width=(width) ⇒ Object (rw)

The width= method is used to set the width of the image.

The width is set in inches.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
UI.messagebox "Before adjustment"
width = image.width=400
if (width)
  UI.messagebox width
else
  UI.messagebox "Failure"
end

Parameters:

  • width

    The width, in inches, to set the image.

Returns:

  • width - the new width if successful

Version:

  • SketchUp 6.0

Instance Method Details

#explodeObject

The explode method is used to explode an image into a face with a texture on it.

Note that current versions of SketchUp will return an empty array here. To work around this limitation you can iterate over your entities collection to determine which new entities were created.

Versions prior to SketchUp 2015 returned an empty array due to a bug.

Examples:

model = Sketchup.active_model
path = "Plugins/su_dynamiccomponents/images"
image_file = Sketchup.find_support_file("report_tool.png", path)
image = model.active_entities.add_image(image_file, ORIGIN, 300)
entities = image.explode

Returns:

  • entitiesarray - an ::Array object of entities if successful

Version:

  • SketchUp 6.0

#image_repSketchup::ImageRep

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

Examples:

model = Sketchup.active_model
path = "Plugins/su_dynamiccomponents/images"
image_file = Sketchup.find_support_file("report_tool.png", path)
image = model.active_entities.add_image(image_file, ORIGIN, 300)
image_rep = image.image_rep

Raises:

  • ArgumentError if the Image is corrupt and lacks image data.

Version:

  • SketchUp 2018

#normalObject

The normal method is used to retrieve the 3D Vector that is perpendicular to the plane of the image.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
vector = image.normal
if (vector)
  UI.messagebox vector
else
  UI.messagebox "Failure"
end

Returns:

  • vector - a Vector3d object if successful

Version:

  • SketchUp 6.0

#pathObject

The path method is used to retrieve the path of the file defining the image.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
path = image.path
if (path)
  UI.messagebox path
else
  UI.messagebox "Failure"
end

Returns:

  • path - the path for the image file if successful

Version:

  • SketchUp 6.0

#pixelheightObject

The pixelheight method is used to retrieve the height of the image file in pixels.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
pixelheight = image.pixelheight
if (pixelheight)
  UI.messagebox pixelheight
else
  UI.messagebox "Failure"
end

Returns:

  • height - the height of the image in pixels if successful

Version:

  • SketchUp 6.0

#pixelwidthObject

The pixelwidth method is used to retrieve the width of the image file in pixels.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
pixelwidth = image.pixelwidth
if (pixelwidth)
  UI.messagebox pixelwidth
else
  UI.messagebox "Failure"
end

Returns:

  • width - the width of the image in pixels if successful

Version:

  • SketchUp 6.0

#size=(width, height) ⇒ Object

The size= method is used to set the width and height of the image, in inches.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
UI.messagebox "Before Resize"
size = image.size= 500,500
if (size)
  UI.messagebox size
else
  UI.messagebox "Failure"
end

Parameters:

  • width

    The width of the image.

  • height

    The height of the image.

Returns:

  • size - the new width and height of the image if successful

Version:

  • SketchUp 6.0

#transform!(transform) ⇒ Object

The transform! method is used to apply a transformation to the image.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
point = Geom::Point3d.new 100,100,100
t = Geom::Transformation.new point
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
UI.messagebox "Before Move"
image = image.transform! t
if (image)
  UI.messagebox image
else
  UI.messagebox "Failure"
end

Parameters:

  • transform

    A Transformation object.

Returns:

  • image - the transformed Image object if successful

Version:

  • SketchUp 6.0

#zrotationObject

The zrotation method is used to get the angle that the image is rotated about the normal vector from an arbitrary X axis.

Examples:

model = Sketchup.active_model
path = Sketchup.find_support_file "report_tool.png", "Tools/DynamicComponents/images"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
zrotation = image.zrotation
if (zrotation)
  UI.messagebox zrotation
else
  UI.messagebox "Failure"
end

Returns:

  • vector - a Vector3d object if successful

Version:

  • SketchUp 6.0