Notifications
Clear all
[Closed] Function for getting the Hwnd of a viewport
Nov 04, 2009 3:27 pm
Just thought that I would post this if any one else is interested. Let me know if you see any faster methods for doing this.
/*HeaderStart****************************************************
:Created By: Paul Neale
:Company: PEN Productions Inc.
:Site: http://paulneale.com
:Email: info@paulneale.com
:Client: PEN Productions
:Purpose: Retuns the HWND for the active viewport.
:History:
Oct 04 2009
Created.
:Todo:
:Bugs:
None Known
:Tests:
for x in windows.getChildrenHWND #max do format "%
" x
-->Use this to create a dotNet handle for the viewport.
p = DotNetObject "System.IntPtr" ( (getViewportHwnd()) [1])
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" p
****************************************************HeaderEnd*/
/*FnStart****************************************************
:Function: getActiveViewportName
:Usage: getActiveViewportName()
:Todo:
:Notes:
Called by getViewportHwnd
****************************************************FnEnd*/
fn getActiveViewportName=
(
local viewName=viewport.getType()
case of
(
(viewName==#view_top): "Top"
(viewName==#view_bottom): "Bottom"
(viewName==#view_right): "Right"
(viewName==#view_left): "Left"
(viewName==#view_back): "Back"
(viewName==#view_persp_user): "Perspective"
(viewName==#view_iso_user): "Orthographic"
(viewName==#view_camera): (viewport.getCamera index:viewport.activeViewport).name
(viewName==#view_spot): (viewport.getCamera index:viewport.activeViewport).name
(viewName==#view_shape): "Shape"
(viewName==#view_grid): "Grid" --Will need to search for "Grid" in the name here.
)
)
/*FnStart****************************************************
:Function: getViewportHwnd
:Usage: getViewportHwnd()
:Todo:
:Notes:
Calls getActiveViewportName and returns the HWND array for the active viewport.
****************************************************FnEnd*/
fn getViewportHwnd=
(
local viewPortName=getActiveViewportName()
local returnHwnd=undefined
if viewPortName!=undefined do
(
for wHwnd in windows.getChildrenHWND #max do
(
if wHwnd[4]=="D3DWindow" and findString wHwnd[5] viewPortName!=undefined do
(
returnHwnd=wHwnd
exit
)
)
)
returnHwnd
)
3 Replies
Nov 04, 2009 3:27 pm
Hey Paul,
It's not a killer but I would use this instead of using exit:
for wHwnd in windows.getChildrenHWND #max [b]while returnHwnd == undefined[/b] do
(
if wHwnd[4]=="D3DWindow" and findString wHwnd[5] viewPortName!=undefined do
(
returnHwnd=wHwnd
)
)
Light
Nov 04, 2009 3:27 pm
Crazy, because it is so simple in the SDK:
::GetCOREInterface()->GetActiveViewport()->GetHWND()
Nov 04, 2009 3:27 pm
Right, exit is slow as well isn’t it. I’ll make the change, turns out I’m not using it now anyways.
Ya Mike there didn’t appear to be an easy way.