I am not sure which subject to post this under because I don’t know if it is going to be a Mel answer or what! I have never used Mel and I think it might be the only way.
I have a scene of a workshop and I have a woodwork vice which the moving parts are made up of two groups, the first group are the parts that move in or out i.e. the front jaw and the two guide bars and the second group is the parts that rotate, i.e. the leading screw, the tommy bar and the bit the tommy bar goes through.
The rotating group I have added to attributes one to control rotate X and one to translate X. I have used the connection editor to join these together and to connect them to the normal rotate X and translate X. The reason I made new attributes and not used the built in ones is I wanted to set minimum and maximum values so the vice can’t go passed closed or open to far.
Then on the non rotating group, I have made a new attribute to control the translate X (again so I can set min and max values).
Then again in the connection editor I have set my new rotate X on the rotating group up to drive the new translate X on the non rotating group.
This starts to work, when I highlight the new rotate X on the rotating group and middle drag as it rotates the vice opens.
The problem is about a quarter turn of the new rotate X and the vice is fully open. What I need to achieve is for every full rotation of the handle the jaw opens about ten units, that would be moves ten units in translate X, and I have not a got a clue how to achieve this.
I know there is an easy manual way of doing it, at frame 1 set a key frame for all the bits that need to move and then so many frames later rotate X one full tern and move the translate X 10 units then set another key frame and so on but I would like to get this to work if I can. Any ideas?
If I understand correctly then the default behaviour of connecting the rotation with the translation gives far too much of a movement.
If so then the code way to do this would be to start without any connections between the objects and create an expression that is evalutated each frame and results in the rotation. You could then key the rotation in the desired frames.
To do this all you need to do is create an expression that gets the rotation of object 1, dilutes it to a much smaller amount and then apply it to the translation of object two.
Open up the expression editor and create a new expression using the following code:
Line one gets the x axis rotation of the named object
Line two sets the x translation of the named object to be the rotation divided by 10 (which simply dilutes the amount).
To use in your project simply change the names and the division to get the required effect. I would expect if it was a vice then the division would be far higher to give the impression that multiple rotations are needed to move the vice parts a small way.
I've also attached a sample movie showing it working so if need be you can take it apart or modify to suit. I think that if you have an earlier version of maya you will need to open it in notepad and change the version references to yours, e.g, changing 2008 to 7.0 or similar)
Simon
p.s, I split the code up so that it was easier to see but if you wanted a single concise line then the following does the job exactly the same: