View Full Version : delete callback in mel script?

03 March 2009, 11:26 PM
Hey, I'm making a UI tool that saves various types of selections in layers (vertices, faces, edges, etc). Anyway, I store the selections in an array. Now my UI works great until the user deletes something in the scene that was saved in one of my selection layers. I really don't want to have to check every single item in my selection list every time a user wants to turn on a selection layer.

Is there a delete callback in mel that will tell me what has been deleted? Or if something has been deleted? I've searched on google and haven't found anything so far, I figured someone here might know off the top of their head.


03 March 2009, 07:02 AM
what do you mean by a 'selection layer'? As far as I know there is not a way to do this, i would suggest that you use a custom 'layer on' that loops through the objects in the list before attempting to turn them on, at that point, you could prompt the user, fail, remove the items that longer exist, or some combination of the three depending on the seriousness of the error or what behavior you are looking for

03 March 2009, 08:08 AM
What a bout using sets?
I hassled as well with selections saved in command string in various ways. But its not worth it. Sets are designed for stuff like that. They delete themselfes if there empty, if all members are deleted. So you'd only have to check if the set exists before you select it.

03 March 2009, 11:41 PM
I'd never heard of sets before - that's a great idea. After thinking about it a while, I just made a function that will clean the array of any objects that no longer exist. I didn't want this to slow the user down, so they can push a button to make this happen. However, sets sound way better. I found the documentation on sets, so I'll have to play around with it. Seems pretty straight forward.


As far as what I meant by selection layer - I'm not using the actual layers in maya (since I don't know how to do that). It was really easy to make something that looks like a layer in my UI. I was kind of disappointed when I found out there aren't any multidimensional arrays. My plan was to hold the various layers(which are each an array) in an array. So I had to hard code each of my layers - a real pain.

03 March 2009, 11:55 PM
I was kind of disappointed when I found out there aren't any multidimensional arrays. My plan was to hold the various layers(which are each an array) in an array. So I had to hard code each of my layers - a real pain.In python there are!!!

03 March 2009, 12:35 AM
sets can also have sets as their members if I'm no mistaken-

03 March 2009, 05:13 AM
This might be a silly question, but... Can you use python and mel script in the same script? or together through seperate scripts? I noticed the python tab in the script editor, but I've never used it. Since python is more extensive than mel script(from what I understand) - is there a reason for me to learn both mel script and python? or is it better for me to learn python? I've done programming in other languages so I could pick up python too if it was worth while.

03 March 2009, 04:45 PM
You can run mel from python and vice versa. I sometimes use single line python calls to take advantage of python's vastly superior string and array handling. For example:

string $nameOfThing = "L_left_arm_front";
// replace the L_ with R
string $newName = python("'" + $nameOfThing + "'.replace(L_,R_");

For clarity's sake I would say you should stick natively with one language rather than trying to maintain two separate scripts unless your python task is very focused and is just handing info back to your mel script (say, reading in an xml file).

As for which one to start with if you're comfortable already with programming concepts and you forsee having to need multi-dimensional arrays, or the need to access any data outside of maya and import it that python may be a better starting point.

I will say I still do simple tasks with MEL since it's just plain faster and easier if you don't need anything fancy. As well you will be able to get help much more easily as there are still way more people that use maya and know mel than those who know python or both.

There is a great add-on module for python called pyMel which is available free that makes running maya commands in python much more intuitive-

CGTalk Moderation
03 March 2009, 04:45 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.