Mel funkyness, any ideas anyone?

I’ve had to jump back to some old scripts to update them.
I’m seeing something really odd.
This has been working for about 8 months until now.

At the very start of the script. After sourcing a debugScript and a core Functions script.

I query the scene name and I break down the scene path into the components I need.
The path, the filename, the ext etc and a couple of other things.

I do this and have done this with and a combination of regex’s:

match
substring
tokenize

The script gets run and maya complains that theres and invalid call to “substring”, “match” has a syntax error and “tokenize” has the wrong number of values. Each of these has been used in different ways to provide the same result as an attempt to get around this behavioral bug.

The bizarre thing is that match expression and substring expression are being run in a call to an external procedure from the core Functions, some data is returned and then being run again with in the procedure that fails. The data that is returned is correct and would return a result if run through the methods being used in the procedure that fails, I’ve been dumping the values for sanity’s sake.
So its not like maya doesn’t know these internal mel functions exist or the data is bunk. It just refuses to accept the syntax is correct even though they function correctly when the script is rehashed or restarted or I extract those lines of code and run them separately in the SE with the dumped data.
All of these errors are spurious to something else but I can’t quite figure out what it is.
If I restart the script or rehash, it works no problems?

I’ve seen this before with substring and substitute but never with match and tokenize as well.
Its annoying I want to know why its failing without providing a crap hacky solution of rehashing in the script or starting it twice.

Any ideas what could cause this type of behavior?

It would be helpful if you posted the code in question. It’s easier to debug code than descriptions.

Crazy guesses would be: Your scene name query is returning a blank string, therefore everything else is wacky; or paths are not properly normalized, and they are throwing your regex’s assumptions off. In either case, print the value before you call your function and see if it is what you expect to be.

Also, dirname, basename, fileExtension, and others are better suited for the job. Python’s os.path is similarly well suited for path manipulations. If you are doing something reliant on path that is not easily expressed in these path manipulations, you may be doing something scary.

Its really odd, all values return properly. When executed separately and via a script ed work. When the script is called twice by pressing the script shelf button it works flawlessly.
However if I start fresh and run once it fails, no globals involved that might not be set.

I’ve rewritten in python to get around it and for ease. The code is too extensive to put a simple example as a simple example works every time it seems its the successive access to certain internal commands with reg-ex’s that fail. Oh well python saves the day as usual.
:slight_smile:

I would try to declare all your variables first. Then add a bunch of prints to make sure your data is correct (ie. print ("
$myFirstString = "+$myFirstString); That’s my shot in the dark if you add your code I could tell ya.

Definitely one of those stupid MEL quirks where it’s not doing something it should but it isn’t giving you any errors or any data to go off.

Usually what I’ll do in this case is put a debugging print statement every X number of lines and see how far it gets on that first run. When you find where it stopped, use that as your next stopping point and put more prints in that area, and keep going until you find the exact place where it’s going dead.

Only trouble is you have to restart Maya every time you test it, but such is the ways of debugging. =)

Sounds like you guys needed to write a mel debugger ;).
I wrote something that dumps the execution path as per below. either trace a whole script life or just trigger at certain values or chosen directions.
Its based on something I saw someone else do, really cool idea.
Makes life much easier… but in this case this is internal maya not the actual script that is failing, I know where it fails but not why Maya fails.

lightingDataUiVisability
    {
        currentWorkSpace
        {
        }
        getSceneRefList
        {
            in getLevelReferenceNodes
            {
            }
        }
        levelDialOutStates
        {
            lighting->
        }
        setLightingChunkVis
        {
            getLightingChunkReferences
            {
                $chunk --> 
                Contents of: $lightingChunks
                getSceneRefList
                {
                  error ($value is shite..)

Get that software if you didn’t already:
http://www.digimation.com/home/Software.aspx?sm=ms

It will make your life much easyer if you develop in Mel.