View

class View

Parent: Object | Class Index
Methods: animation=, average_refresh_time, camera , camera=, center, corner, draw, draw2d, draw_line, draw_lines, draw_points, draw_polyline, draw_text, drawing_color=, dynamic=, enable_autopan=, guess_target, inference_locked?, inputpoint, invalidate, last_refresh_time, line_stipple=, line_width=, lock_inference, model, pick_helper, pickray, pixels_to_model, set_color_from_line, show_frame, tooltip=, vpheight, vpwidth, write_image, zoom, zoom_extents |
Sample Code: viewtests.rb, viewtooltests.rb, animation.rb |

This class contains methods to manipulate the current point of view of the model. Many of these methods are meant to be invoked within a tool instead drawing separate from a tool (such as with the entities.add_edges method).

Instance Methods

animation=
The animation= method is used to set an animation that is displayed for a view. See Animation for details on how to create an animation object.
Syntax:
animation = view.animation = animation
Arguments:
animation - an Animation object
Return Value:
animation - the newly set Animation object
Comments:
Example:

animation = ViewSpinner.new
model = Sketchup.active_model
view = model.active_view
anim = view.animation=animation
if (anim)
UI.messagebox anim
else
UI.messagebox "Failure"
end

average_refresh_time
The average_refresh_time is used to set the average time used to refresh the current model in the view. This can be used to estimate the frame rate for an animation.
Syntax:
time = view.average_refresh_time
Arguments:
Return Value:
time - the time in milliseconds
Comments:
Example:
model = Sketchup.active_model view = model.active_view time = view.average_refresh_time

camera
The camera method is used to retrieve the camera for the view.
Syntax:
camera = view.camera
Arguments:
Return Value:
camera - a Camera object
Comments:
Example:
model = Sketchup.active_model view = model.active_view c = view.camera

camera=
The camera= method is used to set the camera for the view. If a transition time is given, then it will animate the transition from the current camera to the new one.
Syntax:
view.camera = camera view.camera = camera, transition_time
Arguments:
camera - the new Camera object transition_time - the transition time from the existing camera to the new camera
Return Value:
Comments:
Example:
camera2 = Sketchup.Camera.new model = Sketchup.active_model view = model.active_view status = view.camera=camera2

center
The center method is used to retrieve the coordinates of the center of the view in pixels.
Syntax:
center = view.center
Arguments:
Return Value:
center - the center of the view
Comments:
Example:
model = Sketchup.active_model view = model.active_view c = view.center

corner
The corner method is used to retrieve the coordinates of one of the corners of the view. The argument is an index between 0 and 3 that identifies which corner you want. This method returns an array with two integers which are the coordinates of the corner of the view in the view space. If the view uses a Camera with a fixed aspect ratio, then the corners are the corners of the viewing are of the camera which might be different than the actual corners of the view itself.
Syntax:
point = view.corner index
Arguments:
index - a value between (or including) 0 and 3 identifying the corner whose coordinate you want to retrieve.
Return Value:
point - a Point3d object
Comments:
Example:
model = Sketchup.active_model view = model.active_view pt = view.corner 0

draw
The draw method is used to do basic drawing. This method can only be called from within the draw method of a tool that you implement in Ruby.
Syntax:
view = view.draw mode, pts
Arguments:
mode - the item you are going to draw: GL_LINES, GL_LINE_LOOP, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGON pts - an array of Point3d objects
Return Value:
view - a View object
Comments:
Example:
point6 = Geom::Point3d.new 0,0,0 point7 = Geom::Point3d.new 100,0,0 view.line_width=10 status = view.draw GL_LINES, [point6, point7]

draw2d
The draw2d method is used to draw in screen space (using 2D screen coordinates) instead of 3D space.
Syntax:
view = view.draw2d openglenum, points
Arguments:
openglenum - an OpenGL enumerator (unsigned integer). See comments. points - an array of point3d objects (or several individual point3D objects). These Point3D objects are in screen space, not 3D space. The X value corresponds to the number of pixels from the left edge of the drawing area. The Y value corresponds to the number of pixels down from the top of the drawing area. The Z value is not used.
Return Value:
The openglnum value can be any of the following: GL_POINTS, GL_LINES, GL_LINE_LOOP, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGON.
Comments:
view - returns the View object.
Example:

