SketchUp Ruby API and 2 Point Perspective Expertise Needed

if you combine a version of dan’s with mine it works for all 3 camera types…

model = Sketchup.active_model
vec =   model.bounds.corner(0).vector_to(ORIGIN)
model.entities.transform_entities(
vec,model.entities.to_a)
 stp_r, stp_g, stp_b = vec.to_a.entries
    # then
    pages = Sketchup.active_model.pages
    pages.each do |page|
    # camera
    cam = page.camera
    # camera target
    target = cam.target
    # camera eye
    eye = cam.eye
    # camera up
    up = cam.up
   # get arrays
    e0  = eye.to_a
    t0  = target.to_a
    # use standard ruby on target position
    t = t0.zip([stp_r, stp_g, stp_b]).map(&:sum)
    # eye positions
    e = e0.zip([stp_r, stp_g, stp_b]).map(&:sum)
   # use the same up
   cam.set(e, t, up)
   
   end #pages.each 

test file:
cam_move_origin.skp (24.1 KB)

use File >> ‘Revert’ to retest after trying…

EDIT: I just test vec = Geom::Vector3d.new(-200.m,-400.m,0 ) and vec = Geom::Vector3d.new(200.m,400.m,0 ) to move cameras, away then back in a 78MB drawing with Shadows on in scenes…

very fast…

john

1 Like