// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== global proc int blendShapeCreateEmptyDirectory(string $bsdName, int $tgtIndex) // // Description: // Create an empty directory under this blendShape $bsdName, // the new directory shares the same parent directory of the given $tgtIndex. // This function does not support to create directory 0 yet. // // Input: // $tgtIndex >= 0 means it is a target, // < 0 means it is a target directory. // == 0, it is treated as a target not directory 0, // since there is no brother/sister directory at the same level of directory 0. // // Return: // the new directory index which > 0, 0 means fail. // { int $newDirectoryIndex = blendShapeUnusedTargetDirectoryIndex($bsdName); if ($newDirectoryIndex <= 0) return 0; if ($tgtIndex >= 0) { // this is a target. // TODO. this path is not used yet so no implement. } else { // this is a target directory // make sure this new directory does not have childIndices. $tempAttr = $bsdName + ".targetDirectory[" + $newDirectoryIndex + "].childIndices"; $cmd = "setAttr " + $tempAttr + " -type Int32Array 0"; eval($cmd); // update this new directory's the parent directory $tempAttr = $bsdName + ".targetDirectory[" + -$tgtIndex + "].parentIndex"; $parentDir = `getAttr $tempAttr`; $tempAttr = $bsdName + ".targetDirectory[" + $newDirectoryIndex + "].parentIndex"; setAttr $tempAttr $parentDir; // update parent directory's childIndices $tempAttr = $bsdName + ".targetDirectory[" + $parentDir + "].childIndices"; int $childIndices[] = `getAttr $tempAttr`; intArrayInsertAtIndex(size($childIndices), $childIndices, -$newDirectoryIndex); $tempAttr = $bsdName + ".targetDirectory[" + $parentDir + "].childIndices"; $cmd = "setAttr " + $tempAttr + " -type Int32Array " + size($childIndices); for ($idx in $childIndices) $cmd += " " + $idx; eval($cmd); } return $newDirectoryIndex; }