Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Running mel in python reported an error

Running mel in python reported an error

2368457978
Enthusiast Enthusiast
742 Views
7 Replies
Message 1 of 8

Running mel in python reported an error

2368457978
Enthusiast
Enthusiast

Hello everyone! I use python to run mel code (-removeDuplicates <distance >). I want to modify the distance and execute it in the code by entering text, but why does the current runtime script report an error? (error during execution of MEL script)

 

def del_OBJ():
    OBJ = cmds.textField("parameter", q=True, text=True)
    for i in OBJ:                       
        mel_cmd = ('-removeDuplicates', i)
        path = mel.eval(mel_cmd)
        return path
##-removeDuplicates <distance>                
                                
cmds.textField("parameter", editable=True,h=30, w=50)
cmds.button("Delete duplicate objects", w=130,h=30, c="del_OBJ()")

 

  

0 Likes
Accepted solutions (1)
743 Views
7 Replies
Replies (7)
Message 2 of 8

Kahylan
Advisor
Advisor

Hi!

 

Well, there are multiple reasons why your script isn't working:

1) Mel has no procedure called "removeDuplicates"

2) A dash "-" indicates to mel that this is a flag inside a command, not a command by itself. Since your command starts with a dash, it doesn't know what command you are trying to call.

3) When using mel eval, the whole thing needs to be a single string. The following Line should look like this:

#How it looks like now
mel_cmd = ('-removeDuplicates', i)
path = mel.eval(mel_cmd)

#How it should look like if there was a procedure removeDuplicates with a flag called distance
mel_cmd = ('removeDuplicates -distance' + i)
path = mel.eval(mel_cmd)

 

What exactly are you trying to do? Maybe I can help you find the right procedure...

 

 

0 Likes
Message 3 of 8

2368457978
Enthusiast
Enthusiast
-removeduplications < distance > is a mel command, for example (-removeduplications 0.1), and < distance > is a numerical value. I want to execute this command through python now, and use text to control < distance >.
0 Likes
Message 4 of 8

Kahylan
Advisor
Advisor

I can't find this MEL command in any of the docs, and if I try to run it in a MEL Tab I get the error:

// Error: line 1: Cannot find procedure "removeduplicates". //

So this command you are trying to run, is not a standard mel command.

 

Is it from a custom Plugin? If that is the case, could you link me to where you found it?

0 Likes
Message 5 of 8

2368457978
Enthusiast
Enthusiast
Yes, this is a custom plug-in command, and the command is removeduplications < distance >. I usually run it directly in mel, such as removeduplications 0.1.
0 Likes
Message 6 of 8

Kahylan
Advisor
Advisor

Ah ok, to access commands in a custom plugin you need to source it first.

 

Here is a tutorial on how to do that:

https://subscription.packtpub.com/book/business/9781785283987/1/ch01lvl1sec17/calling-a-mel-script-w...

 

I hope it helps!

0 Likes
Message 7 of 8

2368457978
Enthusiast
Enthusiast
def del_du_Groom():
    mel_cmd =' -removeDuplicates 0.1'
    # -removeDuplicates 0.1  0.2  0.3  0.4  0.5                        
    path = mel.eval(mel_cmd)
    return path

Hi. I read this document carefully and found that he just calls mel, and does not explain how to modify mel in python, I can directly call this mel command, I now want to know how to modify <distance> in python, distance is a floating point number, this command It means to delete the duplicate objects within the distance. At present, I can only execute this command fixedly. I want to change the distance to a method that can be modified by the input field, instead of directly entering a value in the calling command.

0 Likes
Message 8 of 8

Kahylan
Advisor
Advisor
Accepted solution

You still aren't sourcing your MEL file, so if you haven't used the mel command in your session before running the script python probably wont find it.

 

but if you this works for you:

 

def del_du_Groom():
    mel_cmd =' -removeDuplicates 0.1'
    # -removeDuplicates 0.1  0.2  0.3  0.4  0.5                        
    path = mel.eval(mel_cmd)
    return path

 

 

all you have to do to give it a changeable distance is some string formatting:

 

def del_du_Groom(d = 1):
    mel_cmd =' -removeDuplicates '+d
    # -removeDuplicates 0.1  0.2  0.3  0.4  0.5                        
    path = mel.eval(mel_cmd)
    return path

 

or:

 

def del_du_Groom(d = 1):
    mel_cmd =' -removeDuplicates {0}'.format(d)
    # -removeDuplicates 0.1  0.2  0.3  0.4  0.5                        
    path = mel.eval(mel_cmd)
    return path

 

0 Likes