@DanRathbun Thanks Dan. Any adverse affect to using a timer? Loss of performance?
@john_drivenupthewall
I was able to find some code on SketchUcation to get the viewport window handle.
This code ‘docks’ the ruby console to the right of the viewport. Now I need to get a handle to the tray window so I can move the ‘docked’ window left on tray window flyout.
#win32api
require 'Win32API'
FindWindow = Win32API.new('user32', 'FindWindow', ["P", "P"], "L")
GetWindowPos = Win32API.new("user32","GetWindowRect",["L","P"],"V")
SetWindowPos = Win32API.new("user32","SetWindowPos",["L","L","L","L","L","L","L"],"V")
GetActiveWindow = Win32API.new('User32', 'GetActiveWindow', '', 'L')
GetWindow = Win32API.new('User32', 'GetWindow', 'LL', 'L')
GetClientRect = Win32API.new('User32', 'GetClientRect', 'LP', 'I')
FindWindowEx = Win32API.new('User32', 'FindWindowEx', 'LLPP', 'L')
GetWindowLong = Win32API.new('User32', 'GetWindowLong', 'LI', 'L')
AdjustWindowRectEx = Win32API.new('User32', 'AdjustWindowRectEx', 'PLIL', 'I')
active = GetActiveWindow.call()
owner = GetWindow.call(active, 4)
@main_hwnd = owner == 0 ? active : owner
def window_pos(window_ref)
r = "0"*16
if window_ref.is_a? Fixnum
h = window_ref
else
h = FindWindow.call(nil,window_ref)
end
GetWindowPos.call(h,r)
return r.unpack("LLLL")
end
def set_window_pos(window_ref,x,y,width=0,height=0)
r = "0"*20
temp = [x,y,height,width,16]
if window_ref.is_a? Fixnum
h = window_ref
else
h = FindWindow.call(nil,window_ref)
end
wp = window_pos(window_ref)
if height == 0 then height = wp[3] - wp[1] end
if width == 0 then width = wp[2] - wp[0] end
SetWindowPos.call(h,0,x,y,width,height,16)
end
def dock_to(docked_title, main_title)
main_pos = window_pos(main_title)
docked_pos = window_pos(docked_title)
left = main_pos[0] - (docked_pos[2]-docked_pos[0])+15
needs_move = false
unless left == docked_pos[0] and main_pos[1] == docked_pos[1] and main_pos[3] == docked_pos[3]
set_window_pos(docked_title,left,main_pos[1],0,main_pos[3]-main_pos[1])
end
end
def dock_viewport_right(hwnd)
vp_pos = window_pos(get_viewport_handle)
docked_pos = window_pos(hwnd)
needs_move = false
left = vp_pos[2] - (docked_pos[2]-docked_pos[0])+6
unless left == docked_pos[0] and vp_pos[1] == docked_pos[1]
set_window_pos(hwnd,left,vp_pos[1],0,vp_pos[3]-vp_pos[1])
end
end
def get_viewport_handle
cname = case Sketchup.version.to_i
when 6
'AfxFrameOrView70u'
when 7,8
'AfxFrameOrView80u'
when 13,14,15,16
'AfxFrameOrView100u'
else
'AfxFrameOrView140u'
end
return FindWindowEx.call(@main_hwnd, 0, cname, nil)
end
#dock_timer = UI.start_timer(0.01,true){dock_to("Building Creator","Ruby Console")}
dock_timer = UI.start_timer(0.01,true){dock_viewport_right(active)}
It looks like I have all the loose pieces no to make something wonderful.