Freeze transforms on a parent but not it's children?


#1

Hey. Anybody know how to freeze the transforms on something without it wanting to freeze transforms on everything else under it’s hirearchy? I know teh script is “makeIdentity -apply true -t 1 -r 0 -s 0 -n 0;” but is there a way to specify that to a single object, rather than just a selection?


#2

Hi etc,

the following code should do the trick… :slight_smile:

proc freezeDaParentOnly()
{
		//The selected parent object...
 string $daObj[] = `ls -sl`;
 //the shape of the selected parent
 string $daS[] = `listRelatives -s`;
 //the children of the parent including the shape
 string $daC[] = `listRelatives -c`;
 //remove shapes form the child objects...
 string $daChilds[] = stringArrayRemove($daS, $daC);
 //unparent the children
 parent -w $daChilds;
 //freeze transform of the parent
 makeIdentity -apply true -t 1 -r 0 -s 0 $daObj;
 //reparent the children
 parent $daChilds $daObj;
}
freezeDaParentOnly;

regards

Alex


#3

nice, however… if the children have there translate attr locked it will move them… unless they were all 0 0 0…

.j


#4

Also, what if you don’t want the translate information of the parent node to be transfered to the child nodes… I am not even sure if this is possible without either creating another node in between orig parent and child…


#5

Hi John,

hadn’t thought of that… thanx for reminding me… :slight_smile:

so here is a new version with a unlock/relock function, and which also should work even if you select more than one parent object you want to freeze the transformation on, without effecting the children of it… :slight_smile:

