Script to display an Attribute in the Channel Box as keyable?

Script to display an Attribute in the Channel Box as keyable?

BenediZ
Collaborator Collaborator
1,082 Views
8 Replies
Message 1 of 9

Script to display an Attribute in the Channel Box as keyable?

BenediZ
Collaborator
Collaborator

Hello,

there is a frequent task I have to do:

Always to set the ISO of an camera on "keyable" in the Channel Box, so that I can access that attribute in the channel box.

 

I tried to script this, but I have no deep knowledge. Please help, how to do it right:

string $Cameras[] = `ls -sl -fl`; // storing the camera

// I have actually to select the shape of the camera, ho to do this?
setAttr $Cameras -k on  vrayCameraPhysicalISO; // this only gives an syntax error. Itried different other possibilities, which also didn't work

 

The desired attribute is called "MyCameraname.vrayCameraPhysicalISO"

Echo commands gave me this:

PS_moveToKeyable Keyable RenderCam;
setAttr -k on |Group_of_cameras|RenderCam|RenderCam.vrayCameraPhysicalShutterSpeed;
button -e -en 1 KEYABLE_Button; button -e -en 1 NONKEYABLE_Button; textScrollList -e -da KEYABLE_List; textScrollList -e -da DISP_NONKEYABLE_List;

 

Thanks for help!

 

1,083 Views
8 Replies
  • MEL
Replies (8)
Message 2 of 9

mcw0
Advisor
Advisor

WOW, what you posted looked really overwhelming.  To make any attribute keyable in the channel box:

setAttr -e -k 1 -cb 1 ($obj+"."+$attr);

Message 3 of 9

BenediZ
Collaborator
Collaborator

Many thanks @mcw0 , I will test it next time!

Message 4 of 9

BenediZ
Collaborator
Collaborator

Hi, it did not work, because of Error: Illegal operation "+" on data of type string[].

I have tested those first two lines:

string $myCamera[] = `ls -sl`; // storing the camera
print ($myCamera"."+"vrayCameraPhysicalISO");

 

setAttr -e -k 1 -cb 1 ($myCamera+"."+"vrayCameraPhysicalISO");

 

There must be another way to get the attribute name "spelled" with MEL.

Thanks for help

Message 5 of 9

brentmc
Autodesk
Autodesk

 

There are some typos in the script. Also, ls returns a list so you need to pull out the first item which is the error you are getting.

 

Note: you should also check the size($myCamera) to make sure it is greater than 0 before trying to access the list.

string $myCamera[] = `ls -sl`; // storing the camera
print ($myCamera[0]+".vrayCameraPhysicalISO");

 

 

--

Brent

Brent McPherson
Principle Engineer
Message 6 of 9

BenediZ
Collaborator
Collaborator

Right, but the typo was only here in the forum. Look here the  result without typo:

string $myCamera[] = `ls -sl`;
print ($myCamera+"."+"vrayCameraPhysicalISO");
// Error: print ($myCamera+"."+"vrayCameraPhysicalISO"); //
// Error: Line 2.21: Illegal operation "+" on data of type string[]. //

0 Likes
Message 7 of 9

brentmc
Autodesk
Autodesk

I updated my original reply.

 

Some commands like ls return a list so you need to pull out the item you are interested in.

--

Brent

Brent McPherson
Principle Engineer
Message 8 of 9

BenediZ
Collaborator
Collaborator

Great, it works:

pickWalkDown; // in order to select the shape of the camera
string $myCamera[] = `ls -sl`;
setAttr -e -k 1 -cb 1 ($myCamera[0]+"."+"vrayCameraPhysicalISO");

0 Likes
Message 9 of 9

bmagner888
Enthusiast
Enthusiast

you can also batch the process by using an array and consoildate steps if you need to do this with more than one attribute.
string $obj = "someObjectName" //enter an object name or query from selection (`ls -sl`)
string $atts=["vrayCameraPhysicalISO", "someOtherAttr", "anotherAttr"] //etc.
//loop through list and apply all
for ($att in $atts){   
    //only proceed if attribute actually exists on object (avoids errors)

    if (`attributeExists $att $obj`) { setAttr -e -k 1 -cb 1 ($obj+"."+$att); }

}

0 Likes