Now for the FUN part. We will need to write the following MEL procedures. Replace "character" with the unique name of the character the GUI is for. ("CHARACTER" in all caps should be replaced with a UNIQUE transform node name in the character's heirarchy, most likely the "top node".)
global proc characterGUI()
{
//loads the GUI
}
global proc characterGUIWin()
{
//builds the GUI window
}
global proc characterLocateGUI()
{
//prompts the user to locate the HTML file
}
global proc characterLocateFile()
{
//loads HTML file location into global variable
}
global proc characterGetNameSpace()
{
//finds character namespace (if present) and loads into global variable
}
global proc characterSelect(string $control, int $tool)
{
//selects desired control and sets proper tool
}
characterGUI
This procedure will check for namespace and GUI file location.
If the namespace is not loaded, it will call "characterGetNameSpace".
If the GUI file location is not loaded, it will call "characterLocateGUI".
Finally, it will call "characterGUIWin" and load the window.
global proc characterGUI()
{
//loads the GUI
//declare global variables to hold namespace & file location
global string $characterNameSpace;
global string $characterGUIlocation;
string $chNode = "CHARACTER"; //unique name of character's "Top Node"
//check for namespace
if (!(`objExists ($characterNameSpace + $chNode)`))
characterGetNameSpace;
//check for file location
if ($characterGUIlocation == "")
characterLocateGUI;
else
characterGUIWin;
}
characterGUIWin
This procedure builds the GUI window. Easy.
global proc characterGUIWin()
{
//builds the GUI window
global string $characterGUIlocation;
//delete's the GUI widow if it's already open
if (`window -exists "characterGUI"`)
deleteUI "characterGUI";
window -t "Character GUI" -w 300 -h 437 -rtf 1 "characterGUI";
columnLayout -w 300;
paneLayout -w 300 -h 437;
//width and height should match image
webBrowser -width 300 -height 437 -url ("file:///" + $characterGUIlocation);
setParent ..;
setParent ..;
showWindow "characterGUI";
}
characterLocateGUI
This procedure loads up a window to prompt the user to locate the html file.
global proc characterLocateGUI()
{
//prompts the user to locate the HTML file
//delete the window if for some crazy reason, it exists
if (`window -exists "characterFindWin"`)
deleteUI "characterFindWin";
window -w 250 -t "Locate CharacterGUI" -rtf 1 "characterFindWin";
columnLayout -w 250;
//button calls spellyLocateFile and closes the window
button -w 250 -l "Locate characterGUI.htm" -c "characterLocateFile; deleteUI \"characterFindWin\";";
setParent ..;
showWindow "characterFindWin";
}
characterLocateFile This procedure presents a file dialog box to the user and loads the selection into a global variable.
global proc characterLocateFile()
{
//loads HTML file location into global variable
global string $characterGUIlocation;
$characterGUIlocation = `fileDialog -dm "characterGUI.htm"`;
characterGUIWin;
}
characterGetNameSpace This procedure identifies the namespace (if any) when a character is imported or referenced.
global proc characterGetNameSpace()
{
//finds character namespace (if present) and loads into global variable
global string $characterNameSpace;
string $chNode = "CHARACTER"; //the unique name of the character's "top node"
string $ns;
string $lsBuffer[];
string $tokBuffer[];
if (`objExists $chNode`) //sets namespace as blank if no namespace is present
{
$ns = "";
}
else //searches through every transform node until it finds the "top node"
{
$lsBuffer = `lsType "transform"`;
for ($i=0; $i<(size($lsBuffer)); $i++)
{
tokenize $lsBuffer[$i] ":" $tokBuffer;
for ($j=1; $j<(size($tokBuffer)); $j++)
{
if ($tokBuffer[$j] == $chNode)
{
$ns = ($tokBuffer[0] + ":");
}
}
}
}
$characterNameSpace = $ns;
}
characterSelect This procedure selects the desired control (with namespace) and changes current tool if appropriate.
global proc characterSelect(string $control, int $tool)
{
//selects desired control and sets proper tool
global string $characterNameSpace;
string $ns = $characterNameSpace;
string $ctxMove = `manipMoveContext`;
string $ctxRot = `manipRotateContext`;
if (!(`objExists ($ns + "CHARACTER")`)) characterGetNameSpace;
select -r ($ns + $control);
if ($tool == 1) setToolTo $ctxRot;
else if ($tool == 2) setToolTo $ctxMove;
} |