//STEP 6:
string $sub = $obj + "_subSpheres";
attachSubFiguresToFaces($obj, $sub_figure, $sub);
  
//PROC: Attach subSphere to each face of main object
global proc attachSubFiguresToFaces(string $obj, string $sub_figure, string $subSpheres){
    $arrayFace = `polyEvaluate -f $obj`;
    int $fId;
    string $mashGrp[];
    for($fId=0; $fId<$arrayFace[0]; $fId++){
        vector $temp = getFaceCenter($obj, $fId);
        string $name = $obj + "_" + $sub_figure + ($fId+1);
        string $cmd[] = `duplicate -n $name $sub_figure`;
        $mashGrp[$fId] = $cmd[0];
        xform -pivots 0 0 0 $name;
        float $a[] = aimY($temp);
  
        select $name;
        move ($temp.x) ($temp.y) ($temp.z);
        rotate -r $a[0] 0 0;
        rotate -r 0     0 $a[1];
    }
  
    select -r $mashGrp[0];
    for($fId=1; $fId<$arrayFace[0]; $fId++){
        select -tgl $mashGrp[$fId];
    }
    group -n $subSpheres;
    delete $sub_figure;
}
  
//PROC: Return vector information of middle of each face
global proc vector getFaceCenter(string $obj, int $faceId){
    select $obj;
    string $objName = $obj + ".f[" + $faceId +"]";
    //Query vector information for one particular face
    float $results[] = `xform -q -ws -t $objName`;
    int $vertexCount = size($results)/3;
    
    int $i, $j, $h;
    vector $vec[];
    float $newVec[];
    //Average all vector information to get center value.
    for($i=0; $i<3; $i++){
        float $tempNum;
        for($h=0; $h<$vertexCount; $h++){
            $tempNum += $results[$h*3+$i];
        }
        float $val = $tempNum/$vertexCount;
        $newVec[$i] = $val;
    }
    //Return center of the face
    vector $faceCenterPnt = <<$newVec[0], $newVec[1], $newVec[2]>>;
    return $faceCenterPnt;
}