Home
Developer Docs

Camera

SketchUp 6.0+

class

Parent: Object

Introduction

The Camera class contains methods for creating and manipulating a camera. The camera in SketchUp is the "point of view" from which you look at the model.

     # Create a camera from scratch with an "eye" position in
     # x, y, z coordinates, a "target" position that
     # defines what to look at, and an "up" vector.
     eye = [1000,1000,1000]
     target = [0,0,0]
     up = [0,0,1]
     my_camera = Sketchup::Camera.new eye, target, up

     # Get a handle to the current view and change its camera.
     view = Sketchup.active_model.active_view
     view.camera = my_camera

Methods

Camera.aspect_ratioSketchUp 6.0+

The aspect_ratio method is used to retrieve the aspect ratio of the Camera.

Returns:

aspectratio
an aspect ratio, such as 1.85, if successful
 camera = Sketchup::Camera.new
 ar = camera.aspect_ratio
 if (ar)
   UI.messagebox ar.to_s
 else
   UI.messagebox "Failure"
 end

Camera.aspect_ratio=SketchUp 6.0+

The aspect_ratio= method is used to set the aspect ratio for a Camera. Changing this value will cause SketchUp to show gray bars over the screen to show the resulting view.

If you set the value to 0.0, then the aspect ratio of the Camera will match the aspect ratio of its View.

Returns:

aspectratio
an aspect ratio, such as 1.85, if successful
 camera = Sketchup::Camera.new
 ar = camera.aspect_ratio = 1.85
 if (ar)
   UI.messagebox ar.to_s
 else
   UI.messagebox "Failure"
 end

Camera.center_2dSketchUp 2015+

The center_2d method returns a point with the x and y offset of the camera when it's in 2d mode. The z value is always zero.

When the camera is in two point perspective and the user pans around, the x and y value will change.

Returns:

Point3d
 Sketchup.active_model.active_view.camera.center_2d

Camera.descriptionSketchUp 6.0+

The description method is used to retrieve the description for a Camera object.

Returns:

description
a string description for the camera if successful
 camera = Sketchup::Camera.new
 description = camera.description
 if (description)
   UI.messagebox description
 else
   UI.messagebox "Failure"
 end

Camera.description=SketchUp 6.0+

The description= method is used to set the description for the Camera.

Returns:

description
a string description for the camera if successful
 camera = Sketchup::Camera.new
 description = camera.description = "35 mm Camera"

Camera.directionSketchUp 6.0+

The direction method is used to retrieve a Vector3d object in the direction that the Camera is pointing.

Returns:

direction
a Vector3d object pointing in the direction that the Camera is pointing if successful
 camera = Sketchup::Camera.new
 # Returns 0,0,-1 which indicates it is pointed down the Z axis
 direction = camera.direction
 if (direction)
   UI.messagebox direction.to_s
 else
   UI.messagebox "Failure"
 end

Camera.eyeSketchUp 6.0+

The eye method is used to retrieve the eye Point3d object for the Camera.

Returns:

eye
a Point3d object if successful
 camera = Sketchup::Camera.new
 # Returns 0,0,1 which indicates it is right in line with the Z axis.
 eye = camera.eye
 if (eye)
   UI.messagebox eye
 else
   UI.messagebox "Failure"
 end

Camera.focal_lengthSketchUp 6.0+

The focal_length method is used to get the focal length in millimeters of perspective Camera.

This value is computed based on the field of view (see the fov method) and the image width (see image_width).

Arguments:

length
The focal length for the camera if successful.

Returns:

nil
 camera = Sketchup::Camera.new
 l = camera.focal_length
 if (l)
   UI.messagebox l.to_s
 else
   UI.messagebox "Failure"
 end

Camera.focal_length=SketchUp 6.0+

The focal_length= method allows you to sent the focal length (in millimeters) of a perspective camera. It must be between 1 and 3000, inclusive. This is an alternate way of setting the field of view.

Returns:

