Notifications
Clear all

[Closed] Detect maximized viewport

 JHN

Is there anyway besides

if viewport.getLayout() == #layout_1 do

to detect if a viewport is maximized?

The problem: (still on max2010)
The render dialog doesn’t take a camera for input, but a view. Locking the view (in the render dialog) causes all sorts of problems when you change your viewport from camera to something else.

Now ponder on this
Say you have a 4view layout and top right is camera and bottomright is camera. In the render dialog you assign the camera view to the render panel, maximize anything but the camera view and see the render view camera switch to that viewport, makes sense in a way, because there’s now only 1 viewport. BUT, go to 4 views, select camera viewport and in render dialog lock the render view. Now again maximize any viewport but the camera viewport, it keeps the render camera, but also you can pick from one of the 3 other views. So somehow max knows about the views that are not maximized.

I can not find out how it knows this. Maximize viewport is not a mode, it’s an actual change of viewport configuration, but how does it know what to switch back too.

It seems unexposed, and since we’re submitting from outside of max to the farm I cannot actively force the camera view to be the render view.

Any ideas or things I’m missing. I already have a workaround, but the locking of views and not being able to tie a camera to the renderer is a real pain!

-Johan

27 Replies

Yes, there is no exposure of viewports maxmimized state, only a toggle function available ( max tool maximize )
The code you posted above would just work when the layout is set to only allow one viewport, which of course would than always be maxmimized. But thats quite a special case

Usually i simply use the following code to detect wether the view is maxmimized or not

viewportMaximized = NOT( viewport.NumViews>1 )

if i get true in my code snippet above, i ‘can assume that after calling “max tool maximize” (which toggles the maxmimized state ) i DEFINITELY have access to all available viewports in the current layout, which is the use case i have most often: cylce through all views to do something with them…

Regarding your case:

honestly i can’t follow exactly what you want to do. I understand the problem though:
the renderer setting is tied to a viewport index, not a camera
So you want to lock the render setting to a specific camera i presume, not to a specific viewport index ?

I’ve never worked on this subject so I don’t know if I am looking into the right direction, but does the following code help?

(
 fn getViewports =
 (
 	for v = 1 to 4 collect #(viewport.getType index:v, viewport.getCamera index:v)
 )
 getViewports()
 )
(
 fn setActiveCamera name =
 (
 	for c in cameras where (c.name == name) do viewport.setCamera c
 )
 setActiveCamera "Camera001"
 )
 JHN

Thanks guys,

I just needed some reassurance I wasn’t missing the obvious.

@Josef : What I’m trying to do is make a bulletproof way to ensure that when a file is submitted for rendering the right viewport (+camera) is set in the render settings.
We never had a problem before because I was calling net render from max where you can enforce a render camera. But now we’ve build our own external render submitter I need to ensure the max file is not rendering the front viewport for example. And since we found out people simply change viewport configurations as they please there’s no way to enforce a strict viewport layout that will always work. So now in my publish script (which publishes the work max file to a parent folder) I do some checks to make sure we’re cool with the viewport and the camera setting. It will fix the viewports to a certain point but if too much things don’t add up, too many camera’s for example it will bail out stating you’d better manually fix the viewports. Hopefully growing some awareness

@Polytools, sorta, but not quite. It’s also hard to get it right, because our conventions in naming and camera use may not necessarily be yours. I don’t always know the name of the camera and I want as less user interaction as possible in fixing things, I don’t assume a lot in my scripts, it is or it isn’t and if it isn’t the user fixes it, otherwise we’ll get into a heap of assumptions and exceptions etc.

Here’s a snippet from the script I use to enforce certain conditions while publishing the max file.


-- uncheck all hide by categories
hideByCategory.none()

-- exper mode off!
if cui.getExpertMode() then cui.expertModeOff()

-- Isolate mode off! max 2010 to 2013 only, 2014 things have changed... need to look into when using 2014
try destroyDialog Iso2Roll catch()

-- close render dialog
renderSceneDialog.close()

-- To make sure we can publish we have to setup the viewport
local viewportOK = true

-- unlock the renderer
rendUseActiveView = true

-- check for active cam
local activeCam = for n = 1 to viewport.numViews where (c = viewport.getCamera index:n) != undefined collect #(c,n)

-- if 1 camera is found we're cool!
if activeCam.count == 1 then
(
	-- set render view index
	viewport.activeViewport = rendViewIndex = activeCam[1][2]

-- now we're not cool
) else (
	-- no camera's then we assume it's an asset/prop so we don't flag it, otherwise, we abort!
	if cameras.count != 0 then
	(
		viewportOK = false
	)
)

if viewportOK then
(
	-- continue
)

-Johan

Johan,

It is unclear for me what are you exactly looking for as well as if the script you provided is working or not for you, and if so what you would like to fix. Therefore, any attempt to help is probably going to fail. If it don’t fail is just by pure coincidence.

You have a scene with 4 cameras but none is set to a viewport.
You have 1 viewport set to a 1 out of 4 cameras, but it is not the active viewport.
You have 2 viewports set to 2 out of 4 cameras.
You have only 1 camera in the scene but it was not assigned to any of the viewports.
You have 1 camera set to 1 viewport, but the active viewport is the top view, and it is maximized.

Are these situations something you are dealing with and need to take some specific action?

For instance, the following code will collect all viewports set to a camera, regardless if they are active or not or if any viewport has been maximized. But again, I don’t know if this will help.

(
  fn getViewportsCamera =
  (
  	for i = 1 to 4 where (viewport.getType index:i) == #view_camera collect #(viewport.getCamera index:i, i)
  )
  )

Jorge

maybe you can use this:
viewport.getType()

if (viewport.getType()) == #view_camera) then
(

do whatever
)
else
(return false)

it’s exposed to the sdk, if you have mxs extension sdk project the following will expose it to mxs…

//********************************************************************************************
 // IsViewportMaxed 
 
 def_visible_primitive(IsViewportMaxed, "IsViewportMaxed");
 
 Value* IsViewportMaxed_cf(Value **arg_list, int count)
 {
 	check_arg_count(IsViewportMaxed, 0, count);
 	return bool_result(MAXScript_interface->IsViewportMaxed());
 }

or add it to the project mxsagni and file viewport.cpp in the samples

 JHN

After python c++ + sdk is next on my list
Good to know though!

Thanks,
-Johan

During my experiments to create plugins without the use of C++ (I don’t know C++), I’ve started looking the Autodesk.Max.dll (I have some C# experience). Unfortunately with this wrapper you can’t create plugins but during my experiments I’ve started exposing some SDK functionality by creating DLLs and loading them with dotNet.loadAssembly. Lately I’ve realized that this dll (Autodesk.Max.dll) is already loaded in 3dsMax and that you can expose those functions/properties directly from 3dsMax’s SDK to MaxScript.

So for example, if there is a property,function exposed in the SDK that MaxScript doesn’t supports it, the easiest way to convert Klunk’s code would be.


gbl= (dotNetClass "Autodesk.Max.GlobalInterface").Instance
gbl.COREInterface.IsViewportMaxed

Hope that helped,
Nick

 JHN

That’s awesome, really!
Too bad I’m on max 2010 still…

But again very good too know!

-Johan

Page 1 / 3