|
SketchUp Ruby API Reference |
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
The explode method is used to explode an image into a face with a texture.
entitiesarray = image.explode
entitiesarray - an Array object of entities if successful
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
The height method is used to retrieve the height of the image.
height = image.height
height - the height of the model if successful
The height is given in inches.
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
The height= method is used to set the height of the image.
height = image.height = height
height - the height, in inches. to set the image
height - the new height if successful
The height is given in inches.
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
The normal method is used to retrieve the 3d vector that is perpendicular to the plane of the image.
vector = image.normal
vector - a Vector3d object if successful
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
The origin method is used to retrieve the 3d point that defines the origin of the image.
point = image.origin
point - a Point3d object containing the origin location if successful
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
The origin= method is used to set the 3d point as the origin of the image.
point = image.origin = point
point - a Point3d object with the new origin
point - the Point3d object representing the newly established origin if successful
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
The path method is used to retrieve the path of the file defining the image.
path = image.path
path - the path for the image file if successful
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
The pixelheight method is used to retrieve the height of the image file in pixels.
height = image.pixelheight
height - the height of the image in pixels if successful
model = Sketchup.active_modelpath = Sketchup.find_support_file "Shapes.jpg", "Plugins/"pt = Geom::Point3d.newentities = model.active_entitiesimage = entities.add_image path, pt, 300pixelheight = image.pixelheightif (pixelheight)UI.messagebox pixelheightelseUI.messagebox "Failure"end
The pixelwidth method is used to retrieve the width of the image file in pixels.
width = image.pixelwidth
width - the width of the image in pixels if successful
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
The size= method is used to set the width and height of the image.
size = image.size = width, height
width - the width of the image
height - the height of the image
size - the new width and height of the image if successful
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
The transform! method is used to apply a transformation to the image.
image = image.transform! transformation
transformation - a Transformation object
image - the transformed Image object if successful
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
The width method is used to retrieve the width of the image.
width = image.width
width - the width of the image if successful
The width is given in inches.
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
The width= method is used to set the width of the image.
width = image.width = width
width - the width, in inches. to set the image
width - the new width if successful
The width is given in inches.
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
The zrotation method is used to retrieve the angle that the image is rotated about the normal 3d vector from an arbitrary X axis.
rotation = image.zrotation
rotation - the angle that the image is rotated about he normal 3d vector (if successful)
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