//
// CC_Curve_Connector
//
// Constraint objcets to the curve.
//
// usage:
// (1) Select a curve and push "get" button to get its name.
// (2) Select Options.
// If "Use Group" is on, each connected curve will have parent group.
// "Align Method" is how to align curve position to the target object.
// "Const' Type" is how to connect curve to the object.
// Search&Replace, Prefix, and Suffix modify the name of curve.
// (3) Select Target and click bottom button.
// Source curve will be copied and be constraint to each target objects.
//
//==============================================================
//==============================================================
//
// CC_Curve_Connector
//
// Constraint objcets to the curve.
//
// usage:
// (1) Select a curve and push "get" button to get its name.
// (2) Select Options.
// If "Use Group" is on, each connected curve will have parent group.
// "Align Method" is how to align curve position to the target object.
// "Const' Type" is how to connect curve to the object.
// Search&Replace, Prefix, and Suffix modify the name of curve.
// (3) Select Target and click bottom button.
// Source curve will be copied and be constraint to each target objects.
//
//==============================================================
//==============================================================
// Window
//==============================================================
if (`window -exists window_cc_connect_ctrls`){
deleteUI window_cc_connect_ctrls;
}
window -t "CC Curve Connector v1.0" window_cc_connect_ctrls;
window -e -wh 330 212 -sizeable false window_cc_connect_ctrls;
columnLayout;
rowColumnLayout -nr 9 -rh 1 22 -rh 2 22 -rh 3 22 -rh 4 22 -rh 5 22 -rh 6 22 -rh 7 22 -rh 8 22 -rh 9 30;
rowColumnLayout -nc 3 -cw 1 120 -cw 2 150 -cw 3 50;
text -l " Name of Curve : " -al "left";
textField textCtrlName;
button -l "Get" -c "cc_connect_ctrls_get" buttonGet;
setParent..;
separator;
radioButtonGrp -nrb 2 -l " Use Group:" -l1 "Yes" -l2 "No"
-cl3 "left" "left" "left" -cw3 80 80 80 -sl 2 radioGroup;
radioButtonGrp -nrb 3 -l " Align Method:" -l1 "Point" -l2 "Orient" -l3 "Parent"
-cl4 "left" "left" "left" "left" -cw4 80 80 80 80 -sl 3 radioMethod;
radioButtonGrp -nrb 3 -l " Const' Type:" -l1 "Point" -l2 "Orient" -l3 "Parent"
-cl4 "left" "left" "left" "left" -cw4 80 80 80 80 -sl 3 radioType;
rowColumnLayout -nc 4 -cw 1 50 -cw 2 100 -cw 3 70 -cw 4 100;
text -l " Search : " -al "left";
textField textSearch;
text -l " & Replace : " -al "left";
textField textReplace;
setParent..;
rowColumnLayout -nc 4 -cw 1 50 -cw 2 100 -cw 3 70 -cw 4 100;
text -l " Prefix : " -al "left";
textField textPrefix;
text -l " Suffix : " -al "right";
textField textSuffix;
setParent..;
separator;
button -l "Select Targets and Click This to Connect" -c "cc_connect_ctrls" buttonConnect;
setParent -u;
showWindow window_cc_connect_ctrls;
proc cc_connect_ctrls_get(){
string $sel[] = `ls -sl`;
if(size($sel) > 0){
textField -e -tx $sel[0] textCtrlName;
}
}
//==============================================================
// Connect
//==============================================================
proc cc_connect_ctrls(){
string $sel[] = `ls -sl`;
if (size($sel) < 1) {error "Select Objects.";}
string $curveName = `textField -q -tx textCtrlName`;
if(`objExists $curveName` == false){error "Controller not exist.";}
int $usegrp = `radioButtonGrp -q -sl radioGroup`;
string $grpPrefix = "grp_";
int $method = `radioButtonGrp -q -sl radioMethod`;
int $type = `radioButtonGrp -q -sl radioType`;
string $search = `textField -q -tx textSearch`;
string $replace = `textField -q -tx textReplace`;
string $prefix = `textField -q -tx textPrefix`;
string $suffix = `textField -q -tx textSuffix`;
if($prefix == "" && $suffix == ""){
textField -e -tx "ctrl_" textPrefix;
$prefix = "ctrl_";
}
string $tmpStr[];
int $n;
for($n = 0; $n < (size($sel)); $n += 1){
string $ctrlName = substituteAllString($sel[$n], $search, $replace);
$ctrlName = $prefix + $ctrlName + $suffix;
duplicate -n $ctrlName $curveName;
string $alignName = $ctrlName;
if($usegrp < 2){
$alignName = $grpPrefix + $ctrlName;
group -em -n $alignName;
$tmpStr = `parentConstraint $ctrlName $alignName`;delete $tmpStr[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $alignName;
parent $ctrlName $alignName;
}
if($method == 1){$tmpStr = `pointConstraint $sel[$n] $alignName`;}
if($method == 2){$tmpStr = `orientConstraint $sel[$n] $alignName`;}
if($method == 3){$tmpStr = `parentConstraint $sel[$n] $alignName`;}
delete $tmpStr[0];
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $ctrlName;
if($type == 1){pointConstraint -mo $ctrlName $sel[$n];}
if($type == 2){orientConstraint -mo $ctrlName $sel[$n];}
if($type == 3){parentConstraint -mo $ctrlName $sel[$n];}
}
}