View Full Version : Script to change cam controls

12 December 2006, 11:25 AM
Hey guys.

I was wondering if anybody knows a script that will change a camera from being just a camera, to a camera and aim? (the option box is at the top of the cam attributes window.)

I''ve looked through the code that executes when you change that value, but can't find anything concrete.

Ideally I need to query the current cam type, and change it to cam and aim if needed.

If anybody has any ideas it'd be much appreciated :thumbsup:

Dr Merman

12 December 2006, 11:45 AM
select your cameras transform node and type this:

cameraMakeNode 1 "";

= camera

cameraMakeNode 2 "";

= camera and aim

cameraMakeNode 3 "";

= camera, aim and up

12 December 2006, 01:19 PM
Brilliant! :thumbsup: Thanks mate.

12 December 2006, 02:08 PM
Hey again, another quick question. I'm currently using the following to get the current cam name:

string $currentPanel = `getPanel -withFocus`;
string $currentCam;

if ($currentPanel == "")
//no camview active
print "/nActivate the relevant viewport";

string $currentCam;
$currentCam = `modelPanel -q -cam $currentPanel`;
string $currentCamRelatives[] = `listRelatives $currentCam`;
string $currentCamShape = $currentCamRelatives[0];

mySeperateProc $currentCam $currentCamShape;

However if say the outliner or hypershade is the window with focus, the code throws out an error, because obviously, they aren't cameras. Is there any way to restrict this script to just picking out the modelpanels, or cameras? It seems that the first part of the if statement is missing something.

Dr Merman

12 December 2006, 02:45 PM
I found my mistake in the above code. It should have been getPanel -underPointer, not -withFocus.

12 December 2006, 03:17 PM
I smell Maxwell Render as the target of this script. :D I have the demo and tried the latest Maya plug-in update to try it out. They did a good job in integrating it, although it has some bugs (after using the Arroway sample textures it produced errors).

Personally I'm not fond of the camera and aim method of framing and focusing. According to most resources I've read on artistic photography they recommend to avoid putting your subject in the dead center. I guess the camera and aim is good for product/technical photography.

Anyhow, I made my own shelf script (although Maxwell has completely de-shelved itself) to automatically focus the Maxwell camera on a specified point (typically a Locator). Simply select a Locator from the desired camera view and execute. The focus distance will be auto-attached to that point, so focusing can be precise and specific. If you are interested...{// Attach active Maxwell camera focus distance to selected item
string $curSelA[] = `ls -sl -type transform`;
if (size($curSelA) != 1)
error "Select one transform node as focus point (ex.: a Locator)";
string $curPanel = `getPanel -wf`;
if (`getPanel -to ($curPanel)` != "modelPanel")
error "Make sure the camera's panel is active (ex.: persp)";
string $curCamT = `modelPanel -q -cam ($curPanel)`;
string $curCamA[] = `listRelatives -c -type camera ($curCamT)`;
string $curCam = $curCamA[0];
string $curConnA[] = `listConnections ($curCam+".mxFocusDistance")`;
if (size($curConnA) != 0) {
string $dbA[] = `ls -type distanceBetween ($curConnA[0])`;
if (size($dbA) != 1) error "Camera's focus distance already has another connection";
connectAttr -f ($curSelA[0]+".translate") ($dbA[0]+".point2");
else {
string $db = `shadingNode -asUtility distanceBetween`;
connectAttr -f ($db+".distance") ($curCamT+"|"+$curCam+".mxFocusDistance");
connectAttr -f ($curCamT+".translate") ($db+".point1");
connectAttr -f ($curSelA[0]+".translate") ($db+".point2");
select -r ($curSelA[0]);

CGTalk Moderation
12 December 2006, 03:17 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.