View Full Version : mel script to create runtime expression with variables

02 February 2008, 03:04 PM

I have a general question about a problem I am having with a script I am writing.

I am storing user selections etc. inside a variable which I then want to use in a runtime expression to link two attributes and keep them in a specific relationship.

I am having problems accessing the script-variables inside my expression, I get all sorts of error messages.

This is a rough example of the expression I am intending to create (if that is in case the best way to do it), with the variables having been created in the MEL script before the expression creation.

obj01.translateX = $obj_matrix[0];
obj01.translateY = $obj_matrix[1];
obj01.translateZ = $obj_matrix[2];

Any advice is appreciated

02 February 2008, 06:10 PM
Sadly you might need to use Global variables. Sometimes you can just make a Global Array and store stuff in that array so that you can have persistent data with just one or two Global Objects. Other then that you can make EnvVariable, or put data in Attr on some element in your scene, which can be dangerous if someone deletes it.

Last of all, if you need complex data structures you have C++ and the API.

I'm not sure about Perl though...


02 February 2008, 05:01 PM
Okay, but using a global variable would not warrant for the expression to work once the scene has been saved and reloaded, as the user would not execute the creation MEL script unless he wanted to change the variable.

I am sure I am missing something here, this cant be that hard, I just want to link to attributes permanently, say you select one objects vtx and want another object to follow that vtx points world space position constantly?

02 February 2008, 07:47 PM
wellllll, to withstand a closing and reopening of the file, you'd need to write the selection to the file. I was thinking originally that the selection wouldn't be big, so you could use enum attributes on objects and pull selections from there, but that wouldn't work too well. You have a bunch of verts selected and you want to remember that between sessions, you're going to need to write a node to the file itself to hold all of the selections.

How ever you could look into the command "sets". It makes a node of just what was selected in the outliner, and I'm like 90% sure it stays between runs of maya. I don't use sets, I don't like having all of that information written to my files, but it would do what you want I believe.

You could also have the script write an expression to add all of the selection to a global when the first frame is came to. That way the expression will run every time you go to the first time, making sure the stuff selected is remembered, but that is such a messed up way of doing it.

I'd say look into sets. (I'm just now starting to learn how to write nodes to have my own history for things, but I haven't exactly looked into it much yet. If I find anything that will help I'll post it up.) Good luck

CGTalk Moderation
02 February 2008, 07:47 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.