How to reliably get the render camera when viewport layouts change?

How to reliably get the render camera when viewport layouts change?

maxZU8TS
Participant Participant
699 Views
4 Replies
Message 1 of 5

How to reliably get the render camera when viewport layouts change?

maxZU8TS
Participant
Participant

I have a MaxScript tool that retrieves the render camera using the following code:

 

 
fn getRenderCamera = ( viewport.getCamera index:rendViewIndex )
 

This works only as long as the viewport layout stays the same.
If a colleague changes the viewport configuration (for example switching from 1 view to 4 views), then the viewport indexes change, and rendViewIndex no longer points to the same viewport.

This causes two problems:

  1. The script sometimes throws an error because the index no longer corresponds to a camera viewport.

  2. In other cases it returns a completely different camera, because another viewport now occupies that index.

Is there a more reliable way to get the active camera via maxscript? Or do I have to tell my team to only work in one viewport layout? I haven't found any other method so far..

0 Likes
Accepted solutions (1)
700 Views
4 Replies
Replies (4)
Message 2 of 5

miauuuu
Collaborator
Collaborator
getActiveCamera()
https://miauu-maxscript.com/
0 Likes
Message 3 of 5

maxZU8TS
Participant
Participant

GetActiveCamera returns the camera of whichever viewport is active. the active viewport does not always equal the locked render view so this doesn't work. In the screenshot below you can see i use getActiveCamera() and the listener returns undefined. Even though my "view to render" is locked to Quad 4 - Corona Camera017.

 

rendviewIndex is supposed to return the index of "view to render" and it works, but when the viewport layout is changed, so does the order of the rendviewindex and it won't return the correct camera/view anymore. Can someone please adress this? 

 

Here below you can see getActiveCamera doesn't correspond with view to render if a different viewport is clicked:

maxZU8TS_0-1765460947260.png


And in this screenshot you can the first part of the listener returning the camera correctly using viewport.getCamera index:rendViewIndex
And in the second part of the listener you can see the error that occurs when i change the viewport layout and try to run the same function again

maxZU8TS_1-1765462811942.png

 

0 Likes
Message 4 of 5

A娘
Advocate
Advocate
Accepted solution

rendViewIndex should get at the correct layout tab , if not it will return undefined , so you should search all tabs , example below

fn getrendercamera =
(
	for i = 1 to ViewPanelManager.GetViewPanelCount() do 
	(
		ViewPanelManager.SetActiveViewPanel i
		if rendViewIndex != undefined do
			exit with (viewport.getCamera index:rendViewIndex)
	)
)

 

Message 5 of 5

maxZU8TS
Participant
Participant

Thank you so much, this solved it. 

I think it's unintuitive to not have a single function that returns the locked camera. Especially since its something you might want to do more often. but many thanks! 

0 Likes