LoginSignup
0
0

シェルフの内容で右クリックマーキングメニューを変更

Last updated at Posted at 2024-04-01

Popup Marking Menu
Shift + Popup Marking Menu
を変更

kohaku_popupMenu.mel
// contextPolyTools〇〇MMを修正
proc kohaku_PM_revisionContextPolyToolsMM(string $targetProc){
    { // 読み込み
        string $procString;
        string $result = `whatIs $targetProc`;
        if($result == "Mel procedure entered interactively.") return; // 修正済み
        string $filePath = `substitute "^.+found in: " $result ""`;
        string $allLines[] = freadAllLines($filePath);
        int $flg = off;
        for($line in $allLines){
            { // 不必要なsetParent ..;を取り除く
                $line = `substitute "^[\t ]*" $line ""`;
                if(`gmatch $line "-subMenu*"`){
                    $flg = on;
                }else if(`gmatch $line "setParent*"`){
                    if($flg){
                        $flg = off;
                    }else{
                        continue;
                    }
                }
                $procString += $line + "\n";
            }
        }
        eval($procString); // 作製
    }
}
// Right-click command
{
    // Execution Right-click command 
    global proc k_PM_RC(string $label){
        global float $gKohaku_PM_rightClickTime;
        global string $gKohaku_PM_rightClickCmd;
        global string $gKohaku_PM_shiftRightClickCmd;
        string $cmd;
        if(`getModifiers` % 2){ // Shift
            $cmd = $gKohaku_PM_shiftRightClickCmd;
        }else{
            $cmd = $gKohaku_PM_rightClickCmd;
        }
        if(`timerX -startTime $gKohaku_PM_rightClickTime` < 0.2) eval($cmd);
    }
    // Registration Right-click command
    global proc kohaku_PM_registrationRightClickCmd(string $label, string $cmd){
        global string $gKohaku_PM_rightClickCmd;
        global string $gKohaku_PM_shiftRightClickCmd;
        global string $gKohaku_PM_rightClickCmdList[];
        global string $gKohaku_PM_rightClickLabelList[];
        if(`getModifiers` % 2){ // Shift
            $gKohaku_PM_shiftRightClickCmd = $cmd;
        }else{
            $gKohaku_PM_rightClickCmd = $cmd;
        }
        if(stringArrayFind($cmd, 0, $gKohaku_PM_rightClickCmdList) <= 0){
            appendStringArray($gKohaku_PM_rightClickCmdList, {$cmd}, 1);
            appendStringArray($gKohaku_PM_rightClickLabelList, {$label}, 1);
        }
        kohaku_PM_rghtClickCmdInViewMessage;
    }
    // Right-click command to inViewMessage
    global proc kohaku_PM_rghtClickCmdInViewMessage(){
        global string $gKohaku_PM_rightClickCmd;
        global string $gKohaku_PM_shiftRightClickCmd;
        global string $gKohaku_PM_rightClickCmdList[];
        global string $gKohaku_PM_rightClickLabelList[];
        if($gKohaku_PM_rightClickCmd == "") return;
        int $originalInViewMessageEnable = `optionVar -q inViewMessageEnable`;
        if($originalInViewMessageEnable == off){
            optionVar -iv inViewMessageEnable 1;
        }
        int $index = stringArrayFind($gKohaku_PM_rightClickCmd, 0, $gKohaku_PM_rightClickCmdList);
        string $label = $gKohaku_PM_rightClickLabelList[$index];
        $index = stringArrayFind($gKohaku_PM_shiftRightClickCmd, 0, $gKohaku_PM_rightClickCmdList);
        string $label2 = $gKohaku_PM_rightClickLabelList[$index];
        string $message = "Right-click \"" + $label + "\" , "
                        + "Shift + Right-click \"" + $label2 + "\"";
        inViewMessage -a 0 -amg $message -fts 9 -pos "topCenter" -ta .5;
        optionVar -iv inViewMessageEnable $originalInViewMessageEnable;
    }
}

