91 lines
2.7 KiB
Plaintext
91 lines
2.7 KiB
Plaintext
/*
|
|
This script contains procedures that supports for attribute sync between Sliders, attribute buttons and maya attributes.
|
|
*/
|
|
|
|
proc string mgp_getAttrSyncCommand(string $node, string $attrLongName)
|
|
{
|
|
return ("MGPickerAttrSyncer -s \""+$node+"\" \""+$attrLongName+"\";");
|
|
}
|
|
|
|
/*
|
|
global proc _MGP_evaluateAllAttrSyncCommands()
|
|
{
|
|
// To-Do: Do a performance pass in c++ to achieve a optimum sync scheduling system.
|
|
global int $MGPICKER_startTime_refresh;
|
|
$elapsedTime = `timerX -startTime $MGPICKER_startTime_refresh`;
|
|
string $pattern = "*MGPickerAttrSyncer*";
|
|
if ($elapsedTime > 1)
|
|
{
|
|
$jobs = `scriptJob -listJobs`;
|
|
for($i=0; $i<size($jobs); ++$i)
|
|
{
|
|
string $script_str = $jobs[$i];
|
|
if(`gmatch $script_str $pattern`)
|
|
{
|
|
$parts = stringToStringArray($script_str, "\"");
|
|
string $nodeAttr[] = stringToStringArray($parts[5], ".");
|
|
string $syncCmd = `mgp_getAttrSyncCommand $nodeAttr[0] $nodeAttr[1]`;
|
|
eval ($syncCmd);
|
|
}
|
|
}
|
|
$MGPICKER_startTime_refresh = `timerX`;
|
|
}
|
|
}
|
|
*/
|
|
|
|
proc mgp_createScriptJobDoit(string $node, string $attrLongName)
|
|
{
|
|
// Because we need to catchQuiet when call this function, which occupies the return value,
|
|
// so global variable is used here as a stupid workaround:
|
|
global int $MGPICKER_WatcherID;
|
|
string $syncCmd = `mgp_getAttrSyncCommand $node $attrLongName`;
|
|
// to-do: check why _MGP_evaluateAllAttrSyncCommands helped but now it messed up.
|
|
$MGPICKER_WatcherID = `scriptJob -killWithScene -attributeChange ($node+"."+$attrLongName) $syncCmd`;
|
|
}
|
|
|
|
global proc int MGP_CreateWatcher(string $node, string $attrLongName)
|
|
{
|
|
if(!`objExists $node`)
|
|
{
|
|
return 0;
|
|
}
|
|
if(`nodeType $node` == "container")
|
|
{
|
|
string $bindAttrs[]=`container -q -bindAttr $node`;
|
|
int $sz = size($bindAttrs);
|
|
for($i=0; $i<$sz; $i+=2)
|
|
{
|
|
if($bindAttrs[$i+1] == $attrLongName)
|
|
{
|
|
string $realObjDotName = $bindAttrs[$i];
|
|
string $temp[]=`stringToStringArray $realObjDotName "."`;
|
|
$node = $temp[0];
|
|
$attrLongName = $temp[1];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(!`attributeExists $attrLongName $node`)
|
|
{
|
|
return 0;
|
|
}
|
|
int $error = catchQuiet(`mgp_createScriptJobDoit $node $attrLongName`);
|
|
if($error)
|
|
{
|
|
return 0;
|
|
}
|
|
global int $MGPICKER_WatcherID;
|
|
return $MGPICKER_WatcherID;
|
|
}
|
|
global proc MGP_DeleteWatcher(int $id)
|
|
{
|
|
if(!`scriptJob -ex $id`)
|
|
{
|
|
return;
|
|
}
|
|
scriptJob -kill $id;
|
|
}
|
|
global proc int MGP_WatcherExist(int $id)
|
|
{
|
|
return `scriptJob -ex $id`;
|
|
} |