View

SketchUp 6.0+

class

Parent: Object

Introduction

This class contains methods to manipulate the current point of view of the model. The drawing methods here (draw_line, draw_polyline, etc) are meant to be invoked within a tool's Tool.draw method. Calling them outside Tool.draw will have no effect.

You access the View by calling the Model.active_view method.

     view = Sketchup.active_model.active_view

Methods

View.add_observerSketchUp 6.0+

The add_observer method is used to add an observer to the current object.

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 view = Sketchup.active_model.active_view
 status = view.add_observer observer

View.animation=SketchUp 6.0+

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.

Arguments:

animation
An Animation object.

Returns:

animation
the newly set Animation object
 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

View.average_refresh_timeSketchUp 6.0+

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.

Returns:

time
the time in milliseconds
 model = Sketchup.active_model
 view = model.active_view
 time = view.average_refresh_time

View.cameraSketchUp 6.0+

The camera method is used to retrieve the camera for the view.

Returns:

camera
a Camera object
 camera = view.camera

View.camera=SketchUp 6.0+

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.

Arguments:

camera
The new Camera object.
transition_time
The transition time from the existing camera to the new camera.

Returns:

nil
 camera2 = Sketchup.Camera.new
 model = Sketchup.active_model
 view = model.active_view
 status = view.camera=camera2

View.centerSketchUp 6.0+

The center method is used to retrieve the coordinates of the center of the view in pixels. It is returned as an array of 2 values for x and y.

Returns:

center
the center of the view
 model = Sketchup.active_model
 view = model.active_view
 c = view.center

View.cornerSketchUp 6.0+

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.

The index numbers are as follows:

  • 0: top left,
  • 1: top right,
  • 2: bottom left,
  • 3: bottom right.
  • Arguments:

    index
    A value between (or including) 0 and 3 identifying the corner whose coordinate you want to retrieve.

    Returns:

    point
    a 2d array [w,h] representing the screen point
     point = view.corner index

View.drawSketchUp 6.0+

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.

The following constants are all OpenGL terms and have been externalized to Ruby. Here is a summary of their meanings:

GL_POINTS: Treats each vertex as a single point. Vertex n defines point n. N points are drawn.

GL_LINES: Treats each pair of vertices as an independent line segment. Vertices 2n-1 and 2n define line n. N/2 lines are drawn.

GL_LINE_STRIP: Draws a connected group of line segments from the first vertex to the last. Vertices n and n+1 define line n. N-1 lines are drawn.

GL_LINE_LOOP: Draws a connected group of line segments from the first vertex to the last, then back to the first. Vertices n and n+1 define line n. The last line, however, is defined by vertices N and 1. N lines are drawn.

GL_TRIANGLES: Treats each triplet of vertices as an independent triangle. Vertices 3n-2, 3n-1, and 3n define triangle n. N/3 triangles are drawn.

GL_TRIANGLE_STRIP: Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. For odd n, vertices n, n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2 define triangle n. N-2 triangles are drawn.

GL_TRIANGLE_FAN: Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices. Vertices 1, n+1, and n+2 define triangle n. N-2 triangles are drawn.

GL_QUADS: Treats each group of four vertices as an independent quadrilateral. Vertices 4n-3, 4n-2, 4n-1, and 4n define quadrilateral n. N/4 quadrilaterals are drawn.

GL_QUAD_STRIP: Draws a connected group of quadrilaterals. One quadrilateral is defined for each pair of vertices presented after the first pair. Vertices 2n-1, 2n, 2n+2, and 2n+1 define quadrilateral n. N/2-1 quadrilaterals are drawn. Note that the order in which vertices are used to construct a quadrilateral from strip data is different from that used with independent data.

GL_POLYGON: Draws a single, convex polygon. Vertices 1 through N define this polygon.

Arguments:

mode
The item you are going to draw, one of the constants from the comments, such as GL_LINES.
pts
An array of Point3d objects.

Returns:

view
a View object
 view = view.draw GL_LINES, pts

View.draw2dSketchUp 6.0+

The draw2d method is used to draw in screen space (using 2D screen coordinates) instead of 3D space.

The second parameter is 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.

Arguments:

openglenum
An OpenGL enumerator (unsigned integer). See comments in the draw method for a list of constants.
points
An array of point3d objects.

Returns:

view
returns the View object.
 view = view.draw2d openglenum, points

View.draw_lineSketchUp 6.0+

The draw_line method is used to draw disconnected lines. This is an alias for draw_lines.

This method is usually invoked within the draw method of a tool.

Arguments:

point_list
An even number of Point3d objects.

Returns:

view
a View object
 view = view.draw_line point1, point2, point3, point4

View.draw_linesSketchUp 6.0+

The draw_lines method is used to draw disconnected lines.

You must have an even number of points. This method is usually invoked within the draw method of a tool.

Arguments:

point_list
An even number of Point3d objects.
pts
An array of Point3d objects.

Returns:

view
a View object
 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

