Notifications
Clear all

[Closed] Can select camera via script in this way?

Hi,
Is it possible to select a scene camera via script ?for example,there 3 camreas in a scene ,of course we can select 1 camera via

select $Camera002

but I want to know how can select it by Select Camera dialog via script?

5 Replies

Where you have the cameras in your script? In a array. I think I don’t understand exactly your question, sorry. You will build your own camera list tool?

There is a system variable: “cameras”, this is a array and in that you can select a camera like:

select cameras[2]

Or:


 camName = Camera002
 for i = 1 to cameras.count do (
 if cameras[i].name == camName do (
 select cameras[i]
 )
 )
 
2 Replies
(@momo2012)
Joined: 11 months ago

Posts: 0

Thanks jb-alvarado,I want to turn Perspertive to Camera viewport,like in 3dsmax,press “C” key to select a camera ,then the viewport would change to camera viewport,the question is ,to do that ,need to select a camera in list,right?so my question is how to make it via script.your script is simple and works fine,but I don’t know how to do the important last step-after I select a camera ,how to change the viewport to camera viewport?

(@momo2012)
Joined: 11 months ago

Posts: 0

My goal is change the currnet Front or perspective(whatever) to camera viewport,we can do it in 3dsmax manual
1.Press “C” key as I said,the will appear a dialog to select camera
2.Select one you will switch,then the current viewport changes to camera viewport

It will works fine via script like this:

execute("select $"+cameras[1].name)  --select a camera,if it exsit
max vpt camera  --change current viewport to camera viewport

But,if the camera grouped with other objects,before it changes to the camera viewport,the select camera dialog will appear ,let you choose one.
I know someone can tell ,why not ungroup it ,then select a camera?I don’t want to do that is the reason if you have a big scene ,if you ungroup ,some objects will move to a new position,so try to avoid it ,I need a way to handle camera viewport without ungroup.

So I am going to know ,how to do that via script,sorry for my first question was not clearly

You find it in the maxscript help:
http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/index.html?url=files/GUID-8AA71F9E-F4F0-4437-A44E-9683619E89D-1999.htm,topicNumber=d28e671593

viewport.setCamera <camera_or_light_node> 
Sets the active viewport to a Camera view, using the specified camera.
You can also set the active view to a Light view using a free, target or direct light.
1 Reply
(@momo2012)
Joined: 11 months ago

Posts: 0

Too much too much thanks,it works!!!whatever the cameras in a group!

viewport.setCamera $Camera002