draw_line
The draw_line method is used to draw disconnected lines. This is an alias for draw_lines. See also draw_lines.
Syntax:
view = view.draw_line point1, point2, point3, point4, ...
Arguments:
point1, point2, poinit3, point4... - an even number of Point3d objects
Return Value:
view - a View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point1 = Geom::Point3d.new 0,0,0 point2 = Geom::Point3d.new 100,100,100 view = view.draw_line point1, point2

draw_lines
The draw_lines method is used to draw disconnected lines.
Syntax:
view = view.draw_lines point1, point2, point3, point4, ... view = view.draw_lines pts
Arguments:
point1, point2, poinit3, point4... - an even number of Point3d objects pts - an array of Point3d objects
Return Value:
view - a View object
Comments:
You must have an even number of points. This method is usually invoked within the draw method of a tool.
Example:
point4 = Geom::Point3d.new 0,0,0 point5 = Geom::Point3d.new 100,100,100 # returns a view status = view.drawing_color="red" status = view.draw_lines point4, point5

draw_points
This method is used to draw points.
Syntax:
view = view.draw_points pts, <pointsize>, <pointstyle>, <pointcolor>
Arguments:
pts - an array of Point3d objects <pointsize> - an optional size of the point in pixels <pointstyle> - an optional style of the point. 1 = open square, 2 = filled square, 3 = "+", 4 = "X", 5 = "*", 6 = open triangle, 7 = filled triangle. <pointcolor> - an optional color of the point
Return Value:
view - a View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point3 = Geom::Point3d.new 0,0,0 # returns a view status = view.draw_points point3, 10, 1, "red"

draw_polyline
The draw_polyline method is used to draw a series of connected line segments from pt1 to pt2 to pt3, and so on.
Syntax:
view = view.draw_polyline pt1, pt2, pt3, pt4, ... view = view.draw_polyline pts
Arguments:
point1, point2, poinit3, point4... - an even number of Point3d objects pts - an array of Point3d objects
Return Value:
view - a View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point12 = Geom::Point3d.new 0,0,0 point13 = Geom::Point3d.new 10,10,10 point14 = Geom::Point3d.new 20,20,20 point15 = Geom::Point3d.new 30,30,30 status = view.draw_polyline point12, point13, point14, point15

draw_text
This method is used to draw text on the screen.
Syntax:
view = view.draw_text point "text"
Arguments:
point - a Point3d object "text" - the text string to draw
Return Value:
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point16 = Geom::Point3d.new 0,0,0 status = view.draw_text point16, "This is a test"

drawing_color=
The drawing_color method is used to set the color that is used for drawing to the view.
Syntax:
view = view.drawing_color = color
Arguments:
color - a color
Return Value:
view - a View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point17 = Geom::Point3d.new 0,0,0 point18 = Geom::Point3d.new 100,0,0 view.line_width=10 status = view.set_color_from_line point17, point18 status = view.draw_lines point17, point18

dynamic=
The dynamic= method allows you to degrade performance, while improving performance, when a model is large and view refresh time is slow.
Syntax:
value = view.dynamic=value
Arguments:
value - 0 is false, 1 is true, >1 is
Return Value:
Comments:
See also camera.rb which is part of the film and stage ruby scripts.
Example:
view.dyamic=3

enable_autopan=
The enable_autopan= method allows you to allow the drawing window to pan when you drag the mouse beyond the boundary.
Syntax:
status = view.enable_autopan = status
Arguments:
status - true if you want to enable autopanning. false if you do not want to enable autopanning.
Return Value:
status - true if autopanning is set to true, false if it is set to false.
Comments:
Example:
view.enable_autopan=false

