Press "Enter" to skip to content

aoObjectOrigin

[code lang="c"]
// 
// aoKit
// Andrew Odendaal's Maya Script Kit
// Software developed by Andrew Odendaal
// Code compatible with versions 7 - 8.5
//
// Author : Andrew Odendaal
// E-mail : [email protected]
// Website: http://www.andrewodendaal.com
// 

// centre object's pivot to origin
global proc aoKitObjectToOrigin() {
	string $aoKitSelection[] = `ls -sl`;
	int $size = size($aoKitSelection);

	string $pc[];
	string $oc[];

	if ($size < 1) {
		warning ("Nothing is selected");
	} else {
		global string $gMainProgressBar;
		string $group = `group -em -n "aoKitTemp#"`;

		progressBar -edit
			-beginProgress
			-isInterruptable true
			-status "Moving Object to Origin :: "
			-maxValue $size
		$gMainProgressBar;

		int $i;
		for ($i = 0; $i < $size; $i++) {
			if (`aoKitAttrExist ($aoKitSelection[$i] + ".translate")` < 1) {
				progressBar -e -step 1 -status ("Cannot Move :: " + $aoKitSelection[$i]) $gMainProgressBar;

				warning ("aoKit :: " + $aoKitSelection[$i] + " does not contain Translation Attributes.");
			} else {
				progressBar -e -step 1 -status ("aoKit :: Move Object to Origin :: " + $aoKitSelection[$i]) $gMainProgressBar;

				$pc = `pointConstraint -o 0 0 0 -weight 1 $group $aoKitSelection[$i]`;
				$oc = `orientConstraint -o 0 0 0 -weight 1 $group $aoKitSelection[$i]`;

				delete $pc[0];
				delete $oc[0];
				clear $pc;
				clear $oc;
			}
		}

		delete $group;

		print ("Objects successfully moved to Origin.\n");
		progressBar -edit -endProgress $gMainProgressBar;
	}

	clear $aoKitSelection;
	print ("Objects successfully moved to Origin.\n");
}

global proc int aoKitAttrExist(string $aoKitObject) {
	string $aoKitBuffer[];                                   
                                                     
	tokenize $aoKitObject "." $aoKitBuffer;                       
                                                     
	if (`attributeQuery -n $aoKitBuffer[0] -ex $aoKitBuffer[1]`) {
		return true;                                       
	} else {                                            
		return false;                                      
	}                                                   
}    
[/code]