Hallo
I am working on my own tank tread creation script. I know that there is one allready made, which works really great, but I want to make my own for learning purpose and I want to add some more options and control.
My problem here is the for() loop, as long as it it $i < 1 it works perfect, but if I increase it (eg. $i < 2) it returns this error:
CODE
Error: Attribute already controlled by an expression, keyframe, or other connection: TankTreadAnimationPath_0.uValue
The problem is in this line, as if I comment it out the script works:
CODE
$expr += (""+$pathAnimation+".uValue=fmod(((time*$speed)+("+$distance+"*"+$i+")),1)"+";\n");
I have looked at it for so long now, and I cant find out what I am doing wrong so I am in desperate help for some help.
Also, as I am still learning and other obvius misstakes in the script would be great to know about
How to use it:
Set path = a nurbs curve
set object = a object
CODE
//***************************************************************
// Information
//***************************************************************
// Name: TankTreadGenerator
// Date: Pending
// Version:
//
//
// Author: Ole Kristian H. Homelien
// Mail: Ole_Kristian92@hotmail.com
//
//***************************************************************
//
// Description:
//
//
// Installation:
//
//
//
// How to Use:
//
//
//***************************************************************
//*******************************************************
//*******************************************************
// Programing starts here, modefy at own risk
//*******************************************************
//*******************************************************
//***************************************************************
//Proccedure for making the UI
//***************************************************************
global proc OKHH_TankTreadGeneratorUI()
{
//***************************************************************
//create the UI
//***************************************************************
//Create the window
string $window;
if (window -exists myWin)deleteUI myWin;
$window = window -title "OKHH\_TankTreadGenerator Beta";
-widthHeight 300 200
myWin
//create formLayout
formLayout myForm;
//---------Content
textField objectTF;
textField pathTF;
text -label "Choose a orientation for the project:" orientationText;
button -l "Set object" -command "OKHH_TankTreadGeneratorAddtoTextFieldObject()" objectButton;
button -l "Set path" -command "OKHH_TankTreadGeneratorAddtoTextFieldPath()" pathButton;
button -label "OK" -command "OKHH_TankTreadGeneratorMain()" okButton;
button -label "Close" closeButton;
checkBox -label "Copy" -align "left" copyBox;
checkBox -label "Instance" -align "left" InstanceBox;
checkBox -label "Dynamic" -align "left" DynamicBox;
checkBox -label "X" -align "left" Xbox;
checkBox -label "Y" -align "left" Ybox;
checkBox -label "Z" -align "left" Zbox;
//---------Content
//---------Edit
formLayout -e
-attachForm objectTF left 0
-attachForm objectTF top 0
-attachPosition objectTF right 0 75
-attachForm objectButton right 0
-attachControl objectButton left 0 objectTF
-attachForm objectButton top 0
-attachControl pathTF top 0 objectTF
-attachForm pathTF left 0
-attachPosition pathTF right 0 75
-attachForm pathButton right 0
-attachControl pathButton top 0 objectTF
-attachControl pathButton left 0 pathTF
-attachForm copyBox left 0
-attachControl copyBox top 10 pathTF
-attachForm InstanceBox left 0
-attachControl InstanceBox top 0 copyBox
-attachForm DynamicBox left 0
-attachControl DynamicBox top 5 InstanceBox
-attachForm orientationText left 0
-attachControl orientationText top 5 DynamicBox
-attachForm Xbox left 0
-attachControl Xbox top 0 orientationText
-attachPosition Xbox right 0 33
-attachControl Ybox left 0 Xbox
-attachControl Ybox top 0 orientationText
-attachPosition Ybox right 0 66
-attachControl Zbox left 0 Ybox
-attachControl Zbox top 0 orientationText
-attachPosition Zbox right 0 100
-attachForm okButton left 0
-attachControl okButton top 7 Xbox
-attachPosition okButton right 0 50
-attachControl closeButton left 0 okButton
-attachControl closeButton top 7 Xbox
-attachForm closeButton right 0
myForm;
//---------Edit
//Show the window
showWindow $window;
//***************************************************************
//End of UI
//***************************************************************
}
//***************************************************************
//Proccedure for adding the object to the
//TextList for later use
//***************************************************************
global proc OKHH_TankTreadGeneratorAddtoTextFieldObject()
{
string $object[]= ls -sl -flatten;
int $noOfObjects = size($object);
if ($noOfObjects == 1)
{
print "\nObject added to the textField";
textField -e -text $object[0] objectTF;
}
else if ($noOfObjects == 0)
{
print "\nYou have to select one object!";
}
else if ($noOfObjects > 1)
{
print "\nPlease select only one object!";
}
}
//***************************************************************
//Proccedure for adding the path object to the
//TextList for later use
//***************************************************************
global proc OKHH_TankTreadGeneratorAddtoTextFieldPath()
{
string $object2[]= ls -sl -flatten;
int $noOfObjects2 = size($object2);
if ($noOfObjects2 == 1)
{
print "\nPath object added to the textField";
textField -e -text $object2[0] pathTF;
}
else if ($noOfObjects2 == 0)
{
print "\nYou have to select one object to use as the path!";
}
else if ($noOfObjects2 > 1)
{
print "\nPlease select only one object to use as the path!";
}
}
//***************************************************************
//Proccedure for adding the treads to the tank
//And to automate the animation
//***************************************************************
global proc OKHH_TankTreadGeneratorMain()
{
//***************************************************************
//---------Read information from the UI
//***************************************************************
string $object = textField -q -text objectTF;
string $pathCurve = textField -q -text pathTF;
int $onOrOffCopy = checkBox -q -v copyBox;
int $onOrOffInstance = checkBox -q -v InstanceBox;
int $onOrOffDynamicBox = checkBox -q -v DynamicBox;
int $onOrOffXbox = checkBox -q -v Xbox;
int $onOrOffZbox = checkBox -q -v Zbox;
int $onOrOffYbox = checkBox -q -v Ybox;
//***************************************************************
//---------Read information from the UI
//***************************************************************
//***************************************************************
//---------Error checking
//***************************************************************
if ($onOrOffInstance == 1 && $onOrOffCopy == 1)
{
warning("You cant have both copy and instances, pick One!");
//Break
}
if ($onOrOffInstance == 0 && $onOrOffCopy == 0)
{
warning("You have to select copy or instance");
//Break
}
if ($object == "")
{
warning("You must select a object to be used in this script!");
//Break
}
if ($pathCurve == "")
{
warning("You must select a path curve to be used in this script!");
//Break
}
if (($onOrOffXbox + $onOrOffYbox + $onOrOffZbox) != 1 )
{
warning("You can not have two project orientations, pick One!");
//break
}
//***************************************************************
//---------Error checking
//***************************************************************
//***************************************************************
//---------Find the lenght and orientation of the curve and the object
//***************************************************************
string $orientation;
float $objectLength;
//Length of the curve
float $lengthCurve = arclen -ch 0 $pathCurve;
//Orientation of the project
if ($onOrOffXbox ==1)
$orientation = "X";
if ($onOrOffYbox ==1)
$orientation = "Y";
if ($onOrOffZbox ==1)
$orientation = "Z";
//Length of the object
float $objectBoundingBox[] = exactWorldBoundingBox $object;
if ($orientation == "X")
{
$objectLength = abs($objectBoundingBox[0] - $objectBoundingBox[3]);
}
if ($orientation == "Y")
{
$objectLength = abs($objectBoundingBox[1] - $objectBoundingBox[4]);
}
if ($orientation == "Z")
{
$objectLength = abs($objectBoundingBox[2] - $objectBoundingBox[5]);
}
//Number of objects needed to cover the curve:
float $noOfObjects = $lengthCurve / $objectLength;
int $realAmountObjects = $noOfObjects;
float $gapBetweenObjects = ($noOfObjects - $realAmountObjects) / $realAmountObjects;
//***************************************************************
//---------Find the lenght and orientation of the curve and the object
//***************************************************************
//***************************************************************
//---------Make the treads and set up the animation
//***************************************************************
//Making an animation control
select $pathCurve;
xform -cp $pathCurve;
float $pathCurveCenter[] = xform -q -ws -piv;
string $animationControl[] = spaceLocator -p 0 0 0;
addAttr -ln SpeedControl -at double ("|"+$animationControl[0]);
setAttr -e -keyable true ("|"+$animationControl[0]+".SpeedControl");
xform -translation $pathCurveCenter[0] $pathCurveCenter[1] $pathCurveCenter[2] $animationControl[0];
//Parent the animation control to the pathCurve
//parent $pathCurve $animationControl[0];
//-------Animate the treads
for($i = 0; $i < 2; $i++)
{
select $object;
//duplicate the tread
if($onOrOffCopy == 1)
{
duplicate -rr;
}
if($onOrOffInstance == 1)
{
instance;
}
//Make a path animation
string $newObject[0] = ls -sl;
string $objectCopy = $newObject[0];
string $pathAnimation = pathAnimation -fractionMode false ;
-follow true
-followAxis x
-upAxis y
-worldUpType "vector"
-worldUpVector 0 1 0
-inverseUp false
-inverseFront false
-bank false
-startTimeU 1
-endTimeU 150
-n ("TankTreadAnimationPath\_"+$i+"")
-c $pathCurve $objectCopy
//delete the pre-made connection
select $pathAnimation;
CBdeleteConnection ("TankTreadAnimationPath_"+$i+".u");
//Calculate the distance between each thread object
//Stuff
print"\n";
print $pathAnimation;
print "\n";
print $objectCopy;
float $distance = 0.3;
//Make a new connection
string $expr ="";
$expr += ("float $speed = "+$animationControl[0]+".SpeedControl"+";\n");
$expr += (""+$pathAnimation+".uValue=fmod(((time*$speed)+("+$distance+"*"+$i+")),1)"+";\n");
//uValue is connected to the pathAnimation
expression -s $expr
-o $pathAnimation
-ae 1
-uc all;
}
//$object
//$pathCurve
//***************************************************************
//---------Make the treads and set up the animation
//***************************************************************
}