guess_target
The guess_target method is used to guess at what the user is looking at when you have a perspective view.
Syntax:
target = view.guess_target
Arguments:
Return Value:
target - a Point3d object representing the point in the model that the user is likely interested in.
Comments:
This method is useful when writing a viewing tool. See also camera.rb which is part of the film and stage ruby scripts.
Example:
target = view.guess_target

inference_locked?
The inference_locked? method is used to determine if inference locking is on for the view.
Syntax:
status = view.inference_locked?
Arguments:
Return Value:
status - true if locked, false if unlocked
Comments:
Example:
model = Sketchup.active_model view = model.active_view status = view.inference_locked?

inputpoint
The inputpoint method is used to retrieve an input point.
Syntax:
inputpoint = view.inputpoint x, y inputpoint = view.inputpoint x, y, inputpoint1
Arguments:
x - a x value y - a y value inputpoint1 - an InputPoint object
Return Value:
Comments:
This will normally be used inside one of the mouse event handling methods in a tool. Usually, it is preferable to create the InputPoint first and then use the pick method on it.
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
edge = entities[0]
vertex = edge.end
point = vertex.position
view = model.active_view
ip = view.inputpoint point[0], point[1]

invalidate
The invalidate method is used to refresh the view.
Syntax:
view = view.invalidate
Arguments:
Return Value:
view - the invalidated View object
Comments:
Example:
model = Sketchup.active_model view = model.active_view status = view.invalidate

last_refresh_time
The last_refresh_time method is used to retrieve the time for the last full view refresh.
Syntax:
time = view.last_refresh_time
Arguments:
Return Value:
time - time in milliseconds
Comments:
Example:
model = Sketchup.active_model view = model.active_view t = view.last_refresh_time

line_stipple=
The line_stipple= method is used to set the line pattern to use for drawing.
Syntax:
view = view.line_stipple = pattern
Arguments:
pattern - a stipple pattern. See ConstructionLine.stipple for valid stipples.
Return Value:
view - the View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point8 = Geom::Point3d.new 0,0,0 point9 = Geom::Point3d.new 100,100,100 # Stipple types documented in ConstructionLine class view.line_stipple = "-.-" view = view.draw_lines point8, point9

line_width=
The line_width= method is used to set the line width to use for drawing. The value is a Double indicating the desired width in pixels.
Syntax:
view = view.line_width = width
Arguments:
width - the width in pixels
Return Value:
view - a View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point10 = Geom::Point3d.new 0,0,0 point11 = Geom::Point3d.new 100,100,100 view.line_width=10 view = view.draw_lines point10, point11

lock_inference
The lock_inference method is used to lock or unlock an inference.
Syntax:
view = view.lock_inference view = view.lock_inference inputpoint view = view.lock_inference inputpoint1, inputpoint2
Arguments:
inputpoint, inputpoint2 - InputPoint objects
Return Value:
view - a View object
Comments:
This method will typically be called from inside a tool class when the user presses the shift key. With no arguments it unlocks all inferences. With one or two arguments, it locks the inference based on the given InputPoint(s).
Example:
model = Sketchup.active_model view = model.active_view s = view.lock_inference UI.messagebox $!.message status = view.inference_locked?

model
The model method is used to retrieve the model for the current view.
Syntax:
model = view.model
Arguments:
Return Value:
model - the model for this view
Comments:
Example:
model = Sketchup.active_model view = model.active_view m = view.model

pick_helper
The pick_helper method is used to retrieve a pick helper for the view. See the PickHelper class for information on pick helpers.
Syntax:
pickhelper = view.pick_helper pickhelper = view.pick_helper x, y pickhelper = view.pick_helper x, y, aperture
Arguments:
x - a x value y - a y value aperture - a radius in pixels that defines what items will be picked.
Return Value:
pickhelper - a PickHelper object
Comments:
With no arguments, this returns an initialized PickHelper. If you supply x and y, they are screen coordinates of the point at which you want to do a pick. Typically, there will be points that were passed to a method on a tool class. The optional aperture lets you set how big a pick aperture (in pixels) you want to use for allowing things to be picked. The default uses the standard pick aperture used for SketchUp picking.
Example:
model = Sketchup.active_model view = model.active_view ph = view.pick_helper