length
the new focal length for the camera if successful
 camera = Sketchup::Camera.new
 l = camera.focal_length=120
 if (l)
   UI.messagebox l
 else
   UI.messagebox "Failure"
 end

Camera.fovSketchUp 6.0+

The fov method retrieves the field of view of the camera (in degrees).

This is only applicable to perspective cameras.

Returns:

fov
field of view, in degrees, if successful
 camera = Sketchup::Camera.new
 fov = camera.fov
 if (fov)
   UI.messagebox fov.to_s
 else
   UI.messagebox "Failure"
 end

Camera.fov=SketchUp 6.0+

The fov= method sets the field of view, in millimeters, for a Camera. It must be between 1 and 120, inclusive.

This is only valid on a perspective camera.

Arguments:

fov
A field of view in millimeters.

Returns:

fov
the new field of view if successful
 camera = Sketchup::Camera.new
 fov = camera.fov = 56.78
 if (fov)
   UI.messagebox fov.to_s
 else
   UI.messagebox "Failure"
 end

Camera.fov_is_height?SketchUp 2015+

The fov_is_height? method indicates whether the field of view is horizontal or vertical.

Returns:

bool
true if vertical, false otherwise
 camera = Sketchup.active_model.active_view.camera
 if camera.fov_is_height?
   fov_vertical = camera.fov
   # Compute the horizontal FOV.
 else
   fov_horizontal = camera.fov
   # Compute the vertical FOV.
 end

Camera.heightSketchUp 6.0+

The height method retrieves the height of a Camera in inches.

This is only valid if it is not a perspective camera.

Returns:

height
height in current units if successful
 camera = Sketchup::Camera.new
 camera.perspective = false
 h = camera.height
 if (h)
   UI.messagebox h.to_s
 else
   UI.messagebox "Failure"
 end

Camera.height=SketchUp 6.0+

The height= method is used to set the height for the Camera in inches.

This is only valid if it is not a perspective camera.

Returns:

height
height in current units if successful
 camera = Sketchup::Camera.new
 camera.perspective = false
 h = camera.height = 20
 if (h)
   UI.messagebox h.to_s
 else
   UI.messagebox "Failure"
 end

Camera.image_widthSketchUp 6.0+

The image_width method retrieves the size of the image on the image plane of the Camera.

By default, this value is not set. If it is set, it is used in the calculation of the focal length from the field of view. Unlike most length values in SketchUp, the image_width and focal_length values are specified in millimeters rather than in inches.

Returns:

width
the width of the camera if successful
 camera = Sketchup::Camera.new
 w = camera.image_width
 if (w)
   UI.messagebox w.to_s
 else
   UI.messagebox "Failure"
 end

Camera.image_width=SketchUp 6.0+

The image_width= method is used to set the size of the image on the "film" for a perspective camera.

The value is given in millimeters. It is used in the conversions between field of view and focal length.

Returns:

width
the width of the camera if successful
 camera = Sketchup::Camera.new
 w = camera.image_width=1.0
 if (w)
   UI.messagebox w.to_s
 else
   UI.messagebox "Failure"
 end

Camera.is_2d?SketchUp 2015+

The is_2d? method indicates if the camera is in 2d mode. 2 point perspective mode and PhotoMatch mode are 2d cameras.

Returns:

Boolean
true if camera is in 2d mode, false otherwise
 Sketchup.active_model.active_view.camera.is_2d?

Camera.newSketchUp 6.0+

Returns a new camera with eye (where the camera is) and targets (where the camera is looking) of type Point3d, up direction of type Vector3d, optional perspective flag of value true or false, and optional field-of-view value in degrees of type Float.

Arguments:

eye
See Camera.eye.
target
See Camera.target.
up
See Camera.up.
perspective
(optional) see Camera.perspective. Defaults to true.
fov
(optional) see Camera.fov. Defaults to 30.0.

Returns:

camera
a new Camera object if successful
 camera = Sketchup::Camera.new
 if (camera)
   UI.messagebox camera
 else
   UI.messagebox "Failure"
 end

