Apr 5 2013

Maya swaping out influences of a skincluster with mel

quick script i put together with the help of my buddy Paul Thuriot, for swapping out one influence transform for another in a skin cluster. this can be useful for transferring skinning information to different joints when editing or adding new functionality to riggs.

This code is kind of a cheat, so you don’t have to store the actual weights and entire data structure that goes with saving and loading weights.
the tricky thing here’s is running the appropriate steps in the proper order so that maya does all the heavy lifting for us.
take a looky 😀

	proc swapSkinClusterInflunces(string $oldInf,string $newInf,string $skinClus)
		string $inf[] = `skinCluster -q -inf $skinClus`;
		for ($i in $inf) setAttr ($i+".liw") 1;
		setAttr ($skinClus+".normalizeWeights") 0;
		skinCluster -e -ai $newInf $skinClus;
		setAttr ($oldInf+".liw") 0;
		setAttr ($skinClus+".normalizeWeights") 1;
		skinCluster -e -ri $oldInf $skinClus;
		for ($i in $inf) setAttr ($i+".liw") 0;
	proc moveNonUserBlockInfluencesToUserBlock()
		source "blockPartySoftBootStrap.mel";
		string $newL[];
		string $sknClust[] = `ls -type "skinCluster"`;
		for ($e in $sknClust)
			int $sknProc = 1;
			setAttr ($e+".normalizeWeights") on;
			string $inf[] = `skinCluster -q -inf $e`;
			for ($j in $inf)
				string $geom[] = `skinCluster -q -g $e`;
				string $LName = longNameOf($j);
				string $buffer[];
				tokenize $LName "|" $buffer;
				if ((size($buffer[0]) < 4) || `substring $buffer[0] 1 4` != "user")
					if ($sknProc)
						$sknProc = 0;
						print ("....Processing "+$e+"' deforming '"+longNameOf($geom[0])+"'\n");
					print ("\T\TReplacing Influence '"+longNameOf($j)+"'\n");
					//make and hang new locators if they do not exist...
					string $midManNm = shortNameOf($j)+"mvdENV";
					if (!objExists($midManNm))
						string $midMan[] = `spaceLocator -n ($midManNm)`;
						parent $midMan[0] $j;
						setAttr ($midMan[0]+".translateX") 0;
						setAttr ($midMan[0]+".translateY") 0;
						setAttr ($midMan[0]+".translateZ") 0;
						setAttr ($midMan[0]+".rotateX") 0;
						setAttr ($midMan[0]+".rotateY") 0;
						setAttr ($midMan[0]+".rotateZ") 0;
						setAttr ($midMan[0]+".scaleX") 1;
						setAttr ($midMan[0]+".scaleY") 1;
						setAttr ($midMan[0]+".scaleZ") 1;
						$newL[size($newL)] = $midMan[0];
						parent -w $midMan[0];
						select $midMan[0] $j;
					//swap out influences


			if ($sknProc == 0)
				print "-----------------\n";

		select $newL;

Leave a Reply