global proc not executing properly

global proc not executing properly

00Six00
Contributor Contributor
720 Views
4 Replies
Message 1 of 5

global proc not executing properly

00Six00
Contributor
Contributor

I ran into an issue with a MEL script I created to make working with cables a bit easier. It works just fine if I run the entire code from the script editor but if i create a shelf button or hot key of Worms() and restart maya, the  code seems to break down and the shelf button or hot key stop functioning properly. Is there something im missing in the code to keep it from breaking. I saved the code in 2019/scripts and have tried sourcing it but that also doesnt seem to be fixing anything.

Any help would be appreciated.

global proc Worms()
{
    SelectAllPolygonGeometry;
    string $polys[] = `ls -sl`;
    string $p;
    for ($p in $polys)
    {
        int $mode = `getAttr ($p+".overrideDisplayType")`;
        
        if ($mode==0)
        {
            setAttr ($p+".overrideEnabled") 1;
            setAttr ($p+".overrideDisplayType") 2;
            setAttr ($p+".useOutlinerColor") 1;
            setAttr ($p+".outlinerColor") 1 0 0;
            clearBrush();
            strokeRef1();
            modelEditor -e -xr true modelPanel4;
            select -cl;
        }
        if ($mode==2)
        {
            //select -all;
            setAttr ($p+".overrideEnabled") 0;
            setAttr ($p+".overrideDisplayType") 0;
            setAttr ($p+".useOutlinerColor") 0;
            setAttr ($p+".outlinerColor") 0 0 0;
            opaqueBrush();
            strokeRef0();
            modelEditor -e -xr false modelPanel4;
            select -cl;   
        }
    }
}

/*
proc strokeRef1()
The procedure to select all polygon geometry in the scene and turn reference mode ON. 
*/

proc strokeRef1()
{
    SelectAllStrokes;
    string $strokes[] = `ls -sl`;
    string $s;
    for ($s in $strokes)
    {
        int $mode = `getAttr ($s+".overrideDisplayType")`;
        
        if ($mode==0)
        {
            setAttr ($s+".overrideEnabled") 1;
            setAttr ($s+".overrideDisplayType") 2;
            setAttr ($s+".useOutlinerColor") 1;
            setAttr ($s+".outlinerColor") 1 0 0;
            //select -cl;        
        }
    }
}

/*
proc strokeRef0()
The procedure to select all polygon geometry in the scene and turn reference mode OFF. 
*/

proc strokeRef0()
{
    SelectAllStrokes;
    string $strokes[] = `ls -sl`;
    string $s;
    for ($s in $strokes)
    {
        int $mode = `getAttr ($s+".overrideDisplayType")`;
        if ($mode==2)
        {
            setAttr ($s+".overrideEnabled") 0;
            setAttr ($s+".overrideDisplayType") 0;
            setAttr ($s+".useOutlinerColor") 0;
            setAttr ($s+".outlinerColor") 0 0 0;
            //select -cl;
        }
    }
}

/*
proc opaque()
The procedure to turn the transparency of the brush in the scene off.
*/

proc opaqueBrush()
{
    string $brush[] = `ls -type "brush"`;
    string $b;
    for ($b in $brush)
    {
        setAttr ($b + ".transparency1") -type double3 0 0 0;
    }
}

/*
proc clear()
The procedure to turn the transparency of the brush in the scene on.
*/

proc clearBrush()
{
    string $brush[] = `ls -type "brush"`;
    string $b;
    for ($b in $brush)
    {
        setAttr ($b + ".transparency1") -type double3 .5 .5 .5;
    }
}

/* To call the command, use the following line*/

Worms();

 

0 Likes
Accepted solutions (1)
721 Views
4 Replies
Replies (4)
Message 2 of 5

00Six00
Contributor
Contributor

I forgot to mention, the script selects all the geometry in the scene and turns reference mode on. it also toggles xray . it does the same for strokes with the procedures. the brush procedure is the transparency setting for the brush since xray doesnt work on brushes. It essentially makes it much easier to select Curves in scenes that are pretty dense.

0 Likes
Message 3 of 5

stuzzz
Collaborator
Collaborator
Accepted solution

What if you set all theses procs as global?

What error message do you have ?

0 Likes
Message 4 of 5

00Six00
Contributor
Contributor

@stuzzz 

Thanks for the reply. It looks like setting the procs to global did the trick. I had actually just thought about trying that before i read your message this morning. Seems like i would have been on the right track. 

Thanks again.

0 Likes
Message 5 of 5

stuzzz
Collaborator
Collaborator

Yep, it's a scope issue.

I wasn't sure but it make sense.

0 Likes