Home Technical Talk

Mel Layers the bane of my existence currently.

polycounter lvl 5
Offline / Send Message
deohboeh polycounter lvl 5
I'm trying to write a Mel script to set all Display layers with "LPL in it's name to visible.
Display layers seems to have very bad documentation and I cant find anything.
I've got many many layers and switching each one on one by muda-nuckin one is getting bothersome.

Any help is much appreciated. :)

Till then I shall be sincerely be banging my head into the desk.

desk_head_bang_gif_by_nino_umaka-d5xdbju.gif

Regards

Dev

Replies

  • deohboeh
    Options
    Offline / Send Message
    deohboeh polycounter lvl 5
    Even being able to query all layers would be great!
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    well in python you could do something like this
    import maya.cmds as cmds
    
    layers = cmds.ls(type='displayLayer')
    for i in layers:
        if "LPL" in i:
            cmds.setAttr('%s.visibility' % i, 1)
    
    mel code would be something like
    string $layers[] = `ls -type "displayLayer"`; 
    for ($i in $layers)
     {
         setAttr ($i + ".visibility") 1;
     }
    
    but you would have to figure out the if statmeant since i dont know how mels string fromatting works off hand
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    I spent 30 mins relearning mel haha Passerby got it. Be careful of setting the main Maya display Layer to off as that is locked.
  • deohboeh
    Options
    Offline / Send Message
    deohboeh polycounter lvl 5
    Thanks Pb!! Gonna try this tomorrow morning! This is going to be uber useful! :)
    Thanks for relearning mel for me haiddasalami! :D
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    string $layerlist[] = `ls -type "displayLayer"`;
    for ($layer in $layerlist) {
        if ($layer != "defaultLayer") {
            string $layerCheck = `substring $layer 1 3`;
            if ($layerCheck == "LPL") {
                setAttr ($layer+".visibility") 0;
            }
        }  
    }
    

    Heres some of the string formatting stuff you can do
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    still cant figure out how to check for a string in a string in mel, but if mel is required you could always do this.
    string $layers[] = `ls -type "displayLayer"`;
    
    for ($i in $layers)
    {
        if (python("'LPL'" + "in" + "'" + $i +"'"))
        {
            setAttr($i + ".visibility", 1);
        }
    }
    
    though as you seen it is most easily done via python

    edit:
    ah hadiddasaalmi beat me to it.

    @hadiddasaalmi also have to agree with you hadiddasaalmi, it just feels bad going back to mel once your used to more advanced languages like python and c#
  • deohboeh
    Options
    Offline / Send Message
    deohboeh polycounter lvl 5
    Thanks guys the script worked for me.
    I made some changes and here they are:
    string $layerlist[] = `ls -type "displayLayer"`;
    
    for ($layer in $layerlist) {
    
        if ($layer != "defaultLayer") {
    
            string $lyrChk = endsWith ($layer, "LPL");
    
            if ($lyrChk) {
                
                setAttr ($layer+".visibility") 1;
    
            }
    
        }  
    
    }
    

    @Passerby: I agree mel seems outdated compared to python. I will switch to it soon.
Sign In or Register to comment.