// =========================================================================== // 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. // =========================================================================== // // Finds a menuItem in a menu from its label. If $offset is not 0, then // the item $offset positions away from the item found is // returned. Negative numbers mean towards the top of the menu. // // If the item is not found or offset is too large, then "" is returned. // /////////////////////////////////////////////////////////////////////////////// global proc string findMenuItemFromLabel( string $menu, // I: menu name string $label, // I: label name int $offset) // I: offset to label { string $allItems[] = `menu -q -ia $menu`; int $i; string $completeItem; for ($i = size($allItems) ; $i-- ; ) { $completeItem = ($menu+"|"+$allItems[$i]); if ((! `menuItem -q -d $completeItem`) && ($label == `menuItem -q -l $completeItem`)) { $i += $offset; if (($i >= 0) && ($i < size($allItems))) return $allItems[$i]; return ""; } } return ""; }