Notifications
Clear all

[Closed] Aligning objects on push of a Button

Hi everyone, I’m new to maxscript and here’s what i’d like to do.

Setting:

  • two Point Helpers (PT_01 and PT_02)
  • one Shape (Shape)
  • one Bone (Bone)

PT_01, PT_02 and Shape are linked to Bone.
One the press of a button i’d like to ALIGN in position Shape to either PT_01 or PT_02. So Shape switches position on the press of a button.

I’ve done this before by using two buttons. I’d like to simplify my UI by just having one button this time.
My Bone will be animated. So the Transform of my Point Helpers is always changing.

I hope this is clear enough. I’ve tried different things so far, but it’s not working like i’d like to.

If someone could give me a hint it would be really appreciated. Thanks a lot.

9 Replies

Something like a simple caption on the buttons like PT_01 then if caption is PT_01 change caption to PT_02 and set 02 position and an else if for the other way around.
Or otherwise a simple variable on/off(bool) or whatever?


   global PT
   on btn pressed do
   (
     if PT == true then
     (
   	.... = PT_02.pos
   	PT = false
     )
     else
     (
   	.... = PT_01.pos
   	PT = true
      )
   )

Something like this out the back of my head…
Or even a bit more like using index to cycle through based on the amount of $PT_*’s in your scene…

Hi guys,
you can check the current spline position with points position, since Shape and Points are all linked to the bone.


 on btAlignButton pressed do
 (
 	if (oShape.position == PT_01.position) then
 	(
 		oShape.position = PT_02.position
 	)
 	else
 	(
 		oShape.position = PT_01.position
 	)
 )
 

Cheers

Hi guys thanks for your response,

Here is what i tried after reading your posts. I already tried it before. It works the first time i press the button, my Shape actually changes position but the second time i push it, nothing happens. It’s like the “if then else” statement doesn’t fully work. Thanks a lot guys.

Shape : s_eyelids_controls
PT_01 : h_eyelids_ancre_bones
PT_02 : h_eyelids_ancre_mesh
on switch_meshTorig pressed do

(

          if ($s_eyelids_controls.position == $h_eyes_eyelids_ancre_bones.position) 
         then ($s_eyelids_controls = $h_eyes_eyelids_ancre_mesh) 
         else ($s_eyelids_controls.position = $h_eyes_eyelids_ancre_bones.position)

)

1 Reply
(@decapitator)
Joined: 11 months ago

Posts: 0

The then expression doesnt change position…?

The then expression doesnt change position…?

If == h_eyelids_ancre_bones (PT_01)
then = h_eyelids_ancre_mesh (PT_02)
else = h_eyelids_ancre_bones (PT_01)

Right now those are the positions that i’m trying to pass to my s_eyelids_controls (Shape).

Thanks for replying

I think what decapitator means is you’re not defining a position in your then statement:


   on switch_meshTorig pressed do
 
 (
 
 	if ($s_eyelids_controls.position == $h_eyes_eyelids_ancre_bones.position) then
 	(
 		$s_eyelids_controls.position = $h_eyes_eyelids_ancre_mesh.position
 	)
 	else
 	(
 		 $s_eyelids_controls.position = $h_eyes_eyelids_ancre_bones.position
 	)
 
 )
   
   

Exactly and if you only define one position, it would only go to one position so you cant toggle it like you asked on how the button would do.

Well that was dumb lol

Thanks a lot guys for opening my eyes. This is a small part of a bigger script. Clearly i was looking at it with my eyes shut.

Really appreciate your time. Have a good day!

[color=white]Hey guys! So i looked at my script again and added the .position to all of my states. It works the first time i push the button my shape moves to the other position, but when i push it again it doesn’t go back to the first position. Here is what i have. If you guys can help me it would be appreciated. Thanks again

if
(
$s_eyelids_controls.position == $h_eyelids_ancre_bones.position
)
then
(
$s_eyelids_controls.position = $h_eyelids_ancre_mesh.position
)
else
(
$s_eyelids_controls.position = $h_eyelids_ancre_bones.position
)
[/color]