@john_drivenupthewall:
My new code for view port resizer. This works at least for Ruby console. I do not know how could I access the SU window hwnd to test on SU directly.
For ruby <2.0 you need the Enorth Viewport Resizer because of the Win32API.so driver.
#Require win32api
if RUBY_VERSION < "2.0.0"
require File.join(PLUGIN_ROOT, "ene_viewport_resizer", "Win32API.so")#Bundled with plugin for SU 2013.
else
require "Win32API"#Standard libraries included in SU 2014+.
end
GetActiveWindow = Win32API.new("user32.dll", "GetActiveWindow", "", "L") unless defined?GetActiveWindow
GetWindowRect = Win32API.new("user32.dll", "GetWindowRect", "LP", "I") unless defined?GetWindowRect
ShowWindow = Win32API.new("user32.dll", "ShowWindow", "LI", "I") unless defined?ShowWindow
MoveWindow = Win32API.new("user32.dll", "MoveWindow", "LIIIII", "I") unless defined?MoveWindow
#Returns array of left, top, right and bottom
def get_rect(hwnd)
rect = [0, 0, 0, 0].pack("L*")
GetWindowRect.call hwnd, rect
rect.unpack("L*").map { |e| [e].pack("L").unpack("l").first }
end
#Get window size as array of width and height.
def get_size(hwnd)
left, top, right, bottom = get_rect hwnd
w = right - left
h = bottom - top
return [w, h]
end;
def getRectangleDimensions();
ss = Sketchup.active_model.selection
ent = ss[0];
origin = ent.transformation.origin;
if ent.class == Sketchup::Group
box = ent.local_bounds
end
if ent.class == Sketchup::ComponentInstance
box = ent.definition.bounds
end
mx = box.max.x;
my = box.max.y;
x = origin[0];
y = origin[1];
z = origin[2];
v = Sketchup.active_model.active_view;
a = v.screen_coords(Geom::Point3d.new(x, y, z))
b = v.screen_coords(Geom::Point3d.new(x, y+my, z))
c = v.screen_coords(Geom::Point3d.new(x+mx, y+my, z))
d = v.screen_coords(Geom::Point3d.new(x+mx, y, z))
w1 = d[0]-a[0];
h1 = d[1]-c[1];
# w2 = c[0]-b[0];
# h2 = a[1]-b[1];
# puts "#{w} x #{h}"
# return [ x, y, w, h ]
return [a[0], c[1], w1, h1];
end;
def setViewPort(w=400,h=200);
x, y, w, h = getRectangleDimensions();
size = [w, h]
view = Sketchup.active_model.active_view;
view.vpwidth;
view.vpheight;
wp_size = [view.vpwidth, view.vpheight]
#Assume the main Sketchup window is the active one
hwnd = GetActiveWindow.call
window_size = get_size hwnd
delta_size = window_size.zip(wp_size).map { |x, y| x - y }
window_new_size = size.zip(delta_size).map { |x, y| x + y }
ShowWindow.call hwnd, 9; #9 = SW_RESTORE
left, top, right, bottom = get_rect hwnd
MoveWindow.call hwnd, left, top, size[0], size[1], 1
end
def centerCamera(perspective = false, zoomOut = 150)
cam = Sketchup.active_model.active_view.camera;
cam.perspective = perspective;
Sketchup.send_action('viewTop:');
Sketchup.send_action('viewZoomToSelection:');
end;
PLUGIN_ROOT = File.dirname(__FILE__) unless defined?(PLUGIN_ROOT)
# file = PLUGIN_ROOT + "/shadows.rb"
file = File.join(PLUGIN_ROOT, "shadows.rb")
if not (file_loaded? file )
UI.menu("Plugins").add_item("Barracuda Shadows") { centerCamera(); }
file_loaded file
end
call setViewPort