// 最近使ったランタイムコマンドから右クリックコマンド選択menuItem作製
global proc kohaku_PM_rghtClickCmdFromRecentCmds(string $parent){
    setParent -m $parent;
    string $recentCmdList[] = `repeatLast -q -cnl`;
    string $recentCmdStringList[] = `repeatLast -q -cl`;
    int $index = $total = 0;
    string $radialPositionList[] = {"N", "NW", "W", "SW", "S", "SE", "E", "NE"};
    string $runTimeCmd;
    for ($cmd in $recentCmdList){
        $index++;
        if($cmd == "") continue;
        if($cmd == "Parent") $cmd = $recentCmdStringList[$index - 1]; // parent constraint and parent menu items have the same name
        $runTimeCmd = `kohaku_PM_getRunTimeCmd $cmd`;
        if(`runTimeCommand -ex $runTimeCmd`){
            string $image = `runTimeCommand -q -i $runTimeCmd`;
            string $menuItem = `menuItem
                -l $cmd // runTimeCmdのラベルではDelete History等がHistoryと表示されてしまう
                // ww
                -c ("kohaku_PM_registrationRightClickCmd(\""+ $cmd + "\", \"" + $recentCmdStringList[$index - 1] + "\")")
                -ecr false
                -i $image
                `
                ;
            if($total < 8){
                menuItem -e -rp $radialPositionList[$total] $menuItem;
                $total++;
            }
        }
    }
}
// recent Command MenuItem作製
global proc kohaku_PM_recentCmdMenu(string $parent){
    global int $gKohaku_PM_maxCharacters;
    setParent -m $parent;
    string $recentCmdList[] = `repeatLast -q -cnl`;
    string $recentCmdStringList[] = `repeatLast -q -cl`;
    int $index = 0;
    for($cmd in $recentCmdList){
        $index++;
        if($cmd == "") continue;
		if($cmd == "Parent") $cmd = $recentCmdStringList[$index]; // parent constraint and parent menu items have the same name,
        string $label = makeStringSingleLine($cmd);
        if(`size $label` > $gKohaku_PM_maxCharacters) $label = startString($label, $gKohaku_PM_maxCharacters) + "...";
        string $runTimeCmd = `kohaku_PM_getRunTimeCmd $cmd`;
        string $image;
        if($runTimeCmd != "") $image = `runTimeCommand -q -i $runTimeCmd`;
        string $menuItem = `menuItem
            -l $label
            -c $recentCmdStringList[$index - 1]
            -i $image
            `
            ;
        string $radialPositionList[] = {"N", "NW", "W", "SW", "S", "SE", "E", "NE"};
        if($index <= 8) menuItem -e -rp $radialPositionList[$index - 1] $menuItem;
    }
}

