// =========================================================================== // 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 blendShapeRenameTargetAlias(string $bs, int $targetIndex, string $newAlias) // Description: // To reanme a target/weight of the given blendShape node // { // Why not just "aliasAttr newAlias blendShapeX.w[y]" ? // It fails when there are deleted targets and their alias are still cached // by the aliasAttr. // To fix that, we modify that cached and unused alias. string $targetAttrW = $bs + ".w[" + $targetIndex + "]"; int $validTargetIndices[] = getAttr("-mi", $bs+".w"); string $old[] = aliasAttr("-q", $bs); int $oldCount = size($old) / 2; for ($i = 0; $i < $oldCount; ++$i) { if ( !intArrayContains($i, $validTargetIndices) && $i != $targetIndex ) { string $temp = $bs + ".w[" + $i + "]"; string $oldAliasName = aliasAttr("-q", $temp); if ($oldAliasName == $newAlias) { string $tempAliasName = "tempAlias" + $targetIndex; string $cmd = "aliasAttr " + $tempAliasName + " " + $temp; evalEcho($cmd); } } } string $cmd = "aliasAttr " + $newAlias + " " + $targetAttrW; evalEcho($cmd); return 1; } global proc string blendShapeUniqueWeighName(string $bsdName, string $weightName) // Description: // the $weightName may already be used, // to create a new name by adding number at the end. { string $name = $weightName; int $i = 1; while (blendShapeTargetIndexFromName($bsdName, $name) != -1) { $name = $weightName + $i; ++ $i; } return $name; }