Home Technical Talk

Need help with Custom Marking Menu.

polycounter lvl 9
Offline / Send Message
jimpaw polycounter lvl 9
Hi!

I have started to build a custom marking menu in Maya 2015. I have a lot of mel scripts that i cant get to work since i dont understand mel. Here are a couple of questions:

1. How do i create a toggle display uv distortion button? I can only make it
to go on and off on seperate buttons, but not make just one button on the menu that does both.

I also need toggle to theese functions aswell:

Toggle Display checker maps
Toggle Show hard edges in red color
Toggle hide selected.
Toggle unselected

2. Is there any standard code you can write that do a toggle on most commands in Maya?

Pivot
1.move pivot to center of selection (select edges around a cylinder and the pivot moves to the center of the selection)
2.Drop pivot to lowest point on selected object from current possition.

UV

---
1. Copy and paste uv. like ninja dojo script has where it actually works rather okay. lets say that you UV two faces and you want to copy that uv to new faces, hopefully that makes sence.
2. Colorise different UV shells



Other questions:
i am looking for forums where people post there own scripts. something like this awsome tread: http://forums.cgsociety.org/showthread.php?f=89&t=14082

Also i wonder if there is any way to change the apperance on the boxes surrounding the text in the marking menus,like colors and so on? Would be great to colorcode them.

Thanks!