View.draw_pointsSketchUp 6.0+

This method is used to draw points.

This method is usually invoked within the draw method of a tool.

Arguments:

pts
An array of Point3d objects.
pointsize
(optional) Size of the point in pixels.
pointstyle
(optional) Style of the point. 1 = open square, 2 = filled square, 3 = "+", 4 = "X", 5 = "*", 6 = open triangle, 7 = filled triangle.
pointcolor
(optional) Color of the point.

Returns:

view
a View object
 point3 = Geom::Point3d.new 0,0,0
 # returns a view
 status = view.draw_points point3, 10, 1, "red"

View.draw_polylineSketchUp 6.0+

The draw_polyline method is used to draw a series of connected line segments from pt1 to pt2 to pt3, and so on.

This method is usually invoked within the draw method of a tool.

Arguments:

point_list
An even number of Point3d objects.
pts
An array of Point3d objects.

Returns:

view
a View object
 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

View.draw_textSketchUp 6.0+

This method is used to draw text on the screen.

This method is usually invoked within the draw method of a tool.

Arguments:

point
A Point3d object.
text
The text string to draw.

Returns:

nil
 point16 = Geom::Point3d.new 0,0,0
 status = view.draw_text point16, "This is a test"

View.drawing_color=SketchUp 6.0+

The drawing_color method is used to set the color that is used for drawing to the view.

This method is usually invoked within the draw method of a tool.

Arguments:

color
A Color object.

Returns:

view
a View object
 view = view.drawing_color = color

View.dynamic=SketchUp 6.0+

The dynamic= method allows you to degrade visual quality while improving performance when a model is large and view refresh time is slow. For example, if you were using a Ruby script to animate the camera through a large scene, you may want to set dynamic to true during that time.

See also camera.rb which is part of the film and stage ruby scripts.

Arguments:

value
true or false

Returns:

nil
 view.dynamic = true

View.field_of_viewSketchUp 6.0+

The field_of_view method is used get the view's field of view setting, in degrees.

Returns:

fov
the field of view
 fov = Sketchup.active_model.active_view.field_of_view

View.field_of_view=SketchUp 6.0+

The field_of_view= method is used set the view's field of view setting, in degrees.

Arguments:

fov
- the field of view

Returns:

status
true if successful
 my_view = Sketchup.active_model.active_view
 my_view.field_of_view = 45
 my_view.invalidate

View.guess_targetSketchUp 6.0+

The guess_target method is used to guess at what the user is looking at when you have a perspective view.

This method is useful when writing a viewing tool. See also camera.rb which is part of the film and stage ruby scripts.

Returns:

target
a Point3d object representing the point in the model that the user is likely interested in.
 target = view.guess_target

View.inference_locked?SketchUp 6.0+

The inference_locked? method is used to determine if inference locking is on for the view.

Returns:

status
true if locked, false if unlocked
 model = Sketchup.active_model
 view = model.active_view
 status = view.inference_locked

View.inputpointSketchUp 6.0+

The inputpoint method is used to retrieve an input point.

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.

Arguments:

x
A x value.
y
A y value.
inputpoint1
An InputPoint object.

Returns:

nil
 inputpoint = view.inputpoint x, y, inputpoint1

View.invalidateSketchUp 6.0+

The invalidate method is used to refresh the view.

Returns:

invalidated_view
the invalidated View object
 model = Sketchup.active_model
 view = model.active_view
 invalidated_view = view.invalidate

View.last_refresh_timeSketchUp 6.0+

The last_refresh_time method is used to retrieve the time for the last full view refresh.

Returns:

time
time in milliseconds
 time = view.last_refresh_time

View.line_stipple=SketchUp 6.0+

The line_stipple= method is used to set the line pattern to use for drawing. The stipple pattern is given as a string. Valid strings are: "." (Dotted Line), "-" (Short Dashes Line), "_" (Long Dashes Line), "-.-" (Dash Dot Dash Line), "" (Solid Line).

This method is usually invoked within the draw method of a tool.

Arguments:

pattern
A string stipple pattern, such as "-.-"

Returns:

view
the View object
 point8 = Geom::Point3d.new 0,0,0
 point9 = Geom::Point3d.new 100,100,100
 view.line_stipple = "-.-"
 view = view.draw_lines point8, point9

View.line_width=SketchUp 6.0+

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.

This method is usually invoked within the draw method of a tool.

Arguments:

width
The width in pixels.

Returns:

view
a View object
 view.line_width = width

View.lock_inferenceSketchUp 6.0+

The lock_inference method is used to lock or unlock an inference.

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).

Arguments:

inputpoint
(optional) 1st InputPoint to inference to.
inputpoint2
(optional) 2nd InputPoint to inference to.

Returns:

view
a View object
 view = view.lock_inference
 view = view.lock_inference inputpoint
 view = view.lock_inference inputpoint1, inputpoint2

View.modelSketchUp 6.0+

The model method is used to retrieve the model for the current view.

