adjust the size of an object to another one


Hi !
Here is my problem.

I need to replace all the windows of a city by new ones.
So I wrote a simple script that duplicates my new window and position and rotate it at each old window. I used the xform command to get the translate and rotate values.
The problem is I also need the new window to be the same size (width and lenght, I don’t need depth) as the old ones which are all of different size. Furthermore all old windows’ scale attributes are not the same, some are 1 and others are 1.2 … etc…

Well that’s not an easy thing to do for me as I’m just a beginner in Mel.
Thanks in advance for your help !


I would advise you to work on a boundingbox size based methon instead of getting the scale. I do not know if the following lines could get the boundingbox size of a group of objects… But let’s try :wink:

float $surfaceMinX = `getAttr ($surface+".boundingBoxMinX")`;
float $surfaceMaxX = `getAttr ($surface+".boundingBoxMaxX")`;
float $surfaceMinY = `getAttr ($surface+".boundingBoxMinY")`;
float $surfaceMaxY = `getAttr ($surface+".boundingBoxMaxY")`;
float $surfaceMinZ = `getAttr ($surface+".boundingBoxMinZ")`;
float $surfaceMaxZ = `getAttr ($surface+".boundingBoxMaxZ")`;

And as you know max-min returns the length :thumbsup:


Thanks french mate !

Actually I tried to use the exactWorldBoundingBox command to store the min/max values in a float array, then assign (setAttr) the max-min result (lenght) to the scale of my new window.
This new window is a square plane originally scaled to 1 1 1, and has a lenght of 1. So I thought if I gave its scale the value of the other object’s boundingbox, it’s own boundingbox would be the same… but it doesn’t work, I’m not very good in maths !
Any idea ?


So I thought if I gave its scale the value of the other object’s boundingbox, it’s own boundingbox would be the same…

So yeah you’re true! Working on bounding boxes sizes is a good deal but their must be something we are not thinking about which makes your script not working.

I assume you know that on moving vertices (or other component types obviously), the scale (.sx .sy .sz attributes) is not udpated). That’s why I suggested you to work on boundings, it prevents from “non-real scale” problem.

So what’s the problem? Scripting error? Method error? Couldn’t help you with the infos I have, keep trying :thumbsup:


Hi seb4d,

here is a little script which should help with the problem… :slight_smile:

first select the object you want to be matched, second select the object that should match the first selected object… and then execute the script… :slight_smile:

proc matchDaSize()
	 //the selected objects
	 string $daObj[]= `ls -sl`;
	 //first selected object which the second selected object should match...
	 float $obj1X = (`getAttr ($daObj[0]+".boundingBoxMaxX")`-(`getAttr ($daObj[0]+".boundingBoxMinX")`));
	 float $obj1Y = (`getAttr ($daObj[0]+".boundingBoxMaxY")`-(`getAttr ($daObj[0]+".boundingBoxMinY")`));
	 float $obj1Z = (`getAttr ($daObj[0]+".boundingBoxMaxZ")`-(`getAttr ($daObj[0]+".boundingBoxMinZ")`));
	 //second selected object which should match object above...
	 float $obj2X = (`getAttr ($daObj[1]+".boundingBoxMaxX")`-(`getAttr ($daObj[1]+".boundingBoxMinX")`));
	 float $obj2Y = (`getAttr ($daObj[1]+".boundingBoxMaxY")`-(`getAttr ($daObj[1]+".boundingBoxMinY")`));
	 float $obj2Z = (`getAttr ($daObj[1]+".boundingBoxMaxZ")`-(`getAttr ($daObj[1]+".boundingBoxMinZ")`));
	 //what the difference between the two objects...
	 float $diffX = $obj1X/$obj2X;
	 float $diffY = $obj1Y/$obj2Y;
	 float $diffZ = $obj1Z/$obj2Z;
	 //do the match operation...
	 setAttr ($daObj[1]+".sx") (`getAttr ($daObj[1]+".sx")`*$diffX);
	 setAttr ($daObj[1]+".sy") (`getAttr ($daObj[1]+".sy")`*$diffY);
	 setAttr ($daObj[1]+".sz") (`getAttr ($daObj[1]+".sz")`*$diffZ);
	 //freese the scale
	 makeIdentity -apply true -t 0 -r 0 -s 1 $daObj[1];
	 //clear the selection...
	 select -cl;





here is a little update, made a little gui for it… :slight_smile:

now you can choose if it should match in X, Y or Z…
you can also select more than one object, all the selected objects, will match the first selected object depending on what is chosen… :slight_smile:

just put the melfile form the zippie in the script folder, and call it with this command… -->





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.