Replies

  • throttlekitty
    Options
    Offline / Send Message
    Here's a script for toggling the UV checkerboard. You can replace "dct" with "ddt" for the distortion shader. The script is a common toggle, set a variable to check the state (what mode are we in?), and simple logic to do this, that or the other depending on what state we are in. For types that have more than two states, you'd just add another if line.
    // Toggles UV texture checkerboard
    
    global proc ToggleCheckerTex()
        {
            string $CurVal = `textureWindow -q -dct polyTexturePlacementPanel1`;
            if ($CurVal == 0)       
            {
                textureWindow -e -dct 1 polyTexturePlacementPanel1;
            }
            else if ($CurVal == 1)
            {
                textureWindow -e -dct 0 polyTexturePlacementPanel1;
            }
        }
        ToggleCheckerTex()
    

    For Hard Edge viewing, shift-RMB > Soften/Harden Edge > Toggle Soft Edge Display. I'm positive I downloaded someones script that had nice object pivot options just like you mentioned, but I can't seem to find it right now, I'll check later.

    If you edit the .mels for your marking menus, each entry has options for italic and bold (not visible in the MM editor), but I don't think colors can be specified.


    While we're at it, here's a simple script that I have in the hotkey editor for User Marking Menus; one button for two menus. In the modeling pane, I get my basic MM set, and in the UV panel/window, I get the MM I made for UV editing. Replace the "source" portions to match the names of what you're using.
    string $panel = `getPanel -withFocus`;
    string $panelType = `getPanel -typeOf $panel`;
    
    if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
    if ($panelType ==  "modelPanel") {
    	popupMenu -button 1 -ctl false -alt false -sh false -allowOptionBoxes true -parent viewPanes -mm 1 tempMM; 
        source "menu_tkBasic";
    } else {
        popupMenu -button 1 -ctl false -alt false -sh false -allowOptionBoxes true -parent polyTexturePlacementPanel1 -mm 1 tempMM; 
        source "menu_tkUV";
    }
    
  • perfect_paradigm
    Options
    Offline / Send Message
    perfect_paradigm polycounter lvl 7
    Well I wrote some of the scripts for you. Maybe you can learn from them to understand how to write some of the other toggle scripts you were wanting.

    I guess you've already been using the script editor to see the code ran by buttons etc.? And toggling on History > Echo All Commands when needed when the code you need isn't showing? (always uncheck it when done or it can slow down Maya)

    I don't know where to start to help you understand Mel, have you used other programming languages, or are you a complete programming beginner?

    Instructions:

    Create mel files with the same names as the procedurces (example: PP_ToggleHideSelectedObjs.mel)

    Put the mel script proc files in one of your script folders, for windows it's in your Documents/Maya folder.

    To run the procs just call name of procs (example: PP_ToggleHideSelectedObjs;) Put that in shelf button or marking menu


    There's already a toggle button for checker display in UV editor, but I guess you were wanting it somewhere else?

    global proc PP_ToggleCheckerMap()
    {
    int $displayCheckeredState = `textureWindow -query -displayCheckered polyTexturePlacementPanel1`;
    textureWindow -edit -displayCheckered (!$displayCheckeredState) polyTexturePlacementPanel1;
    }
    
    PP_ToggleCheckerMap; // To call proc
    

    global proc PP_ToggleHideSelectedObjs()
    {
        global int $IsObjsHidden = 0;
        
        if(!$IsObjsHidden)
        {       
            if(size(`ls -sl`))
            {
                HideSelectedObjects;
                $IsObjsHidden = 1;
            }
        }
        else
        {
            ShowLastHidden;
            $IsObjsHidden = 0;
        }
    }
    
    PP_ToggleHideSelectedObjs; // To call proc  
    
    

    //Puts pivot at bottom of last selected object//
    
    global proc PP_BasePivot()
    {
    string $sel[] = `ls -sl -o -tail 1`;
    float $BB[] = `exactWorldBoundingBox $sel[0]`;
    float $Pivot[] = `xform -q -piv -ws $sel[0]`;
    xform -piv $Pivot[0] $BB[1] $Pivot[2] -ws $sel[0];
    }
    
    PP_BasePivot; // To call proc
    

    //Puts pivot at bottom of all selected objects//
    
    global proc PP_BasePivot()
    {
        string $sel[] = `ls -sl -o`;
        
        for($i=0;$i<size($sel);$i++)
        {        
            float $BB[] = `exactWorldBoundingBox $sel[$i]`;
            float $Pivot[] = `xform -q -piv -ws $sel[$i]`;
            xform -piv $Pivot[0] $BB[1] $Pivot[2] -ws $sel[$i];
        }
    }
    
    PP_BasePivot; // To call proc
    


    I'm not sure what you mean about center pivot to selected components such as edges, that's how it already works in Maya. If you're talking about centering it after you've moved the pivot then the proc below should do it.

    //Center pivot to center of component or object selections//
    
    global proc PP_CenterPivotToSelection()
    {    
        
        string $sel[] = `ls -sl`;
        select $sel;
        
        string $selObjs[] = `filterExpand -sm 10 -sm 12 -ex 0`;
        if(size($selObjs))
        {
            CenterPivot;
        }
    }
    
    PP_CenterPivotToSelection; // To call proc
    


    Here's a Maya scripts thread on polycont. I recently posted a few of my scripts there.
    http://www.polycount.com/forum/showthread.php?p=2085929#post2085929


    Here's the mel command reference:
    http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/Commands/index.html
  • throttlekitty
    Options
    Offline / Send Message
    I was wanting a script to toggle selection visibility, I ended up using it a lot in my current project, I typically use layers for that. I found this script in trying to figure out how to toggle for all views, and it does the trick:
    http://www.seneve.de/downloads/mel/mel_source_3.php
  • jimpaw
    Options
    Offline / Send Message
    jimpaw polycounter lvl 9
    Well I wrote some of the scripts for you. Maybe you can learn from them to understand how to write some of the other toggle scripts you were wanting.

    I guess you've already been using the script editor to see the code ran by buttons etc.? And toggling on History > Echo All Commands when needed when the code you need isn't showing? (always uncheck it when done or it can slow down Maya)

    I don't know where to start to help you understand Mel, have you used other programming languages, or are you a complete programming beginner?

    Instructions:

    Create mel files with the same names as the procedurces (example: PP_ToggleHideSelectedObjs.mel)

    Put the mel script proc files in one of your script folders, for windows it's in your Documents/Maya folder.

    To run the procs just call name of procs (example: PP_ToggleHideSelectedObjs;) Put that in shelf button or marking menu


    There's already a toggle button for checker display in UV editor, but I guess you were wanting it somewhere else?

    global proc PP_ToggleCheckerMap()
    {
    int $displayCheckeredState = `textureWindow -query -displayCheckered polyTexturePlacementPanel1`;
    textureWindow -edit -displayCheckered (!$displayCheckeredState) polyTexturePlacementPanel1;
    }
    
    global proc PP_ToggleHideSelectedObjs()
    {
        global int $IsObjsHidden = 0;
        
        if(!$IsObjsHidden)
        {
            HideSelectedObjects;
            $IsObjsHidden = 1;
        }
        else
        {
            ShowLastHidden;
            $IsObjsHidden = 0;
        }
    }
    
    //Puts pivot at bottom of last selected object//
    
    global proc PP_BasePivot()
    {
    string $sel[] = `ls -sl -o -tail 1`;
    float $BB[] = `exactWorldBoundingBox $sel[0]`;
    float $Pivot[] = `xform -q -piv -ws $sel[0]`;
    xform -piv $Pivot[0] $BB[1] $Pivot[2] -ws $sel[0];
    }
    
    //Puts pivot at bottom of all selected objects//
    
    global proc PP_BasePivot()
    {
        string $sel[] = `ls -sl -o`;
        
        for($i=0;$i<size($sel);$i++)
        {        
            float $BB[] = `exactWorldBoundingBox $sel[$i]`;
            float $Pivot[] = `xform -q -piv -ws $sel[$i]`;
            xform -piv $Pivot[0] $BB[1] $Pivot[2] -ws $sel[$i];
        }
    }
    
    I'm not sure what you mean about center pivot to selected components such as edges, that's how it already works in Maya. If you're talking about centering it after you've moved the pivot then the proc below should do it.

    //Center pivot to center of component or object selections//
    
    global proc PP_CenterPivotToSelection()
    {    
        
        string $sel[] = `ls -sl`;
        select $sel;
        
        string $selObjs[] = `filterExpand -sm 10 -sm 12 -ex 0`;
        if(size($selObjs))
        {
            CenterPivot;
        }
    }
    
    Here's a Maya scripts thread on polycont. I recently posted a few of my scripts there.
    http://www.polycount.com/forum/showthread.php?p=2085929#post2085929



    Here's the mel command reference:
    http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/Commands/index.html



    Thanks alot for the help! to bad almost none of the script worked. I copied the text and pasted into the mel window but nothing happens. Do i have to create a mel script and put in the Maya folder you specified? i shouldnt have to do that since maya creates new script with the pasted mel code right? The texture script worked thought, but only when the uv editor is open. As soon as i clode the window the uv checker goes away.

    I am a complete beginner at scripting, i only scavage the world for scripts from other people and paste in =P Thanks for the tips regarding turning off the echo command to save memory, i will make sure to do that in the future!
  • jimpaw
    Options
    Offline / Send Message
    jimpaw polycounter lvl 9
    Here's a script for toggling the UV checkerboard. You can replace "dct" with "ddt" for the distortion shader. The script is a common toggle, set a variable to check the state (what mode are we in?), and simple logic to do this, that or the other depending on what state we are in. For types that have more than two states, you'd just add another if line.
    // Toggles UV texture checkerboard
    
    global proc ToggleCheckerTex()
        {
            string $CurVal = `textureWindow -q -dct polyTexturePlacementPanel1`;
            if ($CurVal == 0)       
            {
                textureWindow -e -dct 1 polyTexturePlacementPanel1;
            }
            else if ($CurVal == 1)
            {
                textureWindow -e -dct 0 polyTexturePlacementPanel1;
            }
        }
        ToggleCheckerTex()
    
    For Hard Edge viewing, shift-RMB > Soften/Harden Edge > Toggle Soft Edge Display. I'm positive I downloaded someones script that had nice object pivot options just like you mentioned, but I can't seem to find it right now, I'll check later.

    If you edit the .mels for your marking menus, each entry has options for italic and bold (not visible in the MM editor), but I don't think colors can be specified.


    While we're at it, here's a simple script that I have in the hotkey editor for User Marking Menus; one button for two menus. In the modeling pane, I get my basic MM set, and in the UV panel/window, I get the MM I made for UV editing. Replace the "source" portions to match the names of what you're using.
    string $panel = `getPanel -withFocus`;
    string $panelType = `getPanel -typeOf $panel`;
    
    if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
    if ($panelType ==  "modelPanel") {
        popupMenu -button 1 -ctl false -alt false -sh false -allowOptionBoxes true -parent viewPanes -mm 1 tempMM; 
        source "menu_tkBasic";
    } else {
        popupMenu -button 1 -ctl false -alt false -sh false -allowOptionBoxes true -parent polyTexturePlacementPanel1 -mm 1 tempMM; 
        source "menu_tkUV";
    }
    

    Thanks alot man! both worked, but only when the texture editor is open, as sson as i close it, the textures dissapear? probably a function in maya. Thanks alot for helping me out!
  • perfect_paradigm
    Options
    Offline / Send Message
    perfect_paradigm polycounter lvl 7
    @jimpaw

    They all work for me. I made the mel script files for you to make it easier.

    Just download them and put them in your scripts folder.

    Directory for Windows OS:

    Documents\maya\scripts

    Then you can run the script by just it's name.

    So to run PP_BasePivot.mel script file, you would put this code: PP_BasePivot; in a shelf button, or marking menu command or wherever you want.

    Info:

    PP_ToggleCheckerMap Requires UV Texture Editor to be open, but you can minimize this window

    PP_BasePivot & PP_BasePivotAll are variants for your preference. PP_BasePivot puts pivot at bottom of just last selected mesh, PP_BasePivotAll does so for all selected meshes.

    PP_CenterPivotToSelection centers pivot for component selections (edges, verts, faces) and object selections.


    Downloads:

    https://www.dropbox.com/s/in4sdg052xmbrzd/PP_BasePivot.mel

    https://www.dropbox.com/s/5mu2on3rw60kdvc/PP_BasePivotAll.mel

    https://www.dropbox.com/s/b28v4pool29lt0t/PP_CenterPivotToSelection.mel

    https://www.dropbox.com/s/beyl8pcgt72z6md/PP_ToggleCheckerMap.mel

    https://www.dropbox.com/s/4d210qat0aontgm/PP_ToggleHideSelectedObjs.mel


    Btw, I'm writing a few more scripts I think you'll like so check back.
  • jimpaw
    Options
    Offline / Send Message
    jimpaw polycounter lvl 9
    @jimpaw

    They all work for me. I made the mel script files for you to make it easier.

    Just download them and put them in your scripts folder.

    Directory for Windows OS:

    Documents\maya\scripts

    Then you can run the script by just it's name.

    So to run PP_BasePivot.mel script file, you would put this code: PP_BasePivot; in a shelf button, or marking menu command or wherever you want.

    Info:

    PP_ToggleCheckerMap Requires UV Texture Editor to be open, but you can minimize this window

    PP_BasePivot & PP_BasePivotAll are variants for your preference. PP_BasePivot puts pivot at bottom of just last selected mesh, PP_BasePivotAll does so for all selected meshes.

    PP_CenterPivotToSelection centers pivot for component selections (edges, verts, faces) and object selections.


    Downloads:

    https://www.dropbox.com/s/in4sdg052xmbrzd/PP_BasePivot.mel

    https://www.dropbox.com/s/5mu2on3rw60kdvc/PP_BasePivotAll.mel

    https://www.dropbox.com/s/b28v4pool29lt0t/PP_CenterPivotToSelection.mel

    https://www.dropbox.com/s/beyl8pcgt72z6md/PP_ToggleCheckerMap.mel

    https://www.dropbox.com/s/4d210qat0aontgm/PP_ToggleHideSelectedObjs.mel


    Btw, I'm writing a few more scripts I think you'll like so check back.

    Thanks a ton!

    You are awsome! By the way i am using Maya 2015. Really looking forward to see your other scripts. if you go to www.handpaintedtextures.com you can check out my textures and 3d models. Thats the thing i do the most. Scripts i really need is related to faster uv workflow. copy uv paste uv that actually works, that kind of thing and especially scripts that cleans the mesh. I already have a shortcut to Mayas clean command but would like something more with graphic feedback. Ninja dojo has an awsome script built in where you can change the normal angle in realtime wich makes normals fun to work with. Do you need any scripts yourself? perhaps i can point to some cool functions i have seen?


    Now all of the scripts work perfect except PP_CenterPivotToSelection. That one does what mayas built in does. it just centers the pivot when you are in object mode, however when you select a loop around a cylinder for example it doesnt put the pivot in rthe center on that selection when i go back out in object mode. Hopefully it makes sence. Thanks !
Sign In or Register to comment.