Camera.perspective=SketchUp 6.0+

The perspective= method is used to set whether or not this is a perspective camera or an orthographic camera.

Arguments:

perspective
true for perspective, false for orthographic

Returns:

status
true if perspective, false if orthographic
 camera = Sketchup::Camera.new
 status = camera.perspective = false
 if (status)
   UI.messagebox "Perspective"
 else
   UI.messagebox "Orthographic"
 end

Camera.perspective?SketchUp 6.0+

The perspective? method is used to determine whether a camera is a perspective or orthographic camera.

Returns:

status
true if perspective, false if orthographic
 camera = Sketchup::Camera.new
 status = camera.perspective?
 if (status)
   UI.messagebox "Perspective"
 else
   UI.messagebox "Orthographic"
 end

Camera.scale_2dSketchUp 2015+

The scale_2d method returns float indicating the scaling factor of 2d cameras.

When the camera is in two point perspective and the user uses the zoom tools, this value will change.

Returns:

float
 Sketchup.active_model.active_view.camera.scale_2d

Camera.setSketchUp 6.0+

The set method sets the camera orientation. You have to set the camera eye, target and up parameters at the same time to make sure that you have a valid camera definition.

Arguments:

eye
See Camera.eye.
target
See Camera.target.
up
See Camera.up.

Returns:

camera
the modified camera
 camera = Sketchup::Camera.new
 eye = camera.eye
 target = camera.target
 up = camera.up
 # We just set it to exactly what it was pointing at in the first place
 camera.set eye, target, up
 if (camera)
   UI.messagebox camera.to_s
 else
   UI.messagebox "Failure"
 end

Camera.targetSketchUp 6.0+

The target method retrieves Point3d that the camera is pointing at.

Returns:

target
a Point3d object if successful
 camera = Sketchup::Camera.new
 # Target point is 0,0,0
 t = camera.target
 if (t)
   UI.messagebox t.to_s
 else
   UI.messagebox "Failure"
 end

Camera.upSketchUp 6.0+

The up method is used to retrieve the up vector for the camera. This is the direction that the top of the camera is facing.

Returns:

up
a Vector3d object if successful
 camera = Sketchup::Camera.new
 # 0.0, 1.0, 0.0
 up = camera.up
 if (up)
   UI.messagebox up.to_s
 else
   UI.messagebox "Failure"
 end

Camera.xaxisSketchUp 6.0+

The xaxis method is used to retrieve the x axis of the camera coordinate system defined by the camera's direction and up vector.

This value is computed from the cross product between the camera direction and the up vector.

Returns:

vector
a Vector3d object if successful
 camera = Sketchup::Camera.new
 # 1.0, 0.0, 0.0
 v = camera.xaxis
 if (v)
   UI.messagebox v.to_s
 else
   UI.messagebox "Failure"
 end

Camera.yaxisSketchUp 6.0+

The yaxis method retrieves the y axis of the camera coordinate system defined by the camera's direction and up vector.

This value is computed to be perpendicular the camera x and z axes. It is equivalent to the up direction, but is computed to make sure that it is perpendicular to the direction.

Returns:

vector
a Vector3d object if successful
 camera = Sketchup::Camera.new
 # 0.0, 1.0, 0.0
 v = camera.yaxis
 if (v)
   UI.messagebox v.to_s
 else
   UI.messagebox "Failure"
 end

Camera.zaxisSketchUp 6.0+

The zaxis method retrieves the z axis of the camera coordinate system defined by the camera's direction and up vector.

This value is computed. It is the same as Camera.direction

Returns:

vector
a Vector3d object if successful
 camera = Sketchup::Camera.new
 # 0.0, 1.0, 0.0
 v = camera.zaxis
 if (v)
   UI.messagebox v.to_s
 else
   UI.messagebox "Failure"
 end

  

Trimble Home
About Trimble - Privacy Policy - Contact Us