// =========================================================================== // 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. // =========================================================================== // // Procedure Name: // buildSetContainerMenu // // Description: // build the menu used for quickly selecting the current container // // Input Arguments: // Name of the parent menu // // Return Value: // None. // proc int createContainerMenuItem(string $container, string $currentContainer, int $submenu) { int $containerRadioOn = false; $radioState = ( $container == $currentContainer ); if ( $radioState ) { $containerRadioOn = true; } $cmd = ( "container -e -c 1 \"" + $container + "\"" ); string $format = (uiRes("m_buildSetContainerMenu.kSetCurrContAnnotFormat")); $annotation = `format -stringArg $container $format`; string $chmem[] = `container -q -nl $container`; string $subcontainers[] = `ls -type container $chmem`; $submenu = (size($subcontainers) > 0); menuItem -label $container -command $cmd -annotation $annotation -subMenu $submenu -radioButton $radioState; if ($submenu) { menuItem -label $container -command $cmd -annotation $annotation -radioButton $radioState; menuItem -divider true; for ($sub in $subcontainers) { if (createContainerMenuItem($sub, $currentContainer,1)) { $containerRadioOn = true; } } setParent -m ..; } return $containerRadioOn; } global proc buildSetContainerMenu( string $menu ) { string $oldParent = `setParent -m -query`; menu -edit -dai $menu; setParent -m $menu; int $containerRadioOn = false; // Get the list of top-level containers // string $containers[] = `ls -type container`; string $topLevelContainers[]; for ($obj in $containers) { string $parent[] = `container -q -parentContainer $obj`; if (size($parent) == 0) { $topLevelContainers[size($topLevelContainers)] = $obj; } } string $currentContainer = `container -q -c`; // Put in the "None" menu item // radioMenuItemCollection; int $radioState; $radioState = ( size( $currentContainer ) == 0 ); menuItem -label (uiRes("m_buildSetContainerMenu.kNone")) -command "ClearCurrentContainer" -annotation (getRunTimeCommandAnnotation("ClearCurrentContainer")) -radioButton $radioState; // Put in another divider, but only if there are containers // to list in the top-level container section of the menu // if ( size( $topLevelContainers ) > 0 ) { menuItem -divider true; } // Put in the radio buttons for all of the top-level containers // in the scene // string $cmd, $annotation; for ( $container in $topLevelContainers ) { if (createContainerMenuItem($container, $currentContainer, 0)) { $containerRadioOn = true; } } setParent -m $oldParent; }