Here is the model and the code if you want to do your own testing.
Ruby Code
def int
center = Sketchup.active_model.bounds.center
l = Sketchup.active_model.bounds.height
w = Sketchup.active_model.bounds.width
h = Sketchup.active_model.bounds.depth
c = [center[0] - (w*0.1),center[1] - (l*0.1),center[2]]
c1 = [center[0] - (w*0.1),center[1] + (l*0.1),center[2]]
c2 = [center[0] + (w*0.1),center[1] + (l*0.1),center[2]]
c3 = [center[0] + (w*0.1),center[1] - (l*0.1),center[2]]
m = Sketchup.active_model.bounds.min
Sketchup.active_model.active_view.field_of_view = 35
@l = [[m[0]-(l*0.8),m[1]-(w*0.8),h/2], c,[0,0,1]]
@l1 = [[m[0]-(l*0.8),m[1] + l +(w*0.8),h/2], c1,[0,0,1]]
@r = [[m[0] + w +(l*0.8),m[1] + l +(w*0.8),h/2], c2,[0,0,1] ]
@r1 = [[m[0] + w +(l*0.8),m[1]-(w*0.8),h/2], c3,[0,0,1] ]
@c = Sketchup.active_model.active_view.camera
end
def set_zoom
Sketchup.active_model.active_view.zoom_extents
Sketchup.active_model.active_view.zoom 0.9
end
def vl
int
@c.set @l[0],@l[1],@l[2]
set_zoom
end
def vl1
int
@c.set @l1[0],@l1[1],@l1[2]
set_zoom
end
def vr
int
@c.set @r[0],@r[1],@r[2]
set_zoom
end
def vr1
int
@c.set @r1[0],@r1[1],@r1[2]
set_zoom
end
def generate_views_base64(v)
require 'base64'
view = Sketchup.active_model.active_view
cam = Sketchup.active_model.active_view.camera
eye = cam.eye
target = cam.target
up = cam.up
perspective = cam.perspective?
file_extension = '.png'
f1 = Tempfile.new(['view1', file_extension])
f2 = Tempfile.new(['view2', file_extension])
f3 = Tempfile.new(['view3', file_extension])
f4 = Tempfile.new(['view4', file_extension])
f5 = Tempfile.new(['view5', file_extension])
f6 = Tempfile.new(['view6', file_extension])
if v == 1 then vr else vr1 end
options = {
:filename => f1.path,
:width => 1200,
:height => 600,
:antialias => true,
:compression => 1.0,
:transparent => false
}
#write iso views
Sketchup.active_model.active_view.write_image(options)
if v == 1 then vl else vl1 end
options[:filename] = f2.path
Sketchup.active_model.active_view.write_image(options)
#front view
cam.perspective = false
center = Sketchup.active_model.bounds.center
cam.set(center - Geom::Vector3d.new(0, 1000, 0), center, [0,0,1])
view.zoom_extents
options[:filename] = f3.path
Sketchup.active_model.active_view.write_image(options)
#left
cam.set(center - Geom::Vector3d.new(1000, 0, 0), center, [0,0,1])
view.zoom_extents
options[:filename] = f4.path
Sketchup.active_model.active_view.write_image(options)
#back
cam.set(center + Geom::Vector3d.new(0, 1000, 0), center, [0,0,1])
view.zoom_extents
options[:filename] = f5.path
Sketchup.active_model.active_view.write_image(options)
#right
cam.set(center + Geom::Vector3d.new(1000, 0, 0), center, [0,0,1])
view.zoom_extents
options[:filename] = f6.path
Sketchup.active_model.active_view.write_image(options)
#restore camera position
cam.perspective = perspective
Sketchup.active_model.active_view.camera.set(eye, target, up)
b1 = "data:image/png;base64," + Base64.encode64(File.open(f1, 'rb', &:read))
b2 = "data:image/png;base64," + Base64.encode64(File.open(f2, 'rb', &:read))
b3 = "data:image/png;base64," + Base64.encode64(File.open(f3, 'rb', &:read))
b4 = "data:image/png;base64," + Base64.encode64(File.open(f4, 'rb', &:read))
b5 = "data:image/png;base64," + Base64.encode64(File.open(f5, 'rb', &:read))
b6 = "data:image/png;base64," + Base64.encode64(File.open(f6, 'rb', &:read))
[b1, b2, b3, b4, b5, b6]
end
def do_test
t = Time.now
generate_views_base64(0)
puts "#{Time.now - t} seconds to generate views."
end