Hello everyone,
first time posting here and I would really appreciate your help.
I’m writing one of my first scripts in MEL and I encountering a problem. The idea of the script is that you can select a chain of FK-Controllers (like a tail for example) bake them to locators that are connected with constraints so you can animate these in worldspace and bake them back.
Both Script parts work allright when I execute them seperatly but when I try to access them with the UI I wrote Maya gives me this error for the first script:
// Error: line 0: No object matches name: //
Can anyone tell me where the error happens? I’m quiet lost because it’s telling me it’s the line 0
This is the script:
if ( `window -exists globalfkcontrols` ) {
deleteUI globalfkcontrols; // delete window when it exists
}
window -t "FK-Offset" globalfkcontrols;
columnLayout MyMainCol;
text -label "Select FK-CTRLs in order and hit the button" -al "center";
button -l "Create Global FK-CTRLs" -w 500 -h 70 -command "CreateGlobalFK()";
button -l "Bake back to CTRLs" -w 500 -h 70 -command "BakeBack()";
showWindow globalfkcontrols;
window -e -wh 500 160 globalfkcontrols;
global string $group[];
global string $controlers[];
proc CreateGlobalFK()
{
$controlers = `ls -sl`;
//Creates Locators and Childlocators for every controller and constraints them to the controller
for ($i = 0 ; $i < `size $controlers`; $i++)
{
group -em -w -name ($controlers[$i] + "_Global_Grp");
string $group[] = `ls -sl`;
spaceLocator -p 0 0 0 -name ($controlers[$i] + "_Parent_Loc");
string $parentloc[] = `ls -sl`;
parent $parentloc $group;
select -cl;
select -r $controlers[$i];
select -add $group;
doCreatePointConstraintArgList 1 { "0","0","0","0","0","0","0","1","","1" };
pointConstraint -offset 0 0 0 -weight 1;
doCreateOrientConstraintArgList 1 { "0","0","0","0","0","0","0","1","","1" };
orientConstraint -offset 0 0 0 -weight 1;
spaceLocator -p 0 0 0 - name ($controlers[$i] + "_Child_Loc");
string $childloc[] = `ls -sl`;
parent $childloc $parentloc;
select $childloc;
setAttr ($childloc[0] + ".rotateX") 0;
setAttr ($childloc[0] + ".rotateY") 0;
setAttr ($childloc[0] + ".rotateZ") 0;
setAttr ($childloc[0] + ".translateX") 0;
setAttr ($childloc[0] + ".translateY") 0;
setAttr ($childloc[0] + ".translateZ") 0;
}
select "*_Global_Grp";
string $group[] = `ls -sl`;
{string $locs[] = eval("listRelatives -p `ls -type locator \"*Parent_Loc*\"`"); select $locs;}
string $parentloc[] = `ls -sl`;
{string $locs[] = eval("listRelatives -p `ls -type locator \"*Child_Loc*\"`"); select $locs;}
string $childloc[] = `ls -sl`;
//Creates the Aim constraints between locators to imitate FK-behaviour
string $last[] = `ls -sl -tail 1`;
string $all_except_last[] = stringArrayRemove(`ls -sl -tail 1`, `ls -sl -fl`);
for ($i = 0; $i < `size $all_except_last`; $i++)
{
select -r $childloc[$i+1] ;
select -add $childloc[$i] ;
doCreateAimConstraintArgList 1 { "0","0","0","0","1","0","0","0","1","0","0","1","0","1","object","$parentloc[$i]","0","0","0","","1" };
aimConstraint -offset 0 0 0 -weight 1 -aimVector 1 0 0 -upVector 0 1 0 -worldUpType "object" -worldUpObject $parentloc[$i];
}
// Creates Aim Constraint for last segment
select -r $childloc[(`size $childloc`-2)];
select -add $last ;
doCreateAimConstraintArgList 1 { "0","0","0","0","-1","0","0","0","1","0","0","1","0","1","objectrotation","$parentloc[(`size $childloc`-1)]","0","0","0","","1" };
aimConstraint -offset 0 0 0 -weight 1 -aimVector 0 -1 0 -upVector 0 1 0 -worldUpType "objectrotation" -worldUpVector 0 1 0 -worldUpObject $parentloc[(`size $childloc`-1)];
// Bakes the Parent_Locator
float $minTime = `playbackOptions -q -minTime`;
float $maxTime = `playbackOptions -q -maxTime`;
bakeResults -simulation true -t ($minTime + ":" + $maxTime) -sampleBy 1 -oversamplingRate 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true $group;
select $group;
filterCurve;
delete "*_Global_Grp_pointConstraint*";
delete "*_Global_Grp_orientConstraint*";
// Constraints the Controllers to the locators
for ($i = 0; $i < `size $childloc`; $i++)
{
select -r $childloc[$i];
select -tgl $controlers[$i] ;
doCreateParentConstraintArgList 1 { "0","0","0","0","0","0","0","0","1","","0" };
parentConstraint -weight 1;
}
hide "*Child_Loc*";
select $group;
}
proc BakeBack()
{
global string $group[];
global string $controlers[];
float $minTime = `playbackOptions -q -minTime`;
float $maxTime = `playbackOptions -q -maxTime`;
bakeResults -simulation true -t ($minTime + ":" + $maxTime) -sampleBy 1 -oversamplingRate 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true $controlers;
delete $group;
}
Thank you for your help