// =========================================================================== // 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. // =========================================================================== // // // Creation Date: // // Procedure Name: // AEdynParticleInstancerNew // // Description Name; // // Input Value: // // Output Value: // None // global string $AEselectedInstancer; global string $AEmenuParent; global proc AEinstancerNew( string $nodeAttr ) { string $buffer[]; global string $AEselectedInstancer; tokenize($nodeAttr, ".", $buffer); string $nodeName = $buffer[0]; $AEselectedInstancer = $nodeName; setUITemplate -pst attributeEditorTemplate; columnLayout ("instancerColumn"); setParent ..; setUITemplate -ppt; AEcreateInstancedObjectList( $nodeName ); AEinstancerReplace( $nodeName ); } global proc AEinstancerReplace( string $instancerName ) { global string $AEmenuParent; global string $AEselectedInstancer; string $buffer[]; tokenize($instancerName, ".", $buffer); string $nodeName = $buffer[0]; $AEselectedInstancer = $nodeName; setUITemplate -pst attributeEditorTemplate; if (!`columnLayout -ex InstancerColumn`) { setUITemplate -pst attributeEditorTemplate; columnLayout InstancerColumn; setUITemplate -ppt; } setParent InstancerColumn; string $parent = `setParent -q`; AEeditInstancedObjectList( $nodeName ); // Go back to the column. // setParent ..; setUITemplate -ppt; } global proc string AEinstancerCmdFlag( string $attrName ) { string $flag; return $flag; } proc int isValidInstancedObject( string $objectName ) { if( size($objectName) == 0 ) return 0; string $temp[]; // // First check to see if the selected object // is a transform. // clear($temp); $temp = `ls -type transform $objectName`; if( size($temp) == 0 ) return 0; // // Now filter out special types derived from transforms // string $invalidTransformTypes[] = { "pointEmitter", "field", "ikhandle", "ikEffector", "instancer", "joint" }; clear($temp); $temp = `ls -type pointEmitter -type field -type ikHandle -type ikEffector -type joint -type instancer $objectName`; if( size($temp) > 0 ) return 0; return 1; } proc adjustScrollListToSeeItems( string $listName, int $items[] ) { if( size($items) > 0 ) { $items = sort($items); int $i; for( $i = 0; $i < size($items); $i ++ ) { int $firstSelected = $items[$i]; int $numberOfRows = `textScrollList -q -numberOfRows $listName`; if( $firstSelected > $numberOfRows ) { int $selectThis = $firstSelected - $numberOfRows + 1; textScrollList -e -showIndexedItem $selectThis $listName; } } } } proc updateList( string $listName, string $node, int $selectedIndices[] ) { string $currentConnections[] = `listConnections ($node+".inputHierarchy")`; int $vis = `textScrollList -q -visible $listName`; textScrollList -e -visible 0 $listName; textScrollList -e -removeAll $listName; int $i; if( size($currentConnections) == 0 ) { textScrollList -e -append " " -width 380 $listName; } else { for( $i = 0; $i < size($currentConnections); $i ++ ) { string $newText = ($i + ": " + $currentConnections[$i]); textScrollList -e -append $newText -width 380 $listName; } } textScrollList -e -deselectAll $listName; for( $i = 0; $i < size($selectedIndices); $i ++ ) { if( $selectedIndices[$i] <= `textScrollList -q -numberOfItems $listName` ) textScrollList -e -selectIndexedItem $selectedIndices[$i] $listName; } adjustScrollListToSeeItems( $listName, $selectedIndices ); textScrollList -e -visible 1 $listName; } proc connectObjectsToInstancer( string $listName, string $node, string $arrayName[], int $selectedIndices[], string $window ) { scriptJob -replacePrevious -parent $window -conditionTrue readingFile ""; string $currentConnections[] = `listConnections -connections on -plugs on -source on ($node+".inputHierarchy")`; int $i; for( $i = 0; $i < size($currentConnections); $i += 2 ) { disconnectAttr $currentConnections[$i+1] $currentConnections[$i]; } for( $i = 0; $i < size($arrayName); $i ++ ) { connectAttr ($arrayName[$i]+".matrix") ($node+".inputHierarchy["+$i+"]"); } textScrollList -e -visible 0 $listName; textScrollList -e -deselectAll $listName; for( $i = 0; $i < size($selectedIndices); $i ++ ) { if( $selectedIndices[$i] <= `textScrollList -q -numberOfItems $listName` ) textScrollList -e -selectIndexedItem $selectedIndices[$i] $listName; } updateList( $listName, $node, $selectedIndices ); scriptJob -replacePrevious -parent $window -attributeChange ($node+".inputHierarchy") ("instancerAE_updateListWithCurrentSelection "+$listName+" "+$node) -disregardIndex; } proc shuffleInstancerConnections( string $listName, string $node, int $from[], int $to[], int $selectedIndices[], int $showFirst, string $window ) { scriptJob -replacePrevious -parent $window -conditionTrue readingFile ""; string $currentConnections[] = `listConnections -connections on -plugs on -source on ($node+".inputHierarchy")`; string $currentObjectConnections[] = `listConnections ($node+".inputHierarchy")`; int $connectionCount = size($currentConnections) / 2; int $i; for( $i = 0; $i < min(size($from),size($to)); $i ++ ) { int $f = $from[$i]; int $t = $to[$i]; if( ( $f < $connectionCount ) && ( $t < $connectionCount ) ) { string $fromSrc = $currentConnections[$f*2+1]; string $fromDst = $currentConnections[$f*2]; string $toSrc = $currentConnections[$t*2+1]; string $toDst = $currentConnections[$t*2]; disconnectAttr $fromSrc $fromDst; disconnectAttr $toSrc $toDst; connectAttr $toSrc $fromDst; connectAttr $fromSrc $toDst; $currentConnections[$f*2+1] = $toSrc; $currentConnections[$t*2+1] = $fromSrc; string $temp = $currentObjectConnections[$f]; $currentObjectConnections[$f] = $currentObjectConnections[$t]; $currentObjectConnections[$t] = $temp; } } textScrollList -e -deselectAll $listName; for( $i = 0; $i < min(size($from),size($to)); $i ++ ) { int $f = $from[$i]; int $t = $to[$i]; if( ( $f < $connectionCount ) && ( $t < $connectionCount ) ) { string $fromSrc = $currentConnections[$f*2+1]; string $fromDst = $currentConnections[$f*2]; string $toSrc = $currentConnections[$t*2+1]; string $toDst = $currentConnections[$t*2]; textScrollList -e -removeIndexedItem ($f+1) $listName; textScrollList -e -appendPosition ($f+1) (""+$f+": "+$currentObjectConnections[$f]) $listName; textScrollList -e -removeIndexedItem ($t+1) $listName; textScrollList -e -appendPosition ($t+1) (""+$t+": "+$currentObjectConnections[$t]) $listName; } } for( $i = 0; $i < size($selectedIndices); $i ++ ) { if( $selectedIndices[$i] <= `textScrollList -q -numberOfItems $listName` ) textScrollList -e -selectIndexedItem $selectedIndices[$i] $listName; } adjustScrollListToSeeItems( $listName, $selectedIndices ); scriptJob -replacePrevious -parent $window -attributeChange ($node+".inputHierarchy") ("instancerAE_updateListWithCurrentSelection "+$listName+" "+$node) -disregardIndex; } proc fillItemList(string $listName, string $node, string $arrayName[], int $selectedIndices[], string $window ) { connectObjectsToInstancer( $listName, $node, $arrayName, $selectedIndices, $window ); } proc fillItemListFromCurrentSelection(string $listName, string $node, string $arrayName[], string $window ) { int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`; connectObjectsToInstancer( $listName, $node, $arrayName, $selectedIndices, $window ); } proc addItemsFromList( string $list[], string $listName, string $node, string $window ) { string $currentConnections[] = `listConnections ($node+".inputHierarchy")`; int $listChanged = 0; int $i; for( $i = 0; $i < size($list); $i ++ ) { if( isValidInstancedObject( $list[$i] ) == 1 ) { int $found = 0; int $j; for( $j = 0; $j < size($currentConnections); $j ++ ) { if( $list[$i] == $currentConnections[$j] ) { $found = 1; } } if( $found == 0 ) { $currentConnections[size($currentConnections)] = $list[$i]; $listChanged = 1; } } } if( $listChanged ) fillItemListFromCurrentSelection( $listName, $node, $currentConnections, $window ); } global proc instancerAE_addItemsFromSelectionList( string $listName, string $node, string $window ) // // Description: // // This proc reads the selection list, and adds the items // to the list of objects to be instanced by the instancer // $node. // { string $selectedItems[] = `ls -sl`; if( size($selectedItems) > 0 ) addItemsFromList( $selectedItems, $listName, $node, $window ); } global proc instancerAE_removeSelectedItems( string $listName, string $node, string $window ) { string $currentConnections[] = `listConnections ($node+".inputHierarchy")`; int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`; if( size($selectedIndices) == 0 ) return; int $i; int $j; string $temp[]; for( $i = 0; $i < size($currentConnections); $i ++ ) { int $found = 0; for( $j = 0; $j < size($selectedIndices); $j ++ ) { if( $selectedIndices[$j] == $i+1 ) $found = 1; } if( $found == 0 ) { $temp[size($temp)] = $currentConnections[$i]; } } $currentConnections = $temp; textScrollList -e -deselectAll $listName; fillItemListFromCurrentSelection( $listName, $node, $currentConnections, $window ); } global proc instancerAE_moveSelectedItemsUp(string $listName, string $node, string $window ) { string $currentConnections[] = `listConnections ($node+".inputHierarchy")`; int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`; if( size($selectedIndices) == 0 ) return; int $newSelectedIndices[] = $selectedIndices; int $from[]; int $to[]; clear($from); clear($to); int $listChanged = 0; int $i; for( $i = 0; $i < size($selectedIndices); $i ++ ) { int $si = $selectedIndices[$i] - 1; if( $si > $i ) { string $temp = $currentConnections[$si]; $currentConnections[$si] = $currentConnections[$si-1]; $currentConnections[$si-1] = $temp; $newSelectedIndices[$i] = $si; $listChanged = 1; $from[size($from)] = $si; $to[size($to)] = $si-1; } } if( $listChanged == 1 ) { if( size($selectedIndices) <= 2 ) shuffleInstancerConnections( $listName, $node, $from, $to, $newSelectedIndices, 1, $window ); else fillItemList( $listName, $node, $currentConnections, $newSelectedIndices, $window ); } } global proc instancerAE_moveSelectedItemsDown(string $listName, string $node, string $window ) { string $currentConnections[] = `listConnections ($node+".inputHierarchy")`; int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`; if( size($selectedIndices) == 0 ) return; int $newSelectedIndices[] = $selectedIndices; int $from[]; int $to[]; clear($from); clear($to); int $listChanged = 0; int $i; for( $i = size($selectedIndices) - 1; $i >= 0 ; $i -- ) { int $si = $selectedIndices[$i] - 1; int $ni = size($currentConnections) - ( size($selectedIndices) - $i ); if( $si < $ni ) { string $temp = $currentConnections[$si]; $currentConnections[$si] = $currentConnections[$si+1]; $currentConnections[$si+1] = $temp; $newSelectedIndices[$i] = $si+2; $listChanged = 1; $from[size($from)] = $si; $to[size($to)] = $si+1; } } if( $listChanged == 1 ) { if( size($selectedIndices) <= 2 ) shuffleInstancerConnections( $listName, $node, $from, $to, $newSelectedIndices, 0, $window ); else fillItemList( $listName, $node, $currentConnections, $newSelectedIndices, $window ); } } global proc instancerAE_updateListWithCurrentSelection( string $listName, string $node ) { int $selectedIndices[] = `textScrollList -q -selectIndexedItem $listName`; updateList( $listName, $node, $selectedIndices ); } global proc AEeditInstancedObjectList( string $instancer ) { string $parent = `setParent -q`; // string $mainListName = ($instancer+"mainList"); string $mainListName = ("AEinstancer"+"mainList"); scriptJob -replacePrevious -parent $mainListName -attributeChange ($instancer+".inputHierarchy") ("instancerAE_updateListWithCurrentSelection "+$mainListName+" "+$instancer) -disregardIndex; instancerAE_updateListWithCurrentSelection( $mainListName, $instancer ); setParent ..; } global proc AEcreateInstancedObjectList( string $instancer ) { string $parent = `setParent -q`; global string $AEselectedInstancer; rowColumnLayout -columnWidth 1 385 -numberOfColumns 1 -columnAttach 1 "both" 0 // ($instancer+"mainLayout"); ("AEinstancer"+"mainLayout"); text -label (uiRes("m_AEinstancerNew.kInstancedObjects")) // ($instancer+"$listNameLabel"); ("AEinstancer"+"$listNameLabel"); // string $mainListName = ($instancer+"mainList"); string $mainListName = ("AEinstancer"+"mainList"); textScrollList -width 385 -height 94 -allowMultiSelection true -removeAll -annotation (uiRes("m_AEinstancerNew.kListoftheinstancedobjectsandtAnnot")) $mainListName; int $scriptJobIndex = `scriptJob -replacePrevious -parent $parent -attributeChange ($AEselectedInstancer+".inputHierarchy") ("instancerAE_updateListWithCurrentSelection "+$mainListName+" "+$AEselectedInstancer) -disregardIndex`; rowColumnLayout -numberOfColumns 4 -columnWidth 1 98 -columnWidth 2 96 -columnWidth 3 95 -columnWidth 4 95 -columnAlign 1 "center" -columnAlign 2 "center" -columnAlign 3 "center" -columnAlign 4 "center" -columnAttach 1 "both" 0 -columnAttach 2 "both" 0 -columnAttach 3 "both" 0 -columnAttach 4 "both" 0 -rowAttach 1 "top" 2 -rowAttach 2 "top" 2 -rowAttach 3 "top" 2 -rowAttach 4 "top" 2 // ($instancer+"existingItemButtonLayout"); ("AEinstancer"+"existingItemButtonLayout"); button -label (uiRes("m_AEinstancerNew.kAddSelection")) -command ("instancerAE_addItemsFromSelectionList "+$mainListName+" $AEselectedInstancer "+$parent) -annotation (uiRes("m_AEinstancerNew.kAddselectedobjectstothelistAnnot")) -width 98 // ($instancer+"addItemsButton"); ("AEinstancer"+"addItemsButton"); button -label (uiRes("m_AEinstancerNew.kRemoveItems")) -command ("instancerAE_removeSelectedItems "+$mainListName+" $AEselectedInstancer "+$parent) -annotation (uiRes("m_AEinstancerNew.kRemovethehighlighteditemsfromAnnot")) -width 96 // ($instancer+"removeItemsButton"); ("AEinstancer"+"removeItemsButton"); string $moveUpName = ($instancer+"moveItemsUpButton"); button -label (uiRes("m_AEinstancerNew.kMoveUp")) -command ("instancerAE_moveSelectedItemsUp "+$mainListName+" $AEselectedInstancer "+$parent) -annotation (uiRes("m_AEinstancerNew.kMovehighlighteditemshigherintAnnot")) -width 95 $moveUpName; string $moveDownName = ($instancer+"moveItemsDownButton"); button -label (uiRes("m_AEinstancerNew.kMoveDown")) -command ("instancerAE_moveSelectedItemsDown "+$mainListName+" $AEselectedInstancer "+$parent) -annotation (uiRes("m_AEinstancerNew.kMovehighlighteditemslowerinthAnnot")) -width 95 $moveDownName; instancerAE_updateListWithCurrentSelection( $mainListName, $instancer ); setParent ..; }