SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Image class

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

Parent: Drawingelement

Methods: explode, height, height=, normal, origin, origin=, path, pixelheight, pixelwidth, size=, transform!, width, width=, zrotation

Example Code: imagetests.rb

Instance Methods


explode

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

Syntax

entitiesarray = image.explode

Return Value

entitiesarray - an Array object of entities if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
entitiesarray = image.explode
if (entitiesarray)
UI.messagebox entitiesarray
else
UI.messagebox "Failure"
end

 

 


height 

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

Syntax

height = image.height

Return Value

height - the height of the model if successful

Comments

The height is given in inches.

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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

 

 


height= 

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

Syntax:

height = image.height = height

Arguments

height - the height, in inches. to set the image

Return Value

height - the new height if successful

Comments

The height is given in inches.

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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    

 

 


normal          

The normal method is used to retrieve the 3d vector that is perpendicular to the plane of the image.

Syntax

vector = image.normal 

Return Value

vector - a Vector3d object if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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          

 

 


origin      

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

Syntax

point = image.origin 

Return Value

point - a Point3d object containing the origin location if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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          

 

 


origin=      

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

Syntax

point = image.origin = point 

Arguments

point - a Point3d object with the new origin

Return Value

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

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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      

 

 


path                

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

Syntax

path = image.path 

Return Value

path - the path for the image file if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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      

 

 


pixelheight  

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

Syntax

height = image.pixelheight 

Return Value

height - the height of the image in pixels if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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  

 

 


pixelwidth                             

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

Syntax

width = image.pixelwidth 

Return Value

width - the width of the image in pixels if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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     

 

 


size=                                    

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

Syntax

size = image.size = width, height 

Arguments

width - the width of the image

height - the height of the image

Return Value

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

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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                 

 

 


transform!   

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

Syntax

image = image.transform! transformation

Arguments

transformation - a Transformation object

Return Value

image - the transformed Image object if successful

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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

 

 


width                                         

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

Syntax

width = image.width 

Return Value

width - the width of the image if successful

Comments

The width is given in inches.

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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    

 

 


width=           

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

Syntax

width = image.width = width 

Arguments

width - the width, in inches. to set the image

Return Value

width - the new width if successful

Comments

The width is given in inches.

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
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        

 

 


zrotation        

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

Syntax

rotation = image.zrotation 

Return Value

rotation - the angle that the image is rotated about he normal 3d vector (if successful)

Example

model = Sketchup.active_model
path = Sketchup.find_support_file "Shapes.jpg", "Plugins/"
pt = Geom::Point3d.new
entities = model.active_entities
image = entities.add_image path, pt, 300
z = image.zrotation
if (z)
UI.messagebox z
else
UI.messagebox "Failure"
end               

 

SketchUp  Ruby API Reference: Image

© Google Inc. 2007 sketchup.google.com