We have a big big SketchUp model that we want to center to the origin of world axis. We have tons of perspective view, 2 point perspective views, parallel projection views we want to keep from getting damaged by this move of model.
However, I wasn’t able to find a way to deal with 2 point perspective views. I noticed there was a pan and scale operations associated with 2 point perspectives, which confuses Sketchup (Strange behavior when you move eye and target of 2 point perspectives). But as I went through SketchUp Ruby API, I am not seeing any actions you can use Ruby to control 2 point perspective views. Any suggestions are highly appreciated!!!
model = Sketchup.active_model
pages = model.pages
# steps
# you probably need to work out the distance
# from current origin to new origin along
# all three axes in inches
# example made up numbers
stp_r, stp_g, stp_b = 10.m, 120.m, 120.mm
# => [393.7007874015748, 4724.4094488188975, 4.724409448818898]
# then
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
Tried. There is an world origin cannot be changed. If you reset the drawing axes you will find it goes back to a constant. Which is the world origin of SketchUp.
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
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…