View Full Version : How to create interactive tools using mel?

10-04-2011, 11:22 AM
Dear all,

I have problem figuring out a way to create interactive tools in Maya similar to tools like create distance tool or particle tool , where users have the ability to place his point or locator's interactively.


10-04-2011, 03:31 PM
The best you can do with MEL is use the draggerContext command. This is pretty basic compared to the built-in interactive tools and what you could achieve using the API though. What exactly would you like to do interactively?


10-04-2011, 05:01 PM
Thank you, your answer helped me solve my problem.

for now i only want to extend the distance tool where i let users get the distance between multiple points instead of two.

And i want that to happens interactively.

10-06-2011, 04:02 PM
I personnaly never have found a way to use the dragger context to get a point in space, let say snap on the closest location on the closest point of the object from your mouse pointer, can only retreive the point on 2 axes, did you manage to do that?
nathan you seem to have explore this a lot, any advice to do such thing?
Without that I find the tool very limited..:/ but it's probably a skill problem ( understand my skill of course).


10-06-2011, 05:33 PM
I am not sure if i get you point well, But All Maya tools work that way, where you only retrieve two axis.

But what you can do is query the camera that users are looking through and when ever user look through orthographic camera you can change the flag on the command to accommodate the axis for that orthographic plane.

I hope this will help!

10-06-2011, 10:19 PM
Hey Matt, yeah, I have done quite a lot of stuff with draggerContext and I really like it. You can "fake" quite a lot of cool tools with it. I say "fake" as I'm sure that what I'm doing is fashioning a working tool using basic MEL/py and some clever tricks, rather than (what I can only assume is) properly using the API to make "real" contexts. But I think the key to making useful tools with the draggerContext is ray intersection.

The draggerContext can return coordinates using several different projections, and it's not limited to returning one type per click. If you generate a click point, you can edit the draggerContext and query different projection co-ordinates from the same point. What this allows you to do (and again, I have no idea if this is just a clumsy but clever hack, or the only way to do such a thing) is to query the same point from two different projections. This then gives you a vector into the screen which you can ray Intersect to find out an exact world-space 3D coordinate that hits any given mesh or object.

Getting a ray intersection can be done using pure maths, the rayIntersect plug-in, or by using the MFnMesh.closestIntersection method in the API, all of which have previously been discussed in this forum so I don't need to try to reiterate them here.

If I get a chance I'll try to knock up a short example.

CGTalk Moderation
10-06-2011, 10:19 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.