/* NAME: dbConditionControl.mel VERSION: 1.0 CATEGORY: Rigging FUNCTION: Creates a User Interface to simplify the process of creating Condition Nodes USAGE: 1. Copy the dbConditionControl.mel into your Maya Scripts directory (Usually found in "My Documents\maya\\scripts\"). 2. In the Maya Script Editor, type in "dbConditionControl" AUTHOR: David Bokser E-MAIL: me@davidbokser.com WEBSITE: www.davidbokser.com */ global proc dbConditionControl() { string $select[] = `ls -sl`; // Make a new window // string $window = `window -title "Condition Control" -iconName "ConditionCtrl" -widthHeight 200 55`; columnLayout -adjustableColumn true; rowColumnLayout -numberOfColumns 3 -columnWidth 1 80 -columnWidth 2 120 -columnWidth 3 50; text -label "control object"; textField srcObjectTxtFld; button -label "set" -c ("string $objects[] = `ls -sl`; string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($objects[0] + \".\" + $channels[0]) srcObjectTxtFld;") ; setParent..; rowColumnLayout -numberOfColumns 3 -columnWidth 1 80 -columnWidth 2 120 -columnWidth 3 50; text -label "target objects"; textField trgtObjectTxtFld; button -label "set" -c ("string $objects[] = `ls -sl`; string $ccobjs = \"\"; for($obj in $objects) {$ccobjs = $ccobjs + \" \" + $obj; } textField -e -text ($ccobjs) trgtObjectTxtFld;") ; setParent..; rowColumnLayout -numberOfColumns 3 -columnWidth 1 80 -columnWidth 2 120 -columnWidth 3 50; text -label "target attribute"; textField trgtAttrTxtFld; button -label "set" -c ("string $channels[] = `channelBox -q -sma mainChannelBox`; textField -e -text ($channels[0]) trgtAttrTxtFld;") ; setParent..; floatFieldGrp -numberOfFields 1 -cw 1 55 -cal 1 "left" -label "Condition" -value1 0.0 floatFldCondition; optionMenu -label "Operation" operationOption; menuItem -label "Equal"; menuItem -label "Not Equal"; menuItem -label "Greater Than"; menuItem -label "Greater or Equal"; menuItem -label "Less Than"; menuItem -label "Less or Equal"; floatFieldGrp -numberOfFields 1 -cw 1 55 -cal 1 "left" -label "If True" -value1 1.00 floatFldTrue; floatFieldGrp -numberOfFields 1 -cw 1 55 -cal 1 "left" -label "If False" -value1 0.00 floatFldFalse; button -label "Make" -c ("dbConditionApply"); button -label "Close" -command ("deleteUI -window " + $window); setParent ..; showWindow $window; // Resize the main window // window -edit -widthHeight 260 205 $window; } global proc dbConditionApply() { string $ctrlObject = `textField -q -text srcObjectTxtFld`; string $trgtObjects = `textField -q -text trgtObjectTxtFld`; string $trgtAttr = `textField -q -text trgtAttrTxtFld`; float $condition[] = `floatFieldGrp -q -v floatFldCondition`; float $ifTrue[] = `floatFieldGrp -q -v floatFldTrue`; float $ifFalse[] = `floatFieldGrp -q -v floatFldFalse`; string $operation = `optionMenu -q -v operationOption`; string $targetObjects[]; $numTokens = tokenize($trgtObjects, $targetObjects); for($obj in $targetObjects) { string $trgtObject = ($obj + "." + $trgtAttr); dbMakeCondition($ctrlObject, $trgtObject, $condition, $ifTrue, $ifFalse, $operation); } } global proc string dbMakeCondition(string $ctrlObject, string $trgtObject, float $condition[], float $ifTrue[], float $ifFalse[], string $operation) { string $conditionNode = `shadingNode -asUtility condition`; connectAttr -f $ctrlObject ($conditionNode + ".firstTerm"); setAttr ($conditionNode + ".secondTerm") $condition[0]; setAttr ($conditionNode + ".colorIfTrueR") $ifTrue[0]; setAttr ($conditionNode + ".colorIfFalseR") $ifFalse[0]; if ($operation == "Equal") setAttr ($conditionNode + ".operation") 0; if ($operation == "Not Equal") setAttr ($conditionNode + ".operation") 1; if ($operation == "Greater Than") setAttr ($conditionNode + ".operation") 2; if ($operation == "Greater or Equal") setAttr ($conditionNode + ".operation") 3; if ($operation == "Less Than") setAttr ($conditionNode + ".operation") 4; if ($operation == "Less or Equal") setAttr ($conditionNode + ".operation") 5; connectAttr -f ($conditionNode + ".outColor.outColorR") $trgtObject; string $attrName = `substitute "^[^.]*\\." $ctrlObject ""`; string $secondVal = $condition[0]; $conditionNode = `rename $conditionNode ($attrName + $secondVal)`; return $conditionNode; }