Class: Sketchup::Image

Inherits:
Drawingelement show all

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 Method Summary # collapse

Methods inherited from Drawingelement

#bounds, #casts_shadows=, #casts_shadows?, #erase!, #hidden=, #hidden?, #layer, #layer=, #material, #material=, #receives_shadows=, #receives_shadows?, #visible=, #visible?

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, #valid?

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

#glued_toSketchup::Face, ...

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

Returns:

Version:

  • SketchUp 2021.1

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

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

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

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

Returns height - the new height if successful.

Parameters:

  • height

    The height, in inches, to set the image.

Returns:

  • height - the new height if successful

Version:

  • SketchUp 6.0

#image_repSketchup::ImageRep

The #image_rep method returns a copy of a Sketchup::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

Returns:

Raises:

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

Version:

  • SketchUp 2018

Known Bugs:

  • Prior to SketchUp 2021.1, SketchUp crashes when the Image is corrupt and lacks image data.

#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

#originObject

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

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

Returns point - the Point3d object representing the newly established origin if successful.

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

#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

Returns size - the new width and height of the image if successful.

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

Returns image - the transformed Image object if successful.

Parameters:

  • transform

    A Transformation object.

Returns:

  • image - the transformed Image object if successful

Version:

  • SketchUp 6.0

#transformationObject

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

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

Returns image - the newly transformed image.

Parameters:

  • transform

    The Transformation object to apply

Returns:

  • image - the newly transformed image

Version:

  • SketchUp 2014

#widthObject

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

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

Returns width - the new width if successful.

Parameters:

  • width

    The width, in inches, to set the image.

Returns:

  • width - the new width 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