// コンテキストのアイコンを取得
global proc string kohaku_PM_getCtxIcon(string $ctx){
    string $image;
    string $title = `contextInfo -t $ctx`;
    $title = `substitute " " $title ""`;
    if(`runTimeCommand -ex $title`) $image = `runTimeCommand -q -i $title`;
    if($image == ""){
        switch($ctx){
            case "selectSuperContext":
                $image = "aselect.png";
                break;
            case "lassoSelectContext":
                $image = "lassoSelect.png";
                break;
            case "artSelectContext":
                $image = "artSelect.png";
                break;
            default :
                $image = `contextInfo -i1 $ctx`;
                break;
        }
    }
    return $image;
}
// コマンドから個別にランタイムコマンドを取得
global proc string kohaku_PM_getRunTimeCmd(string $cmd){
    string $runTimeCmd;
    if($cmd == "") return "";
    if(`runTimeCommand -ex $cmd`) return $cmd;
    { // Contextの場合
        string $title;
        if(`contextInfo -ex $cmd`) $title = `contextInfo -q -t $cmd`;
        if($title != ""){
            $title = `substitute " " $title ""`;
            if(`runTimeCommand -ex $title`) return $title;
        }
    }
    { // performPolyExtrude 0 等
        string $result;
        if(size(`match "^perform" $cmd`)){
            $result = `substitute "^perform" $cmd ""`;
            $result = `substitute " 0$" $result ""`;
        }
        if(`runTimeCommand -ex $result`) return $result;
    }
    switch($cmd){
        case "artSelectContext" :
            $runTimeCmd = "ArtPaintSelectTool";
            break;
        case "polySlideEdgeContext" :
            $runTimeCmd = "SlideEdgeTool";
            break;
        case "polySelectEditContext" :
            $runTimeCmd = "DuplicateEdges";
            break;
        case "performPolyBevel 3" :
            $runTimeCmd = "BevelPolygon";
            break;
        case "Soften Edge" :
            $runTimeCmd = "PolygonSoftenEdge";
            break;
        case "Harden Edge" :
            $runTimeCmd = "PolygonHardenEdge";
            break;
        default :
            $runTimeCmd = "";
            break;
    }
    return $runTimeCmd;
}
// ランタイムコマンドからlabelを取得
proc string kohaku_PM_getlabel(string $runTimeCmd){
    if($runTimeCmd == "") return "";
    string $label;
    { // ランタイムコマンドにラベルが有る場合
        if(`runTimeCommand -q -ex $runTimeCmd`){
            $label = `runTimeCommand -q -l $runTimeCmd`;
            if(size($label)) return $label;
        }
    }
    { // 個別
        switch($runTimeCmd){
            case "SelectTool" :
                $label = `uiRes("m_defaultRunTimeCommands.kEnableSelectToolLbl")`;
                break;
            case "LassoTool" :
                $label = `uiRes("s_HtoolStrings.rLassoToolName")`;
                break;
            case "ArtPaintSelectTool" :
                $label = `uiRes("m_dagMenuProc.kPaintSelect")`;
                break;
            case "" :
                $label = `uiRes("m_dagMenuProc.kPaintSelect")`;
                break;
        }
        return $label;
    }
}
// 選択タイプ取得
global proc string kohaku_PM_selectionType(){
	string $selection[] = `ls -long -selection`;
    string $resultList[];
    if(!size($selection)) return "NONE";
    { // vertex
        $resultList = `filterExpand -expand false -selectionMask 31 $selection`;
        if(size($resultList)) return "vertex";
    }
    { // edge
        $resultList = `filterExpand -expand false -selectionMask 32 $selection`;
        if(size($resultList)) return "edge";
    }
    { // face
        $resultList = `filterExpand -expand false -selectionMask 34 $selection`;
        if(size($resultList)) return "face";
    }
}
// menuItemを削除
global proc kohaku_PM_deleteMenu(string $parent){
    string $menuItemList[] = `popupMenu -q -ia $parent`;
    if(!`size $menuItemList`) return; // menuItemが無い場合
    for($menuItem in $menuItemList){
        $menuItem = $parent + "|" + $menuItem;
        string $rp = `menuItem -q -rp $menuItem`;
        switch($rp){
            case "N":
            case "W":
            case "S":
            case "NE":
            deleteUI -mi $menuItem;
            break;
        }
    }
}
// build Shelf Etc menuItems
global proc kohaku_PM_shelfEtc(string $parent){
    global int $gKohaku_PM_maxCharacters;
    global string $gKohaku_PM_menuItemString;
    global string $gKohaku_PM_mainShelfList[];
    global string $gKohaku_PM_mainShelf;
    setParent -m $parent;
    { // Right-click Cmd from Recent RunTime Cmd
        string $menuItem = "kohaku_PM_rghtClickCmdFromRecentRunTimeCmds";
        menuItem
            -l "Right-click Cmd from Recent RunTime Cmds"
            -rp "S"
            -pmc ("kohaku_PM_rghtClickCmdFromRecentCmds \"" + $parent + "|" + $menuItem + "\"")
            -pmo true
            -sm on
            $menuItem
            ;
        setParent -m ..;
    }
    { // Right-click Cmd
        string $menuItem = "kohaku_PM_rghtClickCmd";
        menuItem
            -l "Right-click Cmd"
            -rp "SW"
            -pmc ("setParent -m \"" + $parent + "|" + $menuItem + "\";\n" // setParentが必要
                + "eval($gKohaku_PM_radialMenuItemString)")
            -pmo true
            -sm on
            $menuItem
            ;
        setParent -m ..;
    }
    { // Recent Command Menu
        string $menuItem = "kohaku_PM_recentCmdMenu";
        menuItem
            -l `uiRes("m_HotboxMenus.kRecentCommands")`
            -rp "NW"
            -pmc ("kohaku_PM_recentCmdMenu \"" + $parent + "|" + $menuItem + "\"")
            -pmo true
            -sm on
            $menuItem
            ;
        setParent -m ..;
    }
    // シェルフmenuItem & subMenuItem

    // ww
    // コマンド文字の初期化の位置をかえる
    eval($gKohaku_PM_menuItemString);
    { // Kohaku DagMenu
        menuItem -d true;
        menuItem -l "Modify Kohaku Menu" -sm on;
        { // subMenu
            { // 主シェルフ選択
                menuItem -l "Main shelf selection" -sm on;
                { // subMenu
                    radioMenuItemCollection;
                    for($shelf in $gKohaku_PM_mainShelfList){
                        int $rbFlg = off;
                        if($shelf == $gKohaku_PM_mainShelf) $rbFlg = on;
                        string $cmd = "$gKohaku_PM_mainShelf = \"" + $shelf + "\";\n"
                                    + "$gKohaku_PM_menuItemString = \"kohaku_PM undefined\";\n"
                                    ;
                        menuItem
                            -l $shelf
                            -rb $rbFlg
                            -c $cmd
                            -ecr false
                            ;
                    }
                    setParent -m ..;
                }
            }
            { // 開発補助
                menuItem -d on;
                menuItem
                    -l `uiRes("m_AEfluidAttrTemplate.kInitialize")`
                    -c "source \"kohaku_popupMenu\""
                    -ec on // エコー
                    -ecr false
                    ;
            }
            setParent -m ..;
        }
    }
}
// 右クリックコマンド呼び出し
global proc kohaku_PM_callRightClickCmd(){
    global string $gKohaku_PM_rightClickCmd;
    global string $gKohaku_PM_rightClickCmdList[];
    global string $gKohaku_PM_ctrlRightClickCmd; 
    global string $gKohaku_PM_rightClickLabelList[];
    global float $gKohaku_PM_rightClickTime;
    global int $gKohaku_PM_rightClickScriptJobNum;
    int $index;
    if(!`dR_isCtrlHeld`){
        $index = stringArrayFind($gKohaku_PM_rightClickCmd, 0, $gKohaku_PM_rightClickCmdList);
    }else{
        $index = stringArrayFind($gKohaku_PM_ctrlRightClickCmd, 0, $gKohaku_PM_rightClickCmdList);
    }
    string $label = $gKohaku_PM_rightClickLabelList[$index];
    $label = substituteAllString($label, " ", "");
    $gKohaku_PM_rightClickTime = `timerX`;
    $gKohaku_PM_rightClickScriptJobNum = `scriptJob -ro true -ie ("k_PM_RC(\""+ $label + "\")")`;
}
// Shift or Ctrlが押されている場合コマンド実行
global proc kohaku_PM_ModifiersCmd(string $cmd){
    // shift or Ctrl is down
    if(((`getModifiers` / 1) % 2) || ((`getModifiers` / 4) % 2)) eval($cmd);
}
//ww
// 最近使ったツールを記憶
global proc kohaku_PM_recentNonSacredTool(){
    global string $gkohaku_PM_recentNonSacredToolList[];
    string $currentCtx = `currentCtx`;
    if($currentCtx == "ShowManips") return;
    string $sacredTool[] = {"selectSuperContext", "lassoSelectContext", "artSelectContext",
                    "moveSuperContext", "RotateSuperContext", "scaleSuperContext"};
    if(stringArrayContains($currentCtx, $sacredTool)) return;
    int $index = stringArrayFind($currentCtx, 0, $gkohaku_PM_recentNonSacredToolList);
    stringArrayRemoveAtIndex($index, $gkohaku_PM_recentNonSacredToolList);
    stringArrayInsertAtIndex(0, $gkohaku_PM_recentNonSacredToolList, $currentCtx);
}
// Command Menu
global proc kohaku_PM_commandMenu(string $parent){
    global string $gkohaku_PM_recentNonSacredToolList[];
    global int $gKohaku_PM_maxCharacters;
    { // 右クリック
        inViewMessage -cl topCenter; // メッセージ消去
        kohaku_PM_callRightClickCmd;
    }
    setParent -m $parent;
    popupMenu -e -dai $parent;
    { // ContextPolyToolsMMの修正
        string $result = `whatIs "contextPolyToolsFaceMM"`;
        if($result != "Mel procedure entered interactively."){ // 修正されていないなら
            kohaku_PM_revisionContextPolyToolsMM("contextPolyToolsFaceMM");
            kohaku_PM_revisionContextPolyToolsMM("contextPolyToolsObjectMM");
        }
    }
    { // Current Sacred Tool
        global string $gCurrentSacredTool; // toolbox.mel
        string $runTimeCmd = `kohaku_PM_getRunTimeCmd $gCurrentSacredTool`;
        string $label = `kohaku_PM_getlabel $runTimeCmd`;
        string $image = `kohaku_PM_getCtxIcon $gCurrentSacredTool`;
        menuItem
            -l $label
            -c $runTimeCmd
            -ecr false // Tool Boxの動作に合わせる
            -i $image
            -rp "N"
            ;
    }
    { // Non Sacred Tool;
        string $rp = "E";
        if(size($gkohaku_PM_recentNonSacredToolList)){
            string $ctx = $gkohaku_PM_recentNonSacredToolList[0];
            string $label, $runTimeCmd; 
            { // polySlideEdgeContextはtitleが無くcontextInfoでは取得出来ない
                $runTimeCmd = `kohaku_PM_getRunTimeCmd $ctx`;
                if($runTimeCmd != "") $label = `kohaku_PM_getlabel $runTimeCmd`;
                else $label = `contextInfo -t $ctx`;
            }
            menuItem
                -l $label
                -c ("setToolTo " + $ctx)
                -ecr false // Tool Boxの動作に合わせる
                -i `contextInfo -i1 $ctx`
                -rp $rp
                ;
        }else menuItem -l "Non Sacred Tool" -en false -rp $rp;
    }
    { // repeat RunTime Command(ツールを除く)
        string $recentCmdList[] = `repeatLast -q -cnl`;
        string $recentCmdStringList[] = `repeatLast -q -commandList`;
        int $index = 0;
        string $runTimeCmd;
        for ($cmd in $recentCmdList){
            $index++;
            if($cmd == "") continue;
            if(size(`match "setToolTo" $cmd`)) continue; // ツールを除く
            if($cmd == "Parent") $cmd = $recentCmdStringList[$index - 1]; // parent constraint and parent menu items have the same name
            $runTimeCmd = `kohaku_PM_getRunTimeCmd $cmd`;
            if(`runTimeCommand -ex $runTimeCmd`)
                if(!`endsWith $cmd "Tool"` || $cmd == "CompleteCurrentTool") break; // ツールを除く
        }
        string $menuItemName = "kohaku_PM_repeatRunTimeCmd";
        menuItem
            -l $cmd // runTimeCmdのラベルではDelete History等がHistoryと表示されてしまう
            -rtc $runTimeCmd
            -rp "W"
            $menuItemName
            ;
        if($runTimeCmd == ""){
            menuItem -e -en false -l (`uiRes "m_defaultRunTimeCommands.kRepeatLastLbl"` + " RunTime Command") ($parent + "|" + $menuItemName);
        }
    }
    { // Undo & Redo
        string $cmdList[] = {"Undo", "Redo"};
        string $rpList[] = {"SW", "SE"};
        string $labelList[] = {`uiRes "m_buildEditMenu.kEditUndo"`,
            `uiRes "m_buildEditMenu.kEditRedo"`};
        for($i = 0; $i < 2; $i++){
            string $info = `eval("undoInfo -q -" + tolower($cmdList[$i]) + "Name")`;
            string $label = $labelList[$i];
            if($info != ""){
                string $tokens[];
                tokenize $info $tokens;
                if(`size $tokens` > 1) $info = $tokens[0];
                if(`size $info` > $gKohaku_PM_maxCharacters)
                    $info = startString($info, $gKohaku_PM_maxCharacters) + "...";
                $label += " \"" + $info + "\"";
            }
            string $menuItem = ("kohaku_PM_" + `tolower $cmdList[$i]`);
            menuItem
                -l $label
                -c $cmdList[$i]
                -ecr false
                -i (`tolower $cmdList[$i]` + "_s.png")
                -rp $rpList[$i]
                $menuItem
                ;
            dimWhen -f ($cmdList[$i] + "Available") ($parent + "|" + $menuItem);
        }
    }
    { // RepeatLast
        string $cmd = "RepeatLast";
        string $label, $recentCmdNameList[];
        if(`repeatLast -q -numberOfHistoryItems` != 0){
            $recentCmdNameList = `repeatLast -cnl 1`;
            $label = $recentCmdNameList[0];
        }
        if($label == "Parent"){ // parent constraint and parent menu items have the same name
            string $recentCmdStringList[] = `repeatLast -cl 1`;
            $label = $recentCmdStringList[0];
        }
        $label = makeStringSingleLine($label);
        if(`size $label` > $gKohaku_PM_maxCharacters)
            $label = startString($label, $gKohaku_PM_maxCharacters) + "...";
        string $menuItemName = ("kohaku_PM_" + `tolower $cmd`);
        menuItem 
            -l (`uiRes "m_buildEditMenu.kEditRepeat"` + " \"" + $label + "\"")
            -c $cmd
            -ecr false
            -rp "S"
            $menuItemName
            ;
        if(`repeatLast -q -numberOfHistoryItems` == 0)
            menuItem -e -en false ($parent + "|" + $menuItemName);
    }
    { // Command SubMenu
        string $menuItem = "kohaku_PM_cmdMenu";
        menuItem
            -l "Commands Menu"
            -rp "NE"
            -sm on
            -pmc ("contextToolsMM \"" + $parent + "|" + $menuItem + "\"")
            -pmo true
            $menuItem
            ;
        setParent -m ..;
    }
    { // Shelf Plus
        string $menuItemName = "kohaku_PM_shelfEtc";
        menuItem
            -l "Shelf Etc"
            -rp "NW"
            -sm on
            -pmc ("kohaku_PM_shelfEtc \"" + $parent + "|" + $menuItemName + "\"")
            -pmo true
            $menuItemName
            ;
        setParent -m ..;
    }
    { // クリック+方向即離しでメニューが選択される場合の処理
        global int $gKohaku_PM_rightClickScriptJobNum;
        string $menuItemList[] = `popupMenu -q -ia $parent`;
        for($menuItem in $menuItemList){
            $menuItem = $parent + "|" + $menuItem;
            string $rp = `menuItem -q -rp $menuItem`;
            switch($rp){
                case "N":
                case "NW":
                case "W":
                case "SW":
                case "S":
                case "SE":
                case "E":
                case "NE":
                    string $cmd = `menuItem -q -c $menuItem`;
                    $cmd += ";scriptJob -k " + $gKohaku_PM_rightClickScriptJobNum;
                    menuItem -e -c $cmd $menuItem;
                    break;
            }
        }
    }
}
// Object Menu
global proc kohaku_PM_ObjectMenu(string $parent){
    global string $gKohaku_PM_menuItemString;
    global string $gKohaku_PM_mainShelf;
    global string $gKohaku_PM_mainShelfList[];
    global string $gKohaku_PM_rightClickCmd;
    global string $gKohaku_PM_shiftRightClickCmd;
    global string $gKohaku_PM_ctrlRightClickCmd;
    global string $gKohaku_PM_shiftCtrlRightClickCmd;
    global string $gKohaku_PM_rightClickCmdList[];
    global string $gKohaku_PM_rightClickLabelList[];
    global string $gKohaku_PM_radialMenuItemString;
    global float $gKohaku_PM_rightClickTime;
    global int $gKohaku_PM_maxCharacters;
    global int $gKohaku_PM_rightClickScriptJobNum;
    setParent -m $parent;
    
    { // 右クリック
        inViewMessage -cl topCenter; // メッセージ消去
        kohaku_PM_callRightClickCmd;
    }
    int $deleteMenuItem = false; // メニューアイテムが削除されたか
    { // menuItem削除
        string $menuItemList[] = `popupMenu -q -ia $parent`;
        int $flg = off;
        for($menuItem in $menuItemList){
            $menuItem = $parent + "|" + $menuItem;
            string $rp = `menuItem -q -rp $menuItem`;
            switch($rp){
                case "":
                case "NW":
                case "SW":
                case "SE":
                case "E":
                    deleteUI -mi $menuItem;
                    $deleteMenuItem = true;
                    break;
                case "N":
                case "W":
                case "S":
                case "NE":
                    { // クリック+方向即離しでメニューが選択される場合の処理
                        string $cmd = `menuItem -q -c $menuItem`;
                        $cmd += ";scriptJob -k " + $gKohaku_PM_rightClickScriptJobNum;
                        menuItem -e -c $cmd $menuItem;
                    }
                    break;
            }
        }
    }
    { // Others
        if($deleteMenuItem){
            string $menuItem = "kohaku_PM_Others";
            menuItem
                -l "Others"
                -rp "E"
                -sm on
                -pmc ("scriptJob -k " + $gKohaku_PM_rightClickScriptJobNum + ";\n"
                    + "buildObjectMenuItemsNow \"" + $parent + "|" + $menuItem + "\";\n"
                        + "kohaku_PM_deleteMenu \"" + $parent + "|" + $menuItem + "\"")
                -pmo true
                $menuItem
                ;
            setParent -m ..;
        }
    }
}
// Kohaku Popup Menu Information Window
global proc string kohaku_PM_informationWindow(){
    string $window = "kohaku_PM_informationWindow";
    string $title = "Kohaku Popup Menu Information Window";
    if(`window -ex $window`) deleteUI -wnd $window;
    string $result = `window -ret -t $title $window`;
    return $result;
}
// ダミー
global proc kohaku_popupMenu(){}
// 初期化
{
    global string $gKohaku_PM_menuItemString; // menuItem作製用
    $gKohaku_PM_menuItemString = "";
    global string $gKohaku_PM_mainShelf; // メニューの主となるシェルフ
    $gKohaku_PM_mainShelf = "";
    global string $gKohaku_PM_mainShelfList[]; // メニューの主となるシェルフの候補一覧
    clear $gKohaku_PM_mainShelfList;
    global string $gKohaku_PM_rightClickCmd; // right Click Command
    $gKohaku_PM_rightClickCmd = "";
    global string $gKohaku_PM_shiftRightClickCmd; // ctrl + right Click Command
    $gKohaku_PM_shiftRightClickCmd = "";
    global string $gKohaku_PM_rightClickCmdList[]; // right Click Command List
    clear $gKohaku_PM_rightClickCmdList;
    global string $gKohaku_PM_rightClickLabelList[]; // right Click Command Label List
    clear $gKohaku_PM_rightClickLabelList;
    global string $gKohaku_PM_radialMenuItemString; // 右クリックコマンド選択radialMenuItem作製用
    $gKohaku_PM_radialMenuItemString = "";
    global float $gKohaku_PM_rightClickTime; // 右クリックされた時間
    $gKohaku_PM_rightClickTime = 0;
    global int $gKohaku_PM_maxCharacters; // 最大文字数
    $gKohaku_PM_maxCharacters = 25;
    global int $gKohaku_PM_rightClickScriptJobNum; // 右クリック用スクリプトジョブナンバー
    global string $gkohaku_PM_recentNonSacredToolList[]; // Recent Non Sacred Tool
    clear $gkohaku_PM_recentNonSacredToolList;
    { // シェルフmelから情報を取得してmenuItemを形成するテキスト作製
        string $shelfDir = `internalVar -ush`;
        string $shelfMelList[];
        { // 主になるシェルフを選定
            $gKohaku_PM_mainShelfList = `getFileList -fld $shelfDir -fs "shelf_Kohaku_DagMenu_*.mel"`;
            for($i = 0; $i < `size $gKohaku_PM_mainShelfList`; $i++){
                $gKohaku_PM_mainShelfList[$i] = `substitute "^shelf_Kohaku_DagMenu_" $gKohaku_PM_mainShelfList[$i] ""`;
                $gKohaku_PM_mainShelfList[$i] = `substitute ".mel$" $gKohaku_PM_mainShelfList[$i] ""`;
            }
            int $index = 0;
            if($gKohaku_PM_mainShelf == ""){
                $gKohaku_PM_mainShelf = $gKohaku_PM_mainShelfList[0];
            }else{
                $index = stringArrayFind($gKohaku_PM_mainShelf, 0, $gKohaku_PM_mainShelfList);
            }
            $shelfMelList = {("shelf_Kohaku_DagMenu_" + $gKohaku_PM_mainShelfList[$index] + ".mel")};
        }
        { // subメニューのシェルフを取得
            string $subShelfMelList[] = `getFileList -fld $shelfDir -fs "shelf_Kohaku_DagSubMenu_*.mel"`;
            appendStringArray($shelfMelList, $subShelfMelList, `size $subShelfMelList`);
        }
        { // シェルフのmelを元にmenuItem形成用のテキスト作製
            for($fileName in $shelfMelList){
                string $filePath = $shelfDir + $fileName;
                if(!`filetest -f $filePath`) continue; // ファイルが見つからない場合
                // subMenu
                if(`gmatch $fileName "shelf_Kohaku_DagSubMenu_*"`){
                    string $subMenuLabel = `substitute "^shelf_Kohaku_DagSubMenu_" $fileName ""`;
                    $subMenuLabel = `substitute ".mel$" $subMenuLabel ""`;
                    $gKohaku_PM_menuItemString += "menuItem -sm on -l " + $subMenuLabel + ";";
                }
                string $cmd, $doubleClickCmd;
                string $allLine[] = freadAllLines($filePath);
                for($line in $allLine){
                    $line = `substitute "^ +" $line ""`;
                    if(`gmatch $line "shelfButton"`){
                        $gKohaku_PM_menuItemString += "menuItem ";
                    }else if(`gmatch $line "-enableCommandRepeat *"`
                        || `gmatch $line "-label *"`
                        || `gmatch $line "-image *"`
                        || `gmatch $line "-sourceType *"`){
                        $gKohaku_PM_menuItemString += $line;
                    }else if(`gmatch $line "-command *"`){
                        $gKohaku_PM_menuItemString += $line;
                        $line = `substitute "^-command \"" $line ""`;
                        $line = `substitute "\" $" $line ""`;
                        // CheckBox
                        if(`gmatch $line "// Kohaku_dagMenuCheckBoxFlg*"`){
                            /*	
                            シェルフのコマンドで
                            // Kohaku_dagMenuCheckBoxFlg:Start
                            と
                            // Kohaku_dagMenuCheckBoxFlg:End
                            で囲まれた部分にCheckBoxのオンオフを返すプログラムを書くと繁栄
                            
                            例:
                            // Kohaku_dagMenuCheckBoxFlg:Start
                            proc int isolateSelectFlg(){
                                string $currentView = `getPanel -withFocus`;
                                return `isolateSelect -q -state $currentView`;
                            }
                            isolateSelectFlg;
                            // Kohaku_dagMenuCheckBoxFlg:End
                            */
                            $line = `match
                                "// Kohaku_dagMenuCheckBoxFlg:Start.+// Kohaku_dagMenuCheckBoxFlg:End"
                                $line`;
                            $gKohaku_PM_menuItemString += "-cb `eval(\"" + $line + "\")`";
                        }
                    }else if(`gmatch $line "-doubleClickCommand *"`){
                        $line = `substitute "^-doubleClickCommand \"" $line ""`;
                        $line = `substitute "\" $" $line ""`;
                        $doubleClickCmd = $line;
                    }else if(`gmatch $line "separator"`){
                        $gKohaku_PM_menuItemString += "menuItem -d true";
                    }else if(`gmatch $line ";"`){
                        $gKohaku_PM_menuItemString += $line;
                        // option
                        if($doubleClickCmd != ""){
                            $gKohaku_PM_menuItemString += "menuItem -ob true -c \"" + $doubleClickCmd + "\";";
                            $doubleClickCmd = "";
                        }
                    }
                }
                // subMenu閉じる
                if(`gmatch $fileName "shelf_Kohaku_DagSubMenu_*"`){
                    $gKohaku_PM_menuItemString += "setParent -m ..;";
                }
            }
        }
    }
    { // マーキングメニューのmelを元にmenuItem形成用のテキスト作製
        string $markingMenuDir = `internalVar -umm`;
        string $filePath = $markingMenuDir + "menu_Kohaku_DagMenuRightClick.mel";
        if(`filetest -f $filePath`){
            string $allLine[] = freadAllLines($filePath);
            for($line in $allLine){
                $line = `substitute "^ +" $line ""`; // 先頭にある空白を削除
                if(`gmatch $line "menuItem"`){
                    $gKohaku_PM_radialMenuItemString += "menuItem ";
                }else if(`gmatch $line "-label *"`){
                    $gKohaku_PM_radialMenuItemString += $line;
                    $line = `substitute "^-label \"" $line ""`;
                    $line = `substitute "\" $" $line ""`;
                    appendStringArray($gKohaku_PM_rightClickLabelList, {$line}, 1);
                }else if(`gmatch $line "-command *"`){
                    $line = `substitute "^-command \"" $line ""`;
                    $line = `substitute "\" $" $line ""`;
                    appendStringArray($gKohaku_PM_rightClickCmdList, {$line}, 1);
                }else if(`gmatch $line "-radialPosition *"`){
                    $gKohaku_PM_radialMenuItemString += $line;
                }else if(`gmatch $line "-image *"`){
                    $gKohaku_PM_radialMenuItemString += $line;
                }else if(`gmatch $line "-sourceType \"python\"*"`){
                    int $size =`size $gKohaku_PM_rightClickCmdList`;
                    $line = "python(\"" + $gKohaku_PM_rightClickCmdList[--$size] + "\")";
                    $line = `encodeString $line`;
                    $gKohaku_PM_rightClickCmdList[$size] = $line;
                }else if(size(`match ";" $line`) && !`gmatch $line "setParent -m ..;"`){
                    // command
                    int $size = `size $gKohaku_PM_rightClickCmdList`;
                    $gKohaku_PM_radialMenuItemString 
                        += "-c \"$gKohaku_PM_rightClickCmd = $gKohaku_PM_rightClickCmdList[" + --$size + "];"
                        + "kohaku_PM_rghtClickCmdInViewMessage\" "
                        + "-ecr false"
                        + ";"
                        ;
                }
            }
        }
        // 右クリック
        if($gKohaku_PM_rightClickCmd == ""){
            $gKohaku_PM_rightClickCmd = $gKohaku_PM_rightClickCmdList[0];
            $gKohaku_PM_shiftRightClickCmd = $gKohaku_PM_rightClickCmdList[1];
            kohaku_PM_rghtClickCmdInViewMessage;
        }
    }
    { // モデルパネルのpopupMenu -pmc編集
        string $modelPanelList[] = `getPanel -type modelPanel`;
        string $menuNameList[] = {"ObjectPop", "CommandPop"};
        string $procList[] = {"kohaku_PM_ObjectMenu", "kohaku_PM_commandMenu"};
        for($panelName in $modelPanelList){
            if(!`popupMenu -exists ($panelName + "CommandPop")`) continue;
            string $panelControl = `modelEditor -q -control $panelName`;
            int $index = 0;
            for($menuName in $menuNameList){
                string $orignPmCmd = `menu -q -pmc ($panelName + $menuName)`;
                if(!size(`match $procList[$index] $orignPmCmd`)){
                    string $pmCmd = $procList[$index] + " \"" + $panelControl + "|" + $panelName + $menuName + "\"";
                    if($menuName == "ObjectPop"){
                        $pmCmd = $orignPmCmd + ";" + $pmCmd;
                    }
                    popupMenu -e -pmc $pmCmd ($panelName + $menuName);
                }
                $index++;
            }
        }
    }
    { // 最近のツール収集
        string $window = `kohaku_PM_informationWindow`;
        scriptJob -p $window -e "ToolChanged" "kohaku_PM_recentNonSacredTool";
    }
    kohaku_popupMenu;
}


C:\Users\ユーザー名\Documents\maya\scripts
に保存
 

source "kohaku_popupMenu";

を実行、もしくは
C:\Users\ユーザー名\Documents\maya\scripts

userSetup.mel
を作成して

scriptJob -ro true -ct "MayaInitialized" "source \"kohaku_popupMenu\"";

を記入

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0