[Tutor] MEL to Python Translation of array index in conditional statement

Steven D'Aprano steve at pearwood.info
Thu Nov 10 16:57:12 EST 2016


On Thu, Nov 10, 2016 at 08:08:14AM -0500, Brian Schindler wrote:

> I'm trying to convert the following code from MEL (Maya Embedded 
> Language) to Python and having trouble with syntax errors in the 
> conditional statement. Could you help me out?

Only if you help us to help you. I don't know MEL and don't know how to 
read the following:

> float $pos[3] = `xform -q -rp $obj`;
>     if ($pos[0] != 0 || $pos[1] != 0 || $pos[2] != 0) 

and chances are nobody else here does either. Can you explain in words 
what it does? If you're getting an error, best to show us the code you 
tried and the FULL error you are getting (copy and paste it please, as 
text, don't post a screenshot).

I'm going to take a wild guess that the code means something like:

pos = an array of four values
if pos[0] != 0 or pos[1] != 0 or pos[2] != 0 then:
    call an external program xform with arguments -q -rp obj
    convert the result to a floating point value
    set pos[3] to that number


which would be something similar to:


import subprocess
if any(pos[:3]):
    output = subprocess.check_output(['xform', '-q', '-rp', obj])
    pos[3] = float(output)


-- 
Steve


More information about the Tutor mailing list