Home Technical Talk

[Maya] Need help with setAttr and an array

ngon master
Offline / Send Message
throttlekitty ngon master
This snippet works, it's part of putting some blendShape targets into an existing group:
int $targetDir = 1;
setAttr blendShape1.targetDirectory[$targetDir].childIndices -type Int32Array 3 0 1 3;


But this doesn't, and I get an error, but I can't figure out why. I tried splitting the array size and array into two variables, but then the error changes to element number 4.
int $targetDir = 1;
int $otherInts[] = {3, 0, 1, 3};<br>setAttr blendShape1.targetDirectory[$targetDir].childIndices -type Int32Array $otherInts;<br>// Error: line 1: setAttr: Error reading data element number 3:&nbsp; //&nbsp;<br>

I'd rather use mel here, since all the Shape Editor interface is written in mel.

Replies

  • throttlekitty
    Offline / Send Message
    throttlekitty ngon master
    Ok, still no idea why I can't pass an array, but I want to give a shoutout to my dreaming mind for somehow going from the madness of arrays to a dream that I couldn't get water from a pitcher into a glass so I could drink.

    Here's some working mel and includes some of the additional lines to tell the Shape Editor UI to put some blend targets into an existing group. it's very sleek. (do these code boxes not have an option for scrolling?)

    // Assuming at least 4 blendShape targets and 1 empty group, place some of them into that group.
    // Using hardcoded values for this exercise
    int $originalDir[] = `getAttr blendShape1.targetDirectory[0].childIndices`;
    string $newOriginalDirToStrArray[];
    int $targetDir = 1;
    int $blendTargets[] = {3, 0, 1, 3};
    string $blendTargetsToStrArray[];
    int $blendTargetsSize = `size ($blendTargets)`;
    
    for($i=0;$i<$blendTargetsSize;++$i) {
    	$blendTargetsToStrArray[$i] = $blendTargets[$i];	// Do you want to build a string array from an int array?
    	setAttr blendShape1.parentDirectory[$i] $targetDir;	// Tell the blend target which group it is in.
    	}
    // Now basically run the whole setAttr command like a string, because we can't simply use an int array.
    // This tells the blend group which targets it contains.
    eval("setAttr blendShape1.targetDirectory[" + $targetDir + "].childIndices -type Int32Array " + stringArrayToString ($blendTargetsToStrArray, " "));
    
    // Now to update the group they came from; we already know they came from root level so we're assuming that here.
    int $newOriginalDir[] = intArrayRemove ($blendTargets, $originalDir);
    int $newOriginalDirSize = `size ($newOriginalDir)`;
    for($i=0;$i<$newOriginalDirSize;++$i) {
    	$newOriginalDirToStrArray[$i] = $newOriginalDir[$i];
    	}
    eval("setAttr blendShape1.targetDirectory[0].childIndices -type Int32Array " + $newOriginalDirSize + " " + stringArrayToString ($newOriginalDirToStrArray, " "));<br>
Sign In or Register to comment.