How do I key an attribute that’s constrained?

This solution only realy applies to ‘constrained’ attributes and not expression or other forms of driven control.

[Download]

 

proc keyConsAttrib(string $inputObjs[], string $attributes[], float $startTime, float $endTime, float $inc)
{
	float $curTime = currentTime("-q");

	for($eachObj in $inputObjs)
	{
		currentTime($startTime);

		for($eachAttr in $attributes)
		{
			string $fullAttr = ($eachObj + "." + $eachAttr);
			string $listConnResult[] = listConnections("-s", 1, $fullAttr);
			if(nodeType($listConnResult[0]) != "pairBlend")
			{
				
				setKeyframe($fullAttr);
				$listConnResult = listConnections("-s", 1, $fullAttr);
			}

			string $pairBlend = $listConnResult[0];

			$listConnResult = listConnections("-s", 1, "-p", 1, ($pairBlend + ".weight"));
			string $weightSource = $listConnResult[0];

			setAttr($weightSource, 1);


		}
	}
	currentTime($curTime);

	for($curTime = $startTime; $curTime <= $endTime; $curTime += $inc)
	{

		for($eachObj in $inputObjs)
		{
			for($eachAttr in $attributes)
			{
				string $fullAttr = ($eachObj + "." + $eachAttr);
				float $value = getAttr("-time", $curTime, $fullAttr);
				setKeyframe -time $curTime -value $value $fullAttr;
			}
		}
	}

}

Usage:

 

keyConsAttrib(ls("-selection", "-long"), {"tx","ty","tz","rx","ry","rz"}, 0, 30, 1);

[Download]

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *