Script wanted: Set view to the last camera used

Many times I have my viewport with a certain camera (lets call it Cam01). Then I need to change the viewport to top, left, etc, and I always wish I could go back to the camera I was before, without having to select it first.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lupaz's picture

I just wanted to thank you

I just wanted to thank you again. I'm using this every day and works really well.

lupaz's picture

It works very nicely. Thanks!

It works very nicely. Thanks!

jahman's picture

.

try this:

callbacks.removeScripts #viewportChange id:#LastCameraUsed
 
global LastCameraUsed = undefined
 
fn OnViewportChange = 
(
	local cam = getActiveCamera()
 
	if cam != undefined do LastCameraUsed = cam	
 
)
 
callbacks.addScript #viewportChange "OnViewportChange()" id:#LastCameraUsed
 
 
-- Customize > Jahman > 'Switch To Last Used Camera'
macroScript SwitchToLastUsedCamera
category:"Jahman"
tooltip:"Switch To Last Used Camera"
(	
	try
	(
		viewport.SetCamera ::LastCameraUsed
	)
	catch()	
)

if it works as expected, save this script in startup scripts folder
C:\Users\User\AppData\Local\Autodesk\3dsmax\<max_version>\ENU\scripts\startup

And bind it to any key combination you like.
Customize > Jahman > 'Switch To Last Used Camera'

lupaz's picture

Hi Jahman, I installed 3DS

Hi Jahman,

I installed 3DS Max 2025.1 and now the script returns "An error occurred while switching to the last camera." even though it did change to the last camera.
Do you know what could be wrong?

Hope you are still around.

lupaz's picture

Sorry. Nevermind. I installed

Sorry. Nevermind. I installed it from scratch and now it works.
Hope you're doing well.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.