global proc freezeDaParentsOnly( int $t, int $r, int $s )
{
	 //The selected parent object...
	 string $daObj[] = `ls -sl`;
	 for($obj in $daObj)
	 {
		//the shape of the selected parent
		string $daS[] = `listRelatives -s $obj`;
		//the children of the parent including the shape
		string $daC[] = `listRelatives -c $obj`;
		//remove shapes form the child objects...
		string $daChilds[] = stringArrayRemove($daS, $daC);
		//the attibutes to check if they are locked...
		string $attrs[] = { "tx", "ty", "tz", "rx", "ry", "rz", "sx", "sy", "sz" };
		//if any attributes were locked, they will be put into this string...
		string $lockAttr = "";
		//check if any of the attributes of the type translate, rotate or scale is locked...
		for($child in $daChilds)
		{
				for($attr in $attrs)
				{
						//if locked... unlock it...
						if (`getAttr -l ($child+"."+$attr)`)
						{ //unlock the attribute
						 setAttr -l 0 ($child+"."+$attr);
						 //and make a string to lock it again...
						 $lockAttr += ("setAttr -l 1 \""+$child+"."+$attr+"\";
");
						}
				}
		}
		//unparent the children
		parent -w $daChilds;
		//freeze transform of the parent
		makeIdentity -apply true -t $t -r $r -s $s $obj;
		//reparent the children
		parent $daChilds $obj;
		//lock the attributes which were locked before the operation... if any were locked...
		eval($lockAttr);
	 }
}

regards

Alex

edit: changed it into a global proc, and added some options to choose which freezetransformation options you want…

the command is now…


// number either 1 or 0...
freezeDaParentsOnly( number, number, number);
//as in
freezeDaParentsOnly( translate, rotate, scale);


#6

I couldn’t get it to run this time. Where does that update go? The first line?
I really don’t know enough about Procs.

Also, would this work if you had controls you wanted to freeze that were children of a control you also had selected? Or would you have to do them seperately?


#7

Hi ETC,

eh… you can e.g. create a text document… (e.g. with notepad)…

copy the code into this text document, and then save the document , and rename it “freezeDaParentsOnly.mel”… (instead of something.txt)

then you place this in your melscript folder, were you then can execute it via the command…

freezeDaParentsOnly( number, number, number);

the melscript folder could e.g. be like this… -->
c:\Documents and Settings\Alex\Documents\maya\5.0\scripts

if I get the time I will see if I e.g. can put it into a little gui with checkboxes and a button to execute the code… (and implement some of the things below)… :slight_smile:

Also, would this work if you had controls you wanted to freeze that were children of a control you also had selected? Or would you have to do them seperately?

eh… nope, then the script will give an error, unless the selected child under the parent also has children, and if the selected child isn’t locked… (e.g. as the script is at the moment)

however I think it kinda depends on what you wanna do… a little problem with this method is e.g. the child objects get new values when the unlock/relock happens…

the script can properly be modified to also freeze an child (without any children) under a selected parent… e.g. if you have other children that you don’t want affected by the freeze on the parent… otherwise I will just suggest you to use the normal freeze command on the parent if the children also should be affected by the freeze… :slight_smile:

regards

Alex


#8

Hi ETC,

here is an updated version, that now allows to also select children that has children, and even if these children are locked or their parents are locked it should work… it will also freeze selected objects which have locked their attributes… just got to give it a gui now… :slight_smile:

btw. also given it a new name, since it now not only works on selected parent objects… :slight_smile:

so the command is now.

freezeDaSelectedObjectsOnly( number, number, number );

here is the new script then… :slight_smile:


global proc freezeDaSelectedObjectsOnly( int $t, int $r, int $s )
{
  //The selected parent object...
  string $daObj[] = `ls -sl`;
  for($obj in $daObj)
  {
  //the shape of the selected parent
  string $daS[] = `listRelatives -s $obj`;
  //the children of the parent including the shape
  string $daC[] = `listRelatives -c $obj`;
  //remove shapes form the child objects...
  string $daChilds[] = stringArrayRemove($daS, $daC);
  //the attibutes to check if they are locked...
  string $attrs[] = { "tx", "ty", "tz", "rx", "ry", "rz", "sx", "sy", "sz" };
  //if any attributes were locked, they will be put into this string...
  string $lockAttr = "";
				//if the selected object has children...
				if(`size($daChilds)`>0)
				{
						//check if any of the attributes of the type translate, rotate or scale is locked...
		  for($child in $daChilds)
		  {
				  for($attr in $attrs)
		   {
				   //if locked... unlock it...
			if (`getAttr -l ($child+"."+$attr)`)
			{ //unlock the attribute
			  setAttr -l 0 ($child+"."+$attr);
			  //and make a string to lock it again...
			  $lockAttr += ("setAttr -l 1 \""+$child+"."+$attr+"\";
");
			}
			//if the parent object is locked...
						  if (`getAttr -l ($obj+"."+$attr)`)
						  {
							setAttr -l 0 ($obj+"."+$attr);
							$lockAttr += ("setAttr -l 1 \""+$obj+"."+$attr+"\";
");
										}
		   }
		  }
		  //unparent the children
		  parent -w $daChilds;
		  //freeze transform of the parent
		  makeIdentity -apply true -t $t -r $r -s $s $obj;
		  //reparent the children
		  parent $daChilds $daObj[$i];
		  //lock the attributes which were locked before the operation... if any were locked...
		  eval($lockAttr);
				}
				//if the selected object has no children...
				else if(`size($daChilds)`==0)
				{
			  for($attr in $attrs)
			  {
		  //if locked... unlock it...
		  if (`getAttr -l ($obj+"."+$attr)`)
		  { //unlock the attribute
			setAttr -l 0 ($obj+"."+$attr);
			//and make a string to lock it again...
			$lockAttr += ("setAttr -l 1 \""+$obj+"."+$attr+"\";
");
						}
	   }
					 //freeze the object...
					 makeIdentity -apply true -t $t -r $r -s $s $obj;
					 //lock the attributes which were locked before the operation... if any were locked...
					 eval($lockAttr);
				}
  }
}

regards

Alex


#9

Hi again,

a little update after some sleep and some coffee… :slight_smile:

I have made a little gui to the script… so now the command is…

freezeDaSelectedObjectsOnlyUI;

you can just drag this command e.g. to a shelf, or assign it to a hotkey if you want… :slight_smile:

I have attached the melfile in the zipfile… just place the melfile in your scriptfolder, and then execute the command to get the gui…

btw. if you have a proc or used the previous code for the “freezeDaSelectedObjectsOnly”… from the post above… please remove or delete it from the scriptfolder, otherwise you may not get it to work, since the gui use a modified version of it… :slight_smile:

hope you can use it… :slight_smile:

regards

Alex


#10

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.