//
// CC_ExprWriter
//
// A MEL to write a Expression.
//
// usage:
// (1) Select targets that will be affected by new expression.
// (2) Set the name of the expression.
// (3) Select the source object that will affect targets.
// (4) Write proxy expression in the textfield.
// (5) Decide coefficients in "[A]","[B]" fields.
// (6) Write a proxy expression in the textfield.
// (7) Push "Overwrite Expr" button.
// (8) Push "Open Expr Editor" and check the expression is added.
//
//==============================================================
//==============================================================
//
// CC_ExprWriter
//
// A MEL to write a Expression.
//
// usage:
// (1) Select targets that will be affected by new expression.
// (2) Set the name of the expression.
// (3) Select the source object that will affect targets.
// (4) Write proxy expression in the textfield.
// (5) Decide coefficients in "[A]","[B]" fields.
// (6) Write a proxy expression in the textfield.
// (7) Push "Overwrite Expr" button.
// (8) Push "Open Expr Editor" and check the expression is added.
//
//==============================================================
//==============================================================
// Window
//==============================================================
proc ccew_create_window(string $list[], string $exprName, string $srcName, string $exprText){
string $sel[] = $list;
if (`window -exists window_ccew`){deleteUI window_ccew;}
window -t "CC Expression Writer v1.0" window_ccew;
window -e -w 600 -sizeable true window_ccew;
columnLayout -adj 1;
rowColumnLayout -nr 1 -rh 1 22;
rowColumnLayout -nc 2 -cw 1 240 -cw 2 220;
button -l "(1) Select Targets and Click Here." -c "ccew_get_tgt" buttonGetTgt;
text -l " Warning : All values will be cleared." -al "center";
setParent..;
setParent..;
int $n;
for($n=0;$n<size($sel);$n+=1){
rowColumnLayout -nr 1 -rh 1 22;
rowColumnLayout -nc 11 -cw 1 50 -cw 2 150 -cw 3 70 -cw 4 50 -cw 5 50 -cw 6 50
-cw 7 50 -cw 8 50 -cw 9 50 -cw 10 50 -cw 11 50;
text -l " \"[tgt]\" : " -al "left";
nameField -o $sel[$n] ("textTgtName" + $n);
checkBox -l "Disable" ("disableId" + $n);
text -l " \"[A]\" : " -al "right";
floatField -pre 3 -v 1 ("textVarNameA" + $n);
text -l " \"[B]\" : " -al "right";
floatField -pre 3 -v 1 ("textVarNameB" + $n);
text -l " \"[C]\" : " -al "right";
floatField -pre 3 -v 1 ("textVarNameC" + $n);
text -l " \"[D]\" : " -al "right";
floatField -pre 3 -v 1 ("textVarNameD" + $n);
setParent..;
setParent..;
}
rowColumnLayout -nr 5 -rh 1 22 -rh 2 22 -rh 3 22 -rh 4 22 -rh 5 22;
separator;
text -al "left" " (2) : Choose Name and Source." ;
rowColumnLayout -nc 4 -cw 1 130 -cw 2 150 -cw 3 50 -cw 4 130;
text -l " Name of Expression : " -al "left";
textField -tx $exprName textExprName;
setParent..;
rowColumnLayout -nc 3 -cw 1 100 -cw 2 150 -cw 3 50;
text -l " Source \"[src]\" : " -al "left";
textField -tx $srcName textSrcName;
button -l "Get" -c "ccew_get_src" buttonGetSrc;
setParent..;
separator;
setParent..;
rowColumnLayout -nr 1 -rh 1 22;
text -al "left" " (3) Write Expression for each pair:";
setParent..;
scrollField -w 480 -h 120 -tx $exprText textExprField;
rowColumnLayout -nc 5 -cw 1 160 -cw 2 160 -cw 3 160;
button -l "Add Expr" -c "ccew_add_expr" buttonAddExpr;
button -l "Overwrite Expr" -c "ccew_create_expr" buttonCreateExpr;
button -l "Open Expr Editor" -c "ccew_open_expr" buttonOpenExpr;
setParent..;
setParent -u;
int $windowHeight = 120 + (22 * 8) + (22 * size($sel));
window -e -h $windowHeight window_ccew;
showWindow window_ccew;
}
//==============================================================
// Get Targets
//==============================================================
proc ccew_get_tgt(){
string $exprName = `textField -exists textExprName` ? `textField -q -tx textExprName` : "cc_expr1";
string $srcName = `textField -exists textSrcName` ? `textField -q -tx textSrcName` : "";
string $exprText = `scrollField -exists textExprField` ? `scrollField -q -tx textExprField` : "";
ccew_create_window(`ls -sl`, $exprName, $srcName, $exprText);
}
//==============================================================
// Get Source
//==============================================================
proc ccew_get_src(){
string $sel[] = `ls -sl`;
if(size($sel) > 0){
textField -e -tx $sel[0] textSrcName;
}
}
//==============================================================
// Open Expr Editor
//==============================================================
proc ccew_open_expr(){
ExpressionEditor;
}
//==============================================================
// Add Expr
//==============================================================
proc ccew_add_expr(){
string $exprName = `textField -q -tx textExprName`;
$exprOld = `expression -q -s $exprName`;
string $expr = ccew_build_expr();
$expr = ($exprOld + "\n" + $expr);
//print $expr;
expression -e -s $expr $exprName;
}
//==============================================================
// Overwrite Expr
//==============================================================
proc ccew_create_expr(){
string $exprName = `textField -q -tx textExprName`;
if(`objExists $exprName`){
}else{
expression -n $exprName -ae 1 -uc all;
}
string $expr = ccew_build_expr();
expression -e -s $expr $exprName;
}
//==============================================================
// make expression and return it
//==============================================================
proc string ccew_build_expr(){
string $text = "\n";
string $exprBase = `scrollField -q -tx textExprField`;
string $srcName = `textField -q -tx textSrcName`;
int $n = 0;
int $count = 0;
while(1){
string $temp = $exprBase;
if(`nameField -q -exists ("textTgtName" + $n)` == false){break;}
if(`checkBox -q -v ("disableId" + $n)`){$n += 1;continue;}
string $targetName = `nameField -q -o ("textTgtName" + $n)`;
$targetName = `substitute "\^\|" $targetName ""`;
float $varA = `floatField -q -v ("textVarNameA" + $n)`;
float $varB = `floatField -q -v ("textVarNameB" + $n)`;
float $varC = `floatField -q -v ("textVarNameC" + $n)`;
float $varD = `floatField -q -v ("textVarNameD" + $n)`;
$temp = substituteAllString($temp, "[tgt]", $targetName);
$temp = substituteAllString($temp, "[src]", $srcName);
$temp = substituteAllString($temp, "[A]", $varA);
$temp = substituteAllString($temp, "[B]", $varB);
$temp = substituteAllString($temp, "[C]", $varC);
$temp = substituteAllString($temp, "[D]", $varD);
$text += $temp;
$text += "\n\n";
$count += 1;
$n += 1;
}
return $text;
}
//==============================================================
// main
//==============================================================
global proc cc_expr_writer(){
string $exprName = `textField -exists textExprName` ? `textField -q -tx textExprName` : "cc_expr1";
string $srcName = `textField -exists textSrcName` ? `textField -q -tx textSrcName` : "";
string $exprText = `scrollField -exists textExprField` ? `scrollField -q -tx textExprField` : "";
ccew_create_window(`ls -sl`, $exprName, $srcName, $exprText);
}
cc_expr_writer();