Search code examples
rubysketchup

How to set camera for page in Sketchup programmatically?


I am new in writing Sketchup plugins and I got problem. I know how to create page (scene) and camera, but I have no idea how to set the camera for the page. Any tips?

eye = [100, 100, 500]
target = [300, 300, 300]
up = [0, 0, 1]

pg_front = pages.add "front"
front_cam = Sketchup::Camera.new eye, target, up

# First idea, but it's not working
pg_front.camera = front_cam

# Second idea, but it's not working too
pg_front.use_camera = front_cam

Solution

  • Have you tried to use Camera#set?

    pg_front.camera.set(front_cam)
    

    I know very little about Sketchup, but you may have to update the page afterwards:

    pg_front.update(1)
    

    According to the docs of Page#update the following update flags are available:

    - 1 - Camera Location,
    - 2 - Drawing Style,
    - 4 - Shadow Settings,
    - 8 - Axes Location,
    - 16 - Hidden Geometry,
    - 32 - Visible Layers,
    - 64 - Active Section Planes.
    

    If this isn't working, try disabling the camera before reassigning it, then enable it again (pg_front.use_camera = true/false).