Home Technical Talk

Maya - Smooth Mesh preview

polycounter lvl 13
Offline / Send Message
[HP] polycounter lvl 13
Hey guys,

The question is simple for those with basic MEL knowledge I guess.

How do I toggle between the smoothed and non-smoothed version in Maya? I looked everywhere, and it doesn't appear to be possible to assign this to a hokey, so I assume I must do this with MEL?

I know people use 1, 2, 3 on the keyboard, but coming from Max I assigned those keys to vert, edge and poly respectively and I lost the options.

hxnIJ.jpg

TL: DR, I want a hotkey that gives me the same result as the option highlighed in blue.

Replies

  • fmnoor
    Options
    Offline / Send Message
    fmnoor polycounter lvl 17
    It's a little obscure in the hotkey editor. What you're looking for is under Miscellaneous -> HighQualityDisplay / MediumQualityDisplay / LowQualityDisplay

    The mel command associated with this is subdivDisplaySmoothness , use -smoothness to define which level you want (1,2,3)
  • [HP]
    Options
    Offline / Send Message
    [HP] polycounter lvl 13
    Excellent, thanks man!
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Hey Helder, I wrote this a while back for Autocon. Feel free to use it (works between 1 and 3)
    string $sel[] =`ls -sl`;    
        for ($thisObj in $sel){ 
            int $displaylevel[] = `displaySmoothness -query -polygonObject $thisObj`;
            if ($displaylevel[0] == 0) 
            {
                //Go to 3
                displaySmoothness -polygonObject 3;
            }
            if ($displaylevel[0] == 1) 
            {
                //Go to 3
                displaySmoothness -polygonObject 3;
            }
            if ($displaylevel[0] == 3) 
            {
                //Go to 1
                displaySmoothness -polygonObject 1;
            }
            
        }
    
  • fade1
    Options
    Offline / Send Message
    fade1 polycounter lvl 14
    and here is my piece of code. assign it to a hotkey and you're fine. with pageUp/pageDown you can toggle the level, when your mesh is in smooth preview mode.

    // toggle smooth mesh preview for selection
    // get selected mesh nodes
    string $sel[] = `ls -sl -dag -lf`;
    // set attributes
    for ($s in $sel) {
    int $v = `getAttr ($s+".displaySmoothMesh")`;
    int $w = `getAttr ($s+".smoothLevel")`;
    if ($v == 0) $v = 2; else $v = 0;
    if ($w == 0) $w = 1;
    setAttr ($s+".displaySmoothMesh") $v;
    setAttr ($s+".smoothLevel") $w;
    }
  • Bal
    Options
    Offline / Send Message
    Bal polycounter lvl 17
    fade1's script is better cause it works on multiple selections, I'm using something similar.

    Also if your coming from max, I know one thing that really bothered me when I started doing sub-d modeling in Maya, was an easy way to hide the wireframe of objects without having to deselect them (makes it hard to judge the curves of your sub-d modeling when it's visible, and it's annoying having to deselect things all the time).
    Here's a quick script to do that, maybe you'll find it useful as well.

    string $wires = `displayPref -q -wsa`;
    if ($wires == "none")
    displayPref -wsa "full";
    else
    displayPref -wsa "none";
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Bal wrote: »
    fade1's script is better cause it works on multiple selections, I'm using something similar.

    Just tested it out Bal and worked with multiple selections (it should cause I go through all of them with the for loop.) Anywho fixed up the code cause Maya by default makes objects with a subdivision level of 0
  • [HP]
    Options
    Offline / Send Message
    [HP] polycounter lvl 13
    Bal wrote: »
    I know one thing that really bothered me when I started doing sub-d modeling in Maya, was an easy way to hide the wireframe of objects without having to deselect them (makes it hard to judge the curves of your sub-d modeling when it's visible, and it's annoying having to deselect things all the time).
    Here's a quick script to do that, maybe you'll find it useful as well.

    string $wires = `displayPref -q -wsa`;
    if ($wires == "none")
    displayPref -wsa "full";
    else
    displayPref -wsa "none";

    This is awesome, I was looking for this! This is basically the F4 key in max, super useful thanks!

    fade1, I couldn't get your script to work for some reason. Going in the hotkey editor and selecting the right options under Miscellaneous worked for me, it also works on multiple selections so unless your script does something extra I don't think it's needed.

    Here's another quick question, what's the diference between "subdivDisplaySmoothness -smoothness 1;" and "subdivDisplaySmoothness -smoothness 0;"? Because there is no visual difference.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    [HP] wrote: »
    Here's another quick question, what's the diference between "subdivDisplaySmoothness -smoothness 1;" and "subdivDisplaySmoothness -smoothness 0;"? Because there is no visual difference.

    Something Maya does by default. Theres no real difference haha.
  • fade1
    Options
    Offline / Send Message
    fade1 polycounter lvl 14
    @[HP]
    i haven't tried haiddasalami script, but if you're fine with it, use it.
    i attached a picture with instructions on installing the script. there is no magic code in it, so it should work ;)
  • ian360
    Options
    Offline / Send Message
    An old post but a very interesting one... And thanks for the script fade1!
  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    Fade, I assigned your script to CTRL+T, bad short-cut; that will change. None the less it isn't working ? :(

    Bal - Your little script, because with MEL you have to declare int, float etc, how did you justify that the variables $wires was going to be a string ?
  • fade1
    Options
    Offline / Send Message
    fade1 polycounter lvl 14
    it's old, but i just tried, it still works in maya 2016. You have to select an object and then it should work.
  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    fade1 - I have it assigned as a MEL hotkey (CTRL+T) after restarting Maya, and trying on a sphere, nothing happens ?

    I can't even get Bal script to work with a Y assigned hotkey, arghh.
  • fade1
    Options
    Offline / Send Message
    fade1 polycounter lvl 14
    i think there is something wrong with yout hotkey assignment.
    What you can do to proive this:
    - copy and paste the script into the script editor
    - select everything and middle-mouse drag it to a shelf
    - then you have clickable button(don't forget to select your object)
    that shold work. or you can:
    - select your object
    - select the whole mel code in the script editor and press enter(num tab!) -> this also executes the code

    if this works(i'm sure it will ;) ) you can check your key assignment problem
  • CreativeSheep
    Options
    Offline / Send Message
    CreativeSheep polycounter lvl 8
    I don't know why my hotkeys assignments are not working, hrm.
  • Noth
    Options
    Offline / Send Message
    Noth polycounter lvl 15
    going to necro this to add what I was looking for when I stumbled across it.

    Small script to set multiple objects selected the smoothing level (3 button) to a value of your choice.

    string $sel[]=`ls -sl`;
    for ($each in $sel)
    {
        setAttr ($each+".smoothLevel") 2;
    }
  • Yogifi
    Options
    Offline / Send Message

    Bal said:
    fade1's script is better cause it works on multiple selections, I'm using something similar.

    Also if your coming from max, I know one thing that really bothered me when I started doing sub-d modeling in Maya, was an easy way to hide the wireframe of objects without having to deselect them (makes it hard to judge the curves of your sub-d modeling when it's visible, and it's annoying having to deselect things all the time).
    Here's a quick script to do that, maybe you'll find it useful as well.

    string $wires = `displayPref -q -wsa`;
    if ($wires == "none")
    displayPref -wsa "full";
    else
    displayPref -wsa "none";

    Thank you for this! Really wanted it, was using a marking menu for hiding selection UI but a toggle is always better.

    Is this safe to use with 2020? I've changed the string from wires to wires22 just in case....

    fade1 said:
    and here is my piece of code. assign it to a hotkey and you're fine. with pageUp/pageDown you can toggle the level, when your mesh is in smooth preview mode.

    // toggle smooth mesh preview for selection
    // get selected mesh nodes
    string $sel[] = `ls -sl -dag -lf`;
    // set attributes
    for ($s in $sel) {
    int $v = `getAttr ($s+".displaySmoothMesh")`;
    int $w = `getAttr ($s+".smoothLevel")`;
    if ($v == 0) $v = 2; else $v = 0;
    if ($w == 0) $w = 1;
    setAttr ($s+".displaySmoothMesh") $v;
    setAttr ($s+".smoothLevel") $w;
    }
    I know this is many years old but this is exactly what I was hoping for, a way to toggle between smooth mesh and off, including multiple selections and taking into account mesh display 2.

    It seems to work but Maya throws up a warning everytime I run it. I've reinstalled Maya from scratch twice already as I felt like I broke it with custom scripts...is anyone able to solve it so that it doesn't throw up these warnings in Maya 2020?

    // Warning: string $sel[] = `ls -sl -dag -lf`; //
    // Warning: Line 3.34 : Redeclaration of variable "$sel" shadows previous declaration at line 1. Previous value will be overwritten by explicit initializer. //


    The other issue is that it doesn't work for objects in component mode.


  • CybranM
    Options
    Offline / Send Message
    CybranM interpolator
    I'm having the same problem as Yogifi, I'd really like to toggle mesh preview with one hotkey in component mode not only in object mode.
  • Barbiturat
    Options
    Offline / Send Message
    Barbiturat polycounter lvl 10
    CybranM said:
    I'm having the same problem as Yogifi, I'd really like to toggle mesh preview with one hotkey in component mode not only in object mode.
    Hey, try this:
  • CybranM
    Options
    Offline / Send Message
    CybranM interpolator
  • Minos
Sign In or Register to comment.