Class: Sketchup::Image

Inherits:
Drawingelement show all
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/Image.rb

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



39
40
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 39

def explode
end

#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



57
58
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 57

def glued_to
end

#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



86
87
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 86

def glued_to=(drawing_element)
end

#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



109
110
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 109

def height
end

#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

Parameters:

  • height

    The height, in inches, to set the image.

Returns:

  • height - the new height if successful

Version:

  • SketchUp 6.0



136
137
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 136

def height=(height)
end

#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



156
157
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 156

def image_rep
end

#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



178
179
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 178

def normal
end

#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



201
202
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 201

def origin
end

#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

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



228
229
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 228

def origin=(point)
end

#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



249
250
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 249

def path
end

#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



272
273
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 272

def pixelheight
end

#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



294
295
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 294

def pixelwidth
end

#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



323
324
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 323

def size=(width, height)
end

#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



350
351
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 350

def transform!(transform)
end

#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



369
370
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 369

def transformation
end

#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

Parameters:

  • transform

    The Transformation object to apply

Returns:

  • image - the newly transformed image

Version:

  • SketchUp 2014



392
393
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 392

def transformation=(transform)
end

#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



416
417
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 416

def width
end

#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

Parameters:

  • width

    The width, in inches, to set the image.

Returns:

  • width - the new width if successful

Version:

  • SketchUp 6.0



443
444
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 443

def width=(width)
end

#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



465
466
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Image.rb', line 465

def zrotation
end