[Maxscript] SpaceMapping on all visible viewports

Hello, I’m writing a script that draws something on top of the viewport. I already have the following.

I’ve written a custom control in c# that does most of the handling. I get the max Handle by calling GetMaxHWND in my control:

maxHandle = ManagedServices.AppSDK.GetMaxHWND();

With this handle I look for a child handle with the name “ViewPanel”. In there I can find the hwnd’s of the viewports. With those hwnd’s I get the size and position of the viewports so I can draw a Form() on top of it.

The first problem I came across is that there is currently no callback for ViewportLayoutChanges (please correct me if I’m wrong). Because of this I wasn’t able to update the size nor position of my Forms when the user resizes the viewports. I’ve fixed this using a hook written in c++ that hooks the WM_WINDOWPOSCHANGED message. This is working great, but now I have a new problem…

For my first test of my viewport drawing script I’d like to paint something on selected vertices.
I’m able to convert the world position of the vertices to screen position (thanks to http://www.illusioncatalyst.com/mxs_files/spaceMapping.html).

The problem is: this seems to only work on the active viewport, but I’d like to get the screen position of the verts on ALL visible viewports.



As you can see in the first picture the red circle is only drawn in the active viewport, because that’s the only one I can get the screen position of. The second image is what I’d like it to do. But I have no idea how.

I thought about simulating a mouse click on each viewport (after all I know the coordinates of each one) to make them active, and then getting the screen position. However this sounds a bit tedious.

Any help on this would be appreciated! :nod:

Thanks

So, basically what you need is the TM of all the viewports? Would switching active viewports in a loop be good enough?

(
	struct view (id, tm)
	local prev = viewport.activeViewport

	with redraw off local views = for v = 1 to viewport.numViews collect
	(
		viewport.activeViewport = v
		view id:v tm:(viewport.GetTM())
	)

	viewport.activeViewport = prev
	views
)

Hey, that worked! Thank you!