[Closed] Object position script error
hello,
I’m trying to make a script to reset the position of the selected object to zero, I also want to include the options to reset the x, y, or the z axis of the object, but I always come with an error…can someone tell me what am I doing wrong with this and if there’s a better way to do it?
thanx in advance.
rollout objpos "Utilities"
(
radiobuttons zero_type labels:#("X","Y","Z","all") default:4 --setting up radio group
button zeroout "Origin" --making the reset button
type = zero_type.state -- collecting the radio group selection
on zeroout pressed do
(
if type == 1 do
(
$.pos.x = 0
)
else
{
if type == 2 do
$.pos.y = 0
)
else
(
if type == 3 do
$.pos.z = 0
)
else
{
if type == 4 do
$.pos = [0,0,0]
)
)
)
createdialog objpos
Is there a reason you are setting your zero_type.state to a variable? The following works fine for me:
rollout objpos "Utilities"
(
radiobuttons zero_type labels:#("X","Y","Z","all") default:4 --setting up radio group
button zeroout "Origin"
on zeroout pressed do
(
if zero_type.state == 1 then
(
$.pos.x = 0
)
if zero_type.state == 2 then
(
$.pos.y = 0
)
if zero_type.state == 3 then
(
$.pos.z = 0
)
if zero_type.state == 4 then
(
$.pos = [0,0,0]
)
)
)
createdialog objpos
Also, be careful, I noticed you had a couple “{” characters instead of standard “()” parenthesis. Let me know if this helps.
–Jon
Thank you for your help, It works fine now, thanks to you
it was the “{”…where did that come from?
but after I fixed those, I still get some errors, and I still dont know the reason.
I set the radiobutton state to a variable after I got the errors, I thought maybe this will help.
next step is to make the same thing to sub-objects, wish me luck and thanks for your help.
The code jonlauf posted seems to work as expected.
A possible optimization would be of course
rollout objpos "Utilities"
(
radiobuttons zero_type labels:#("X","Y","Z","all") default:4
button zeroout "Origin"
on zeroout pressed do
(
case zero_type.state of
(
1: $.pos.x = 0
2: $.pos.y = 0
3: $.pos.z = 0
4: $.pos = [0,0,0]
)
)
)
createdialog objpos
On the other hand, this script is not even needed as you can get the same effect using the Transform Type-In Dialog… just right-click the world position spinners’ arrows and the selected objects will go to the origin.
Thanx for the optimization Bobo, your “Maxscript for the Masses” was great…it’s what inspired me to start scripting in the first place
well…I’m starting the script…max has this annoying feature wich if you have a couple of vertices selected and they don’t have the same X value for instance…if you right click on the transform type-in spinner…it doesn’t put them all at zero…instead it avarege the distance accordingly…I don’t know if this made sense, but I think you know what I’m talking about.
as I said…eventually I will make this script, hopefully with cgtalk guys help, I will make the script does that exactly…making the vertices jump to zero when pressing the button.