[Closed] Group Objects, Scale and transform
Hello all,
I have here a script that works fine when I let it run alone, but when I am doing it in a button then it scale wrong.
select objects
group selection name:"tempGroup"
clearselection()
select $tempGroup
sel_z = ($tempGroup.max.z - $tempGroup.min.z)
scaleFactor = 1/(1/(random 50.00 50.00) * sel_z)
scale $tempGroup [scaleFactor,scaleFactor,scaleFactor]
move_z = ($tempGroup.max.z - $tempGroup.min.z)/2
$tempGroup.pos = [0,0,move_z]
ungroup $tempGroup
In a button the value from sel_z = ($tempGroup.max.z – $tempGroup.min.z) is way to small. When I split the script in to buttons, with the first button I create the group and with the second I scale the group it works when I click with the mouse after the first button on the object and then push the second button.
You have any Idea what I can do?
Thanks for helping!
jb_
You don’t actually need the group here (and besides, getting the node by a name that’s hardcoded is always a bad idea), this is basically the same:
(
sel_z = selection.max.z - selection.min.z
scaleFactor = 50 / sel_z
about (selection.center) scale selection [scaleFactor, scaleFactor, scaleFactor]
move_z = (selection.max.z - selection.min.z)/2
move selection [-selection.center.x, -selection.center.y, move_z]
)
Similar idea for mirror operation
-- ARGUMENT OPTIONS
-- axis enums: {#x|#y|#z}. Default X-Axis
-- center (miiror about point3) also you can use any object center. Default: world center
-- clone enums: {#copy|#instance|#reference}. Default instance
fn mirrorSelection axis:#x center:[0,0,0] clone:#instance = if selection.count != 0 do
(
local ax = case axis of (
(#x): [-1,1,1]
(#y): [1,-1,1]
(#z): [1,1,-1]
)
local parentslist = #()
maxOps.CloneNodes (selection as array) offset:[0,0,0] cloneType:clone newNodes:&clones
for i in clones do (append parentslist i.parent ; i.parent = undefined)
about center scale clones ax
for i = 1 to clones.count do clones[i].parent = parentslist[i]
free parentslist
)
mirrorSelection()
Hello Swordslayer,
your example look much easier, thanks for that. I was fixing the problem a bit different, but your code I will save for the future.
I was also thinking that is not so good to select objects by name, but I don’t found out how to change that.
And thanks gazybara to, is also a good example what I will save in my code snippet folder.