Find out cameras in the scene


#1

I want to list all cameras in the scene and get them in a newly created window like
option menu.

window;
    columnLayout;
    
string $cam[] = `listCameras`;
    attrEnumOptionMenuGrp
            -l "Output Format"
            -ei 0 $cam ;
showWindow;

this is the code i have done but i am not getting list all cameras in the scene


#2

-ei is used to add an enum element, but you are only adding element 0. You need to add all the elements in the $cam array like this…

window;
columnLayout;  
string $cam[] = `listCameras`;
string $cmd = "attrEnumOptionMenuGrp -l \"Output Format\"";
for($i=0; $i < size($cam); $i++){
    $cmd += (" -ei " + $i + " " + $cam[$i]);
}
eval($cmd);
showWindow;

David


#3

Thnxs for giving reply…


#4

I have one more doubt when i am chaining cameras options in window how to update in render settings window,
for updating is there any command.


#5

attrEnumOptionMenuGrp is designed to be linked to an attribute value by using the “attribute” keyword. Then the state of the button is kept in sync with the attr, and you can then change it in your window or in the attr editor.

I think the problem you have is that there is no single attribute for the renderable camera. You might think there is when you look at the renderSettings window, because it looks like the attribute editor, but it is not. When you change the renderable camera in that window it sets the “renderable” attr on camera you chose from the list to ON, and sets it to OFF for the camera in the list that you replaced. In fact its a bit more complicated because you can have more than one renderable camera.

So if you are making a custom UI where you want to set the renderable camera, then attrEnumOptionMenuGrp is not going to be much use. What you should be doing is getting the camera list and building a menu with a menuItem for each camera, and associate a command with each menuItem to set the camera renderable attributes.

Alternatively you could build a series of check-boxes, one for each camera, which would have their change command linked to each camera. Have a look at the “defaultRenderGlobals” node in the attribute editor to see what I mean.

Have a look at some of the examples in the docs or in scripts on creativecrash that do similar things.

David