Hi all:
I'm writing a script to create a 2D array of instances of a selected object. I've been able to get the code to run when executing individual sections, and the proc compiles, but when I try to run it, Maya hangs. Can anyone see why?
CODE
global proc pixl_instanceArray ()
{
// Create Parent for instances
string $instancePrntTmp[] = spaceLocator -n "inst\_prnt"
;
string $instancePrnt = $instancePrntTmp[0];
// Select object
string $selTmp[] = ls -sl
;
string $objToInstance = $selTmp[0];
// Get bounding box, including invisible children:
float $xFormBBTmp[] = xform -q -bbi $objToInstance
;
// Calc X & Z Dimensions:
float $selXDim = abs($xFormBBTmp[1] - $xFormBBTmp[0]);
float $selZDim = abs($xFormBBTmp[5] - $xFormBBTmp[4]);
int $numXInstances = 10;
int $numZInstances = 10;
float $xOffset = $selXDim + $selXDim/2;
float $zOffset = $selZDim + $selZDim/2;
//*** create the instances ***//
for ($i = 1; $i <= $numXInstances; $i++)
{
for ($k = 1; $k <= $numZInstances; $k++)
{
$instanceName = `instance -name ($objToInstance + "X\_" + $i + "Z\_" + $k) $objToInstance`;
setAttr ($instanceName[0] + ".translateX") ($i * $xOffset);
setAttr ($instanceName[0] + ".translateZ") ($k * $zOffset);
parent $instanceName[0] $instancePrnt;
}
}
}
}
pixl_instanceArray();
Also, when I use instance, it returns a string, which is the name of the new node. However, in order to address the instance, bracket notation is required, as if addressing a string[] - why? ie:
CODE
int $i = 1;
int $k = 7;
float $xOffset = 3;
$instanceName = instance -name ($objToInstance + "X\_" + $i + "Z\_" + $k) $objToInstance
;$instanceName = instance -name ($objToInstance + "X\_" + $i + "Z\_" + $k) $objToInstance
;
setAttr ($instanceName[0] + ".translateX") ($i * $xOffset); // Works
setAttr ($instanceName + ".translateX") ($i * $xOffset); // Fails:
// Error: Line 3.41: Illegal operation "+" on data of type string[]. //
Thanks.