As pointed out by @theodox. You should never rely on Maya setting the name you told it to set. Because if Maya has a naming clash, etc. than maya will override you so whenever you create something always catch the name. So for example
polyExtrudeFacet -n $outNameExtrude
-ch 1 -keepFacesTogether 1
-pvx 0 -pvy 0 -pvz 4.0 $outName;
Should be:
$tmp = `polyExtrudeFacet -n $outNameExtrude
-ch 1
-keepFacesTogether 1
-pvx 0 -pvy 0 -pvz 4.0
$outName` ;
$outNameExtrude = $tmp[0];
This saves you form Maya blowing up in your face. So your code would look like:
proc makeCubesDrivenBy(
string $controlName, int $totalObjects, float $spacing
){
for($i=1;$i<=$totalObjects;$i++)
{
string $tmp[];
string $outName = ("twist_"+ $i);
string $outNameExtrude = ("ext_"+$i);
float $extrusion = 0;
$tmp = `polyCube -n $outName -ch 1
-o on -w 12.009218
-h 7.720124 -d 0.755927
-cuv 4`;
$outname = $tmp[0];
setAttr ($outName+".translateZ") ($spacing*$i);
$tmp = `polyExtrudeFacet -n $outNameExtrude
-ch 1
-keepFacesTogether 1
-pvx 0 -pvy 0 -pvz 4.0
$outName` ;
$outNameExtrude = $tmp[0];
setAttr ($outNameExtrude + ".localTranslate")
-type double3 0 $extrusion 0 ;
expression -s ( $outNameExtrude + ".tz" +
"= Rotator.rotateY * 0.01*" +
($i*0.5) + ";") -o ""
-ae 0 -uc all ;
}
}
{
string $pipe[], $facet[];
int $totalObjects = 1;
$pipe = `polyPipe -n Rotator -ch 1
-o on -r 1.839239
-h 1.223879` ;
$facet = `polyExtrudeFacet -ch 1 -keepFacesTogether 1
-pvx 0.07364761256
-pvy 0.6119394158
-pvz 4.019784712
-divisions 1 -twist 0
-taper 1 -off 0
-smoothingAngle 30 Rotator.f[36]`;
setAttr ($facet[0] + ".localTranslate")
-type double3 0 0 0.930651 ;
makeCubesDrivenBy($pipe[0], 1 , 1.5);
}
Anyway the process itself isnt really sane as you copy history inputs but I can not really guess what you are after.
PS: dont use -ae 1 in expressions unless you really have to, and you dont.