Notifications
Clear all

[Closed] Viewport Layout Settings

I’m working with the default quad viewport layout.
According to that, viewport 4 is perspective view and viewport 1 is top view. So let’s say I want to change viewport1 to perspective as well.

          I'm running this code and I get a brand new perspective window. It keeps the settings of the previous window(top view) like camera angle, shading, etc, it's looking different than the original persp window. That's not what I want.
viewport.activeViewport = 1
viewport.setType #view_persp_user

However, if I change the top view to perspective via viewport configuration/layout/left click on top view/select perspective, this gives me exactly the same perspective view on viewport 4, and this is what I wanted to do.

          So, is there another piece of code to set viewport type so that it keeps my original settings like the way "viewport configuration" does?

Thanks in advance.

11 Replies

In such cases it’s best to turn on the macrorecorder and look what output your menu selection
produces.
But anyways:
i cannot confirm that selecting the menu entry produces a different result than switching via script command…

you need to use find the existing perspective viewport, set it as active, copy it’s transform to a variable
eg. tm = viewport.getTM(), set your other viewport as active and set it’s transform to tm.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

…transform and FOV I guess…

Thanks for the replies.

@spacefrog

Unfortunately macro recorder isn’t showing anything. What I’m actually trying to do is writing a simple script switching between two different layouts. Tricky part is, when I’m switching I want to keep viewport states, I should give you an example:

first layout has 4 viewports: top, front, left, persp
second layout has 3 viewports: track view, camera view, persp

When I switch these layouts perspective view should stay same instead of getting a persp view from scratch.

@Gravey can you please show me an example code?

Ah – now i understand
Just look how i did that persp/panning/zoom matching in my PowerSwitcher Viewport script

look for the ApplyVPInfo function and VPPowerSwitcherInfo struct…

link to the script is in my sig…
might be a cool future idea for my script to transfer viewport panning info/perspective/zoom/FOV settings when switching layouts…

UPDATE:
on a second thought this should already happen, at least for viewports you switched already using my script…
as i store the info for each viewport type regardless what Max is keeping internally in buffers…

so you might simply check out my script and see if it does it the way you want it to be…
To do it right after start i just would have to implement a short function which loops through the viewports and stores each VP in my internall buffer… that should do it …

fn CopyViewport source_index target_index =
(
	oldActiveView = viewport.activeViewport
	viewport.activeViewport = source_index
	type = viewport.getType()
	tm = viewport.getTM()
	fov = viewport.getFOV()
	viewport.activeViewport = target_index
	viewport.setType type
	viewport.setTM tm
	viewport.setFOV fov
	viewport.activeViewport = oldActiveView
	
	OK
)
1 Reply
(@spacefrog)
Joined: 11 months ago

Posts: 0

AFAIK
that doesn’t correctly restore the zoom value in isometric (= non-perspective: user, left,top etc…) viewports, because that is handled by the FOV value, which is only readable in isometric views, but not settable. Thus you have to determine the current display bounding region of the source viewport, which requires some “jumping through hoops”* and do a ZoomToBounds afterwards

This “jumping through hoops” requires a translation of the top-left and the bottom-right viewport pixel-coordinates into worldspace, generate a valid, (virtual)camera aligned AABB bounding box and do a ZoomToBounds to that bounding values. That results in the same Zoom settings like in the new isometric vierwport
(see the CreateVPInfo function in my PowerSwitcher script)

But i’m sure, Denis will immediatly come up with a short one maxscript command hack, making the workaround i just descriped and used in my script, completely obsolete 😈

Thanks. I’m still trying to figure out a way. It’s more complicated than I thought.
Also, one more thing, is it possible that we could use custom set viewport size information as well or are we stuck to those premade layouts (layout_3ht, layout_2hb, etc) when we change a layout?

1 Reply
(@spacefrog)
Joined: 11 months ago

Posts: 0

prev Max2012 version up to Max2011 supported to set the viewport sizes ( in some ‘hacky’ way )
via

[B]"gw.setPos <x_integer> <y_integer> <w_integer> <h_integer>"[/B]

but that functionality is broken in Max 2012, and probably never will return
It wasn’t updating the splitter bars anyway and always worked only on one viewport, so you would have had a lot of calculations and tricks to do, to adjust the layout dimensions

The best way i think would be to somehow find the handles to the splitter controls and use Windows messages to position them to your liking. Saving to maxstart.max only saves the currently used layout’s windows arrengement, so evertime you switch layout you are presented with the default arrangement

Spacefrog, your script is pretty awesome, but I think it’s just storing single viewport.
So I was wondering, are there any scripts that can store/load layout settings completely, just the way maxstart.max file does? (basically all the settings in “Viewport Configuration” should be retained, plus viewports and their sizes and positions)
There’s an old script of BoBo’s. It saves and restores layouts. It’s pretty neat but it does not store most settings like maxstart.max file does. It just stores layout type and viewport names.

not that i know of ( something that stores all layout’s info etc…)
Might be again a good feature for my script …
If only all this scripting would bring some money, i would spend my life writing scripts and 3 ds Max plugins to overcome all the shortcomings Max has piled-up over the years …