frameLayout and existance [mel]


#1

I’m having a number of issues with the script I’m trying to build. Unfortunately I lack some clear documentation that would help me diagnosis the weirdness. So I’m getting a sense that Maya is doing some weird stuff and need to double check.

Basically I’m trying to avoid global variables and parallel arrays/matrixs. So I’m trying to track and adjust conditions by checking my UI through it’s own parameters. The intention is an alternative to the auto-keyframer: An UI that allows a user to select controls and attributes to track and then keyframe all in one button press/window. If you run the script as is the basic UI is set up and where I’m going with this.

The problem I’m running into is a lack of understanding of how Maya is treating window elements. For example I may have a frameLayout named

framenurbscurve1

. If I delete this frameLayout with deleteUI it removes the frame from my window but it still shows up as existing when I check with the -ex command.

Given that I want to use exist checks to make sure the object isn’t already in my manager this is an issue.

Another issue I ran into seems naming scheme related. I tried to build the names for frames using the long name node names. I had to change this to short names. Then I had to change the order of my name building.

// $sel[] is the array of results from a selection grab using `ls -sl -l` for long names.
//$selNice[] is the array of results from a selection grab using `ls -sl -sn` for short names.
//$obj is current position/object in the loop.
//$arrayPlacement is a simple variable to track current loop iteration so I can use short names.
//Iterations as described above are listed one by one below.
frameLayout -label $obj -collapsable true -bs "in" -collapse true ($obj+"Frame");
frameLayout -label $obj -collapsable true -bs "in" -collapse true ("$ selNice[$arrayPlacement]+"Frame");
frameLayout -label $obj -collapsable true -bs "in" -collapse true ("frame" +$ selNice[$arrayPlacement]);

So “|nurbsCone1Frame” to “nurbsCone1Frame” to “framenurbsCone1”. I believe it was a nurbsSphere that was returning as if the frame existed before I made it.

Also everything breaks when I add a scrollLayer to get a scrollbar and I’m not sure why.

So what do I get?
I get that there is the label and the name for a UI element. I get that I can tell Maya what to name a UI element. I could also allow Maya to name the new UI element and store the name in a variable to call later.

What don’t I get?
Is deleteUI only removing the frame from my window? What’s the lifespan of window UI elements? Not comprehensively knowledgeable about Maya’s own naming schemes. Having some trouble absorbing the way the UI is being executed and built. It seems to mantain a position in the window and new UI elements are put there?

I wanted to avoid sharing my current code but I suppose it’ll be needed. (I did intend to post the finished script here as thanks for the previous help.) I’ll put the current code in a second post after this one.

Any links to good information on building mel UI is useful. I’ve of course been looking at the reference library and a few tutorials that go into the basics. What I really need is insight in the way the logic is flowing behind the commands.


#2
global string $kfManager1;

global proc updateTextfield(string $newHappen, string $targetText)
{
textField -e -text $newHappen $targetText;
}

global proc main()
{   
    int $doesExist = `window -exists kfManagerWin`;
    if($doesExist == 0)
     {
    window -title "Keyframe Manager" -widthHeight 300 200 kfManagerWin;
    addUIWidgets();
    }
showWindow kfManagerWin;
}
global proc expandUIWidgets()
{
   
  string $sel[] = `ls -sl -l`;
  string $selNice[] = `ls -sl -sn`;
  int $arrayPlacement = 0;

   for ($obj in $sel)
   {
    
 string $test = `frameLayout -ex ("frame" + $selNice[$arrayPlacement])`;
     print ($test+"
");
     print ($obj+"
");
     print ($sel[$arrayPlacement]+"
");
     print ($selNice[$arrayPlacement]+"
");
     print ("frame" + $selNice[$arrayPlacement]+"
");
       if (0 ==`frameLayout -ex ("frame" + $selNice[$arrayPlacement])`)
       {
   setParent..;
   setParent..;
   setParent..;
  	
	frameLayout -label $obj -collapsable true -bs "in" -collapse true ("frame" + $selNice[$arrayPlacement]);
	    button -label "Remove Me" -command ("deleteUI " + ("frame" + $selNice[$arrayPlacement]));

	   gridLayout -ag true -cellWidthHeight 120 20;
    findAttributes($obj , ("frame" + $selNice[$arrayPlacement]));
      
         $arrayPlacement++;
       }
   }
}

global proc addUIWidgets()
{
  //  scrollLayout;
    columnLayout -adjustableColumn true;
    frameLayout -label "Tools" -collapsable false -bs "out";
	gridLayout           
	      -numberOfColumns 2 -cellWidthHeight 120 40;


		button -label  "Add Selected Object" -command "expandUIWidgets";
	    button -label "Quit" -command "quitProc";
	    button -label "Key";
}
global proc quitProc ()
{
    if (`window -ex kfManagerWin`) deleteUI kfManagerWin;
}
global proc findAttributes(string $currentNode, string $currentNodeNice)
{
string $foundAttributes[] = `listAttr -k -r -w -u $currentNode`;

for ($obj in $foundAttributes)
    {
       button -label $obj -bgc 1 0 0 -command ("toggleKeyThisAttr(\""+$currentNodeNice+$obj+"ButtonName"+"\")") ($currentNodeNice+$obj+"ButtonName");
    }
}

global proc toggleKeyThisAttr (string $buttonLabel)
{
vector $buttonTestBGC = `button -q -bgc $buttonLabel`;



    if ($buttonTestBGC.x == 1 && $buttonTestBGC.y == 0 && $buttonTestBGC.z == 0) 
        {
             button  -e -bgc 0 1 0 $buttonLabel;
        }
    else if ($buttonTestBGC.x == 0 && $buttonTestBGC.y == 1 && $buttonTestBGC.z == 0)
        {
            button  -e -bgc 1 0 0 $buttonLabel;
        }
   
}

global proc keyThemAll()
{
    
}

main();

//this script is intended to build a list of objects that an animator is keyframing and to save all keys the animator wants.
//directed auto keys.

#3

I realize that was a big block of text and code up there. Especially given that code is not cleaned, purged of tests/residual code yet, and commented to highlight logic paths for increased readability.

So I’d like my biggest issue. When I run my code with an if statement that checks if my frameLayout already exists


//junk and tests deleted in comparison to above code

global proc expandUIWidgets()
{
 
  string $sel[] = `ls -sl -l`;
  string $selNice[] = `ls -sl -sn`;
  int $arrayPlacement = 0;

   for ($obj in $sel)
   {
 if (0 ==`frameLayout -ex ("frame" + $selNice[$arrayPlacement])`)
  {
   setParent..;
   setParent..;
   setParent..;
  	
	frameLayout -label $obj -collapsable true -bs "in" -collapse true ("frame" + $selNice[$arrayPlacement]);
	    button -label "Remove Me" -command ("deleteUI " + ("frame" + $selNice[$arrayPlacement]));

	   gridLayout -ag true -cellWidthHeight 120 20;
    findAttributes($obj , ("frame" + $selNice[$arrayPlacement]));
      
         $arrayPlacement++;
     }
   }
}

It doesn’t work and seems to think that the frameLayouts already exist yet nothing shows up in the window. If I comment out the if statement it works fine.

Logic error check wise: I am clearly doing my existence check before creating the frameLayout that I am checking existence for.

So why on earth is it existing before I tell it to exist? :banghead:


#4

Okay I managed to get it all to a point that could be called “Final but could use improvement”. Still have not fully cleaned up the code but it does what I want it to do. Once I clean it up I’ll add it to the sticky.

I’m still unsure of a better way to go through the hierarchy of UI elements. The way I’ve done it is through using

-q -childArray

to allow me to build nested loops that I can then apply logic to. In some cases I used a Match command

                if ("" != (`match "grid" ($moreNamesObj[$y])`))

to verify what element I’m working on. Tight naming scheme of UI elements was integral to building something I could climb down logically.

Note: Going UP heirarchy is as easy as

setParent ...;

I’m also very unsure how to implement an inscript error checker to see if UI elements already exist…because that code tends to spit out 1s for…some reason.

global proc main()
{   
    int $doesExist = `window -exists kfManagerWin`;
    if($doesExist == 0)
     {
    window -title "Keyframe Manager" -widthHeight 300 200 kfManagerWin;
    addUIWidgets();
    }
showWindow kfManagerWin;
}
global proc expandUIWidgets()
{   
  string $sel[] = `ls -sl -l`;
  string $selNice[] = `ls -sl -sn`;
  int $arrayPlacement = 0;

   for ($obj in $sel)
   {
    
 string $test = `frameLayout -ex ("frame" + $selNice[$arrayPlacement])`;
/*     print ($test+"
");
     print ($obj+"
");
     print ($sel[$arrayPlacement]+"
");
     print ($selNice[$arrayPlacement]+"
");
     print ("frame" + $selNice[$arrayPlacement]+"
");*/
   //    if (0 ==`frameLayout -ex ("frame" + $selNice[$arrayPlacement])`)
      // {
   setParent kfManagerWSubCL;

  	
	frameLayout -label $obj -collapsable true -bs "in" -collapse true ("frame" + $selNice[$arrayPlacement]);
	    button -label "Remove Me" -command ("deleteUI " + ("frame" + $selNice[$arrayPlacement])) ("remove_"+$selNice[$arrayPlacement]);

	   gridLayout -ag true -cellWidthHeight 120 20 ("grid_"+$selNice[$arrayPlacement]);
    findAttributes($obj , ("frame" + $selNice[$arrayPlacement]));
      
         $arrayPlacement++;
    //   }
   }
}

global proc addUIWidgets()
{
    scrollLayout;
    columnLayout -adjustableColumn true kfManagerWMainCL;
    frameLayout -label "Tools" -collapsable false -bs "out" kfManagerWMainFL;
	gridLayout -numberOfColumns 2 -cellWidthHeight 120 40 kfManagerWMainGL;
		button -label  "Add Selected Object" -command "expandUIWidgets";
	    button -label "Quit" -command "quitProc";
	    button -label "Key" -command "keyThemAll";
	setParent kfManagerWMainCL;
    columnLayout -adjustableColumn true kfManagerWSubCL;
}

global proc quitProc ()
{
    if (`window -ex kfManagerWin`) deleteUI kfManagerWin;
}
global proc findAttributes(string $currentNode, string $currentNodeNice)
{
string $foundAttributes[] = `listAttr -k -r -w -u $currentNode`;

for ($obj in $foundAttributes)
    {
       button -label $obj -bgc 1 0 0 -command ("toggleKeyThisAttr(\""+$currentNodeNice+$obj+"ButtonName"+"\")") ($currentNodeNice+$obj+"ButtonName");
    }
}

global proc toggleKeyThisAttr (string $buttonLabel)
{
vector $buttonTestBGC = `button -q -bgc $buttonLabel`;



    if ($buttonTestBGC.x == 1 && $buttonTestBGC.y == 0 && $buttonTestBGC.z == 0) 
        {
           //changbutton from off to on
             button  -e -bgc 0 1 0 $buttonLabel;

        }
    else if ($buttonTestBGC.x == 0 && $buttonTestBGC.y == 1 && $buttonTestBGC.z == 0)
        {   
           //changbutton from on to off
            button  -e -bgc 1 0 0 $buttonLabel;

        }
   
}

global proc keyThemAll()
{
 // name of sub menu to target for query of children array string names  kfManagerWSubCL
    int $numObj = `columnLayout -q -nch kfManagerWSubCL`;
    string $namesObj[] = `columnLayout -q -ca kfManagerWSubCL`;

 
    for ($x=0;$x<$numObj;$x++)
    {
           string $moreNamesObj[];
            clear $moreNamesObj;
                int $moreNumObj;

       /* //error check
        print ("

"+$namesObj[$x]+"
");
        print ($x+" "+$numObj+" 
");
        print (`frameLayout -q -ca ($namesObj[$x])`);*/
         
        
         $moreNumObj =`frameLayout -q -nch ($namesObj[$x])`;
        $moreNamesObj = (`frameLayout -q -ca ($namesObj[$x])`);
 //          print ("
"+$moreNamesObj[0]+"  "+$moreNamesObj[1]);


        //code to query children names
            for ($y=0;$y<$moreNumObj;$y++)
                {
                if ("" != (`match "grid" ($moreNamesObj[$y])`))
                {
                    string $attNames[] = `gridLayout -q -ca ($moreNamesObj[$y])`;
                    int $attNum = `gridLayout -q -nch ($moreNamesObj[$y])`;


                    
                    for ($z=0;$z<$attNum;$z++)
                    {
                       vector $buttonTestBGC = `button -q -bgc ($attNames[$z])`;

                       if ($buttonTestBGC.x == 0 && $buttonTestBGC.y == 1 && $buttonTestBGC.z == 0)
                                {
                                setKeyframe -attribute (`button -q -label $attNames[$z]`) (`frameLayout -q -label $namesObj[$x]`);
                               // print ("
"+`button -q -label $attNames[$z]`+"  "+`frameLayout -q -label $namesObj[$x]`);
                                }                      
                    }

                }
                
                }
            
               
    }
}

main();

//this script is intended to build a list of objects that an animator is keyframing and to save all keys the animator wants.
//directed auto keys.

If anyone has any questions or comments I’m all ears. For now I’ve hit a point of brain boil and frustration that requires locating and kicking a small puppy…or maybe cooking a lobster.