Returns:

model
the model for this view
 model = view.model

View.pick_helperSketchUp 6.0+

The pick_helper method is used to retrieve a pick helper for the view. See the PickHelper class for information on pick helpers.

This call returns an initialized PickHelper.

Returns:

pickhelper
a PickHelper object
 model = Sketchup.active_model
 view = model.active_view
 ph = view.pick_helper

View.pickraySketchUp 6.0+

The pickray method is used to retrieve a ray passing through a given screen position in the viewing direction.

Returns:

ray
a ray
 ray = view.pickray x, y

View.pixels_to_modelSketchUp 6.0+

The pixels_to_model method is used to compute a model size from a pixel size at a given point.

This method is useful for deciding how big to draw something based on a desired size in pixels.

Arguments:

pixels
The pixel size.
point
A Point3d object where the size will be calculated from.

Returns:

size
the model size
 size = view.pixels_to_model pixels, point

View.refreshSketchUp 7.1+

The refresh method is used to immediately refresh the view.

Returns:

refreshed_view
the refreshed View object
 model = Sketchup.active_model
 view = model.active_view
 refreshed_view = view.refresh

View.remove_observerSketchUp 6.0+

The remove_observer method is used to remove an observer from the current object.

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 view = Sketchup.active_model.active_view
 status = view.remove_observer observer

View.screen_coordsSketchUp 6.0+

The screen_coords method is used to retrieve the screen coordinates of the given point on the screen.

The x and y values returned correspond to the x and y screen coordinates. Ignore the z values. If the referenced point is not in the current viewport, the x and/or y value may be negative.

Arguments:

point3d
A Point3d object.

Returns:

x, y
A Point3d containing the screen position
 point = view.screen_coords(ORIGIN)

View.set_color_from_lineSketchUp 6.0+

Set the drawing color for the view based on the direction of a line that you want to draw. These colors will match the axes colors in the SketchUp model (typically blue for straight up and down, etc.)

This method is usually invoked within the draw method of a tool.

Arguments:

point1
Point3d object representing first point in the line.
point2
Point3d object representing second point in the line.

Returns:

view
a View object
 view = view.set_color_from_line point1, point2

View.show_frameSketchUp 6.0+

The show_frame method is used to show a frame of an Animation object in the current view.

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.

Arguments:

lt;delay
An optional delay in seconds.

Returns:

nil
 status = view.show_frame <delay

View.tooltip=SketchUp 6.0+

Set a tooltip to display in the view. This is useful for displaying tooltips in a tool that you write in Ruby.

Arguments:

string
The string tooltip.

Returns:

tooltip
the new tooltip string
 tooltip = view.tooltip = string

View.vpheightSketchUp 6.0+

The vpheight method is used to retrieve the height of the viewport for the view.

Returns:

height
the height of the viewport in pixels.
 model = Sketchup.active_model
 view = model.active_view
 height = view.vpheight

View.vpwidthSketchUp 6.0+

The vpwidth method is used to retrieve the width of the viewport for the view.

Returns:

width
the width of the viewport in pixels.
 width = view.vpwidth

View.write_imageSketchUp 6.0+

The write_image method is used to write the current view to an image file.

All arguments except for the filename are optional.

If antialias is specified, it should be either true or false.

If a hash is passed as the first parameter, then the contents of that hash define how the image is exported. The keys are:

  • filename The filename for the saved image.
  • width (optional) Width in pixels (max 16000).
  • height (optional) Height in pixels (max 16000).
  • antialias (optional) true or false
  • compression (optional) Float compression factor for JPEG images,
between 0.0 and 1.0
  • transparent true or false
  • Arguments:

    filename_or_hash
    The filename for the saved image or a hash containing a set of keys.
    width
    (optional) Width in pixels.
    height
    (optional) Height in pixels.
    antialias
    (optional) true or false
    compression
    (optional) Float compression factor for JPEG images, between 0.0 and 1.0

    Returns:

    nil
     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"
     keys = {
       :filename => "c:/tmp/write_image.png",
       :width => 640,
       :height => 480,
       :antialias => false,
       :compression => 0.9,
       :transparent => true
     }
     model = Sketchup.active_model
     view = model.active_view
     view.write_image keys

View.zoomSketchUp 6.0+

The zoom method is used to zoom in or out by some zoom factor.

Arguments:

zoom_or_ents
A Float zoom factor from 1.0 or larger or an Array or collection of entities to "zoom extents" around.

Returns:

view
the zoomed View object
 view = view.zoom factor
 view = view.zoom selection
 view = view.zoom entity
 view = view.zoom array_of_entities

View.zoom_extentsSketchUp 6.0+

The zoom_extents method is used to zoom to the extents about the entire model, as if the user has selected the zoom extents command from the menu.

Returns:

new_view
the zoomed View object
 view = Sketchup.active_model.active_view
 new_view = view.zoom_extents

  

Trimble Home
About Trimble - Privacy Policy - Contact Us