Hello guys, I've been trying to wrote a script about scaling an object to specified target length, it's based of a "Scale To" script by Walid Abou Ali over at Scriptspot. Wanted to improve it to support multiple selected objects.
Here is the snippet of what I have right now;
(
target = 10
xlength = selection.max.x - selection.min.x
ylength = selection.max.y - selection.min.y
zlength = selection.max.z - selection.min.z
ratio = target/xlength
xPos = selection.center.x*ratio
yPos = selection.center.y*ratio
zPos = selection.min.z*ratio
for obj in selection do
(
obj.transform = obj.transform * (matrix3 [ratio,0,0] [0,ratio,0] [0,0,ratio] [xPos, yPos, zPos])
)
)
.. so what I have currently works fine with a single selected object, but I'm having a headache with the matrix3 row4 of the object transformation to set the center of the scaling translation.
My question is why wont it use the center of selection for the translation even though I put selection.center.x there? It did however scale to the correct size as specified on the "target", but the center of scaling seems like on a random position (well..I'm sure it wasn't a random number, but I just couldn't make up where is the number coming from).
Replies
By right it shouldn't be moved since the scale is the same and the selection center is also the same (because it's only 1 object in selection). The same thing happen when I select 2 box, it jumps to some other location when I run the script.
The reason the box moves from 10 to 20 is because you are multiplying the center position by it's current position.
The first solution off the top of my head is to just scale the object and handle the position afterward.
On a side note, I never realized the selection center gizmo in Max is weighted by object locations. But selection.center is the actual center you expect.
Still not fully understand the math solution you have on the fn, will look into it more next time, but for now it's all works as expected!
Well thought I just posted here the complete version of the script that I have for now, probably anyone will benefit from it as well, or might even add some idea or improvements; ..the Group Scale checkbox is whether or not to scale the objects in selection individually (and scale each of them to the target scale) or group of selected objects (for example modeling an object with many small individual pieces that suppose to fit one another, so instead of scaling each of them to the target scale, this checkbox use the selection's dimension and scale all at the same time).
Note: but please be careful with parented object, it'll do some weird stuff regarding parent/ child relation..the child object got scaled 2 times I believe (scale for its own and scale for its parent).
To fix children scaling twice just skip any object that has a parent.
Hmm..about the parented object, it seems like when I added those line, it will messed up the calculation.
Just to be sure, its used on this portion?
(BTW, a cool feature would be to resize as you adjust the spinner.)
Yeah, you're right monster. The only problem is when I checked both the group scale and reset xform then it'll do some funny stuff, without reset xform it's working correctly.
Hmm..about monster suggestion for an interactive spinner?..I'll see what I can do
Hey monster, please take a look here. I've added the "Interactive mode" like what you suggested. You need to press Apply button in order for it to be available. Not too sure about this behavior, which one do you think better? the interavtive button always available for user to press or like how the currect behavior is?
.. it seems like there is still part of the code that can be trimmed down a little. But so far it dose things that I wanted it to do