pickray
The pickray method is used to retrieve a ray passing through a given screen position in the viewing direction.
Syntax:
ray = view.pickray x, y
Arguments:
Return Value:
ray - a ray
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
edge = entities[0]
vertex = edge.end
point = vertex.position
view = model.active_view
ray = view.pickray point[0], point[1]

pixels_to_model
The pixels_to_model method is used to compute a model size from a pixel size at a given point.
Syntax:
size = view.pixels_to_model pixels, point
Arguments:
pixels - the pixel size point - a Point3d object where the size will be calculated from
Return Value:
size - the model size
Comments:
This method is useful for deciding how big to draw something based on a desired size in pixels.
Example:

set_color_from_line
Set the drawing color for the view based on the direction of a line that you want to draw.
Syntax:
view = view.set_color_from_line point1, point2
Arguments:
point1, point2 - Point3d objects representing the line you want to draw
Return Value:
view - a View object
Comments:
This method is usually invoked within the draw method of a tool.
Example:
point17 = Geom::Point3d.new 0,0,0 point18 = Geom::Point3d.new 100,0,0 view.line_width=10 status = view.set_color_from_line point17, point18 status = view.draw_lines point17, point18

show_frame
The show_frame method is used to show a frame of an Animation object in the current view.
Syntax:
status = view.show_frame <delay>
Arguments:
<delay> - an optional delay in seconds.
Return Value:
Comments:
You can supply an optional delay in seconds to wait before showing the next frame. This can be useful to control the speed at which the animation runs.
Example:
view.show_frame

tooltip=
Set a tooltip to display in the view. This is useful for displaying tooltips in a tool that you write in Ruby.
Syntax:
tooltip = view.tooltip = string
Arguments:
string - the string tooltip
Return Value:
tooltip - the new tooltip string
Comments:
Example:
model = Sketchup.active_model view = model.active_view # Returns a string tool tip tt = view.tooltip="This is a Test"

vpheight
The vpheight method is used to retrieve the height of the viewport for the view.
Syntax:
height = view.vpheight
Arguments:
Return Value:
height - the height of the viewport in pixels.
Comments:
Example:
model = Sketchup.active_model view = model.active_view height = view.vpheight

vpwidth
The vpwidth method is used to retrieve the width of the viewport for the view.
Syntax:
width = view.vpwidth
Arguments:
Return Value:
width - the width of the viewport in pixels.
Comments:
Example:
model = Sketchup.active_model view = model.active_view width = view.vpwidth

write_image
The write_image method is used to write the current view to an image file.
Syntax:
status - view.write_image filename, <width>, <height>, <antialias>, <compressionFactor>
Arguments:
filename - the filename for the saved image <width> - width in pixels <height> - height in pixels <antialias> - <compressionFactor> -
Return Value:
Comments:
All arguments except for the filename are optional. If you specify a width without specifying a height, or if you give zero for either the width or height, then the other dimension is computed to preserve the aspect ratio of the view. If antialias is specified, it should be either true or false.
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
UI.messagebox "Now Lets Write the Image"
view = model.active_view
# Puts in SketchUp install directory by default
status = view.write_image "test.jpg"

zoom
The zoom method is used to zoom in or out by some zoom factor.
Syntax:
view = view.zoom factor
Arguments:
factor - a Zoom factor from 1 or larger
Return Value:
view - the zoomed View object
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
UI.messagebox "Now Lets Zoom"
view = model.active_view
newview = view.zoom 3

zoom_extents
The zoom_extents method is used to zoom so that the entire model fills the view.
Syntax:
view = view.zoom_extents
Arguments:
Return Value:
view - the zoomed View object
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
UI.messagebox "Now Lets Zoom Extents"
view = model.active_view
newview = view.zoom_extents