//ijChannelTransfer v1 for Maya 6.0.1 //Created by Ian Jones //Copyright 2005 //Last Changed Sep 26, 2005 //Allows you to transfer values based on object selection order or swap the attributes. // Usage: // simply run the command: // ijChannelTransfer "-channel <> -mode <>"; // Example channel string: "t r s" -> translateXYZ, rotateXYZ, scaleXYZ, // "tY tX sX rZ -> translateXY, scaleX, rotateZ // "all" -> all keyable // Example modes index: 1 -> Transfer // 2 -> Swap // 3 -> Copy // 4 -> Paste // REQUIRES zooUtils to run global proc ijChannelTransfer(string $optionStr) { //-- Parse/Define varaiables and modes string $optionTemp[]; int $mode = 3; // 1 :: transfer A -> B, 2 :: transfer A <-> B, 3 :: Copy A, 4 :: Paste to A string $channelStr; int $allChannels = 0; $optionTemp = `zooGetFlagArguments $optionStr mode`; if( `size $optionTemp` ) $mode = $optionTemp[0]; $optionTemp = `zooGetFlagArguments $optionStr channel`; if( `size $optionTemp` ) $channelStr = $optionTemp[0]; //------- //-- Begin:: Save selection, store attributes, transfer attributes, return result //------- //Save selection for transfer, warn if zero selections are made string $selection[] = `ls -sl`; if( !`size $selection` )warning "Please select at least one object"; //Seperate the channels into an array string $axes[] = { "x","y","z" }; string $channels[]; tokenize $channelStr " " $channels; //If channel string is all then fill the array with all keyable attributes from sel[0] if ( $channelStr == "all" )select $selection[0];clear $channels;$channels = `listAttr -keyable`;$allChannels = 1; // 1-Transfer, 2-Swap, 3-Copy, 4-Paste switch ($mode) { case 1: for( $channel in $channels ) { //Ensure the channel exists, then query children attributes if( `objExists ( $selection[0] + "." + $channel )` ) { string $childAttrs[] = `attributeQuery -n $selection[0] -lc $channel`; if( `size $childAttrs` ) { //For each attribute query the value, ensure the target exists then set target for( $n=0; $n<`size $childAttrs`; $n++ ) { float $attrTemp = `getAttr ( $selection[0] + "." + $childAttrs[$n] )`; if( `objExists ( $selection[1] + "." + $childAttrs[$n] )` ) setAttr ( $selection[1] + "." + $childAttrs[$n] ) $attrTemp; } } else { //For each attribute query the value, ensure the target exists then set target float $attrTemp = `getAttr ( $selection[0] + "." + $channel )`; if( `objExists ( $selection[1] + "." + $channel )` ) setAttr ( $selection[1] + "." + $channel ) $attrTemp; } } } break; case 2: for( $channel in $channels ) { //Repeat proccess of Transfer (see above) except save out attribute values from target // before setting so they can me applied to sel[0]. if( `objExists ( $selection[0] + "." + $channel )` ) { string $childAttrs[] = `attributeQuery -n $selection[0] -lc $channel`; if( `size $childAttrs` ) { for( $n=0; $n<`size $childAttrs`; $n++ ) { float $attrTempA = `getAttr ( $selection[0] + "." + $childAttrs[$n] )`; if( `objExists ( $selection[1] + "." + $childAttrs[$n] )` ) { float $attrTempB= `getAttr ( $selection[1] + "." + $childAttrs[$n] )`; setAttr ( $selection[1] + "." + $childAttrs[$n] ) $attrTempA; setAttr ( $selection[0] + "." + $childAttrs[$n] ) $attrTempB; } } } else { float $attrTempA = `getAttr ( $selection[0] + "." + $channel )`; if( `objExists ( $selection[1] + "." + $channel )` ) { float $attrTempB = `getAttr ( $selection[1] + "." + $channel )`; setAttr ( $selection[1] + "." + $channel ) $attrTempA; setAttr ( $selection[0] + "." + $channel ) $attrTempB; } } } } break; case 3: //Defining global array to house the saved channelName^channelValue global string $ijChannelTransferStoredAttr[0]; //Clears global to preserve memory clear $ijChannelTransferStoredAttr; for( $channel in $channels ) { if( `objExists ( $selection[0] + "." + $channel )` ) { string $childAttrs[] = `attributeQuery -n $selection[0] -lc $channel`; if( `size $childAttrs` ) { for( $n=0; $n<`size $childAttrs`; $n++ ) { float $attrTemp = `getAttr ( $selection[0] + "." + $childAttrs[$n] )`; $ijChannelTransferStoredAttr[`size $ijChannelTransferStoredAttr`] = ( $childAttrs[$n] + "^" + $attrTemp ); } } else { float $attrTemp = `getAttr ( $selection[0] + "." + $channel )`; $ijChannelTransferStoredAttr[`size $ijChannelTransferStoredAttr`] = ( $channel + "^" + $attrTemp ); } } } break; case 4: //Explodes global array from targetChannel^targetValue to channelTemp[] - Name = index 0, Value= index 1 for( $channel in $ijChannelTransferStoredAttr ) { string $channelTemp[]; tokenize $channel "^" $channelTemp; if( `size $channelTemp`) { if( `objExists ( $selection[0] + "." + $channelTemp[0] )` ) { float $attrTemp = $channelTemp[1]; setAttr ( $selection[0] + "." + $channelTemp[0] ) $attrTemp; } } } break; default: warning "Please set a valid mode using -mode 1-4 :: 1-Xfer 2-Swap 3-Copy 4-Paste"; break; } }