Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   Link rotating X and Translate X (https://simplymaya.com/forum/showthread.php?t=28603)

trikeman 30-12-2007 11:19 PM

Link rotating X and Translate X
 
Hi

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?

Thanks
Trikeman

t1ck135 31-12-2007 01:05 PM

1 Attachment(s)
Hi Trikeman,

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:
Code:

$pObjValue = `getAttr "pCylinder1.rotateX"`;
setAttr pCube1.translateX ($pObjValue / 10);

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:
Code:

setAttr pCube1.translateX (`getAttr "pCylinder1.rotateX"` / 10);

trikeman 31-12-2007 01:10 PM

Hi

Thank you Simon, will get on and give that a try.

Thanks
Trikeman

gster123 31-12-2007 01:36 PM

Could you just not set up a SDK?

That way you have control over how much movement you have, you could also pre and post infinity the curves

t1ck135 31-12-2007 02:40 PM

I've never done one so dont know steve ;)
will have a look into it though as it sounds good

Simon


All times are GMT. The time now is 09:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018