Program a boolean attribute to set an object to a specified position

Program a boolean attribute to set an object to a specified position

Anonymous
Not applicable
1,563 Views
3 Replies
Message 1 of 4

Program a boolean attribute to set an object to a specified position

Anonymous
Not applicable

Hi, first time on the forums.

 

I'm in a 3D animation course at college and I'm currently working on a rigging assignment. I want the pivots of certain control objects to be oriented a specific way, just to make rotating the parented objects a bit easier. However realized rather quickly that freezing the controls resets the orientation of the pivot, and conversely baking the pivot back to the desired orientation returns the transform values of the object back to its relative position in the scene (not sure if that really makes sense, but I don't know how else to word it).

I've already attempted a tactic I found elsewhere where you put the desired control within a group, but I couldn't quite get it to work. So I came up with an idea to use a boolean attribute to toggle the controls back into place. I did manage to program an expression that will translate and rotate the object to the position I want it at. However, I can't figure out how to get the attributes to accept user input again after the boolean is toggled off, as it just remains locked into place otherwise.

 

I have asked my instructor about it, but he seemed to imply it was very difficult to do and I was and told me to not to worry about it. I'm curious, though. Exactly what would I have to do in order to get this to work?

 

Here's the code that I'm trying to use to do this:

lrejc91572AZ6_1-1587839431754.png

I'm currently using the 2019 student version of Maya.

 

Any help is appreciated. Thanks!

0 Likes
1,564 Views
3 Replies
Replies (3)
Message 2 of 4

jmreinhart
Advisor
Advisor

It's a bit hard to understand what the end result you are aiming for is, but it sounds like you could just create a buffer group above the control and change the rotations on that group to orient the control.

0 Likes
Message 3 of 4

Anonymous
Not applicable

I've seen that solution before and I have tried it, but I couldn't get it to work the way I wanted. But then again, I might have been utilizing it wrong. The explanations I found weren't that specific, so I might just be missing something entirely.

 

As for what exactly I'm trying to achieve, well... I'm not entirely sure how else to describe that. Setting the attributes to a specific value seems to lock them to that value even when my boolean attribute is set to "off". So I'm assuming that the the expression is continuing to execute that particular part of the expression because there's nothing in the else else statement that will tell it to do otherwise. So I'm wondering if there's a specific expression I could be using in the else statement that will allow the attributes to except user input once again.

Though thinking on it now, the values might have also just been converted to const variables, in which case I would need to figure out a way to return the values back to modifiable floats. Either way, however, I'm not all that familiar with MEL and how it compares to C++ (which I'm more familiar with).

Really, anything to help me further understand the scripting language in general would be extremely helpful.

0 Likes
Message 4 of 4

jmreinhart
Advisor
Advisor

So if in your expression you have something like:

if (switch.boolean == true){
object.tx = 10;
}

Then maya will create a connection from  the expression node to the objects translateX attribute. If the switch is turned off that connection will still exist. You can't set animation keys on an attribute that has inputs. Well technically there are animBlend nodes that work in some situations but are complicated and hard to maintain when animating, so I would not suggest using them.

0 Likes