mel in python script calling

801 views
Skip to first unread message

Christopher.

unread,
May 31, 2015, 3:34:38 PM5/31/15
to python_in...@googlegroups.com
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


Justin Israel

unread,
May 31, 2015, 3:49:14 PM5/31/15
to python_in...@googlegroups.com

You are trying to mix python and MEL syntax together? You can't do that, unless it's Mel code that uses the python() function to call python code, and visa versa.

# some .py
def foo():
    # py syntax
foo()

// some .mel
global proc foo() {
    // Mel syntax
}


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/89a8b58e-6287-467f-b3c3-5137356b6a9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher.

unread,
May 31, 2015, 6:28:51 PM5/31/15
to python_in...@googlegroups.com
That's what I thought.  How can I have a mixed bag of MEL and Python, would you need to see one of the other parts of the script ?


On Sunday, May 31, 2015 at 3:49:14 PM UTC-4, Justin Israel wrote:

You are trying to mix python and MEL syntax together? You can't do that, unless it's Mel code that uses the python() function to call python code, and visa versa.

# some .py
def foo():
    # py syntax
foo()

// some .mel
global proc foo() {
    // Mel syntax
}


On Mon, 1 Jun 2015 7:34 AM Christopher. <crestchr...@gmail.com> wrote:
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
May 31, 2015, 6:42:37 PM5/31/15
to python_in...@googlegroups.com

You can use both MEL and Python in your solutions. MEL goes in mel files, and python goes in py files.

How to call python code from your mel scripts:
http://download.autodesk.com/global/docs/maya2014/en_us/Commands/python.html

How to call mel code from your python scripts:

import maya.mel as mm
mm.eval(SOME_MEL_CODE_STRING)

On Mon, Jun 1, 2015 at 10:28 AM Christopher. <crestchr...@gmail.com> wrote:
That's what I thought.  How can I have a mixed bag of MEL and Python, would you need to see one of the other parts of the script ?


On Sunday, May 31, 2015 at 3:49:14 PM UTC-4, Justin Israel wrote:

You are trying to mix python and MEL syntax together? You can't do that, unless it's Mel code that uses the python() function to call python code, and visa versa.

# some .py
def foo():
    # py syntax
foo()

// some .mel
global proc foo() {
    // Mel syntax
}


On Mon, 1 Jun 2015 7:34 AM Christopher. <crestchr...@gmail.com> wrote:
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/89d09d96-1048-44cb-9bf1-676f036c9837%40googlegroups.com.

Christopher.

unread,
Jun 1, 2015, 11:47:28 AM6/1/15
to python_in...@googlegroups.com
When you say (some_mel_code_string) do you mean a string of whatever I want, or mel code as a string, or something else ?
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Jun 1, 2015, 4:21:58 PM6/1/15
to python_in...@googlegroups.com
Haha, yes. You get to put anything your heart desires in that string and it will come true. 
Actually, you just put valid MEL syntax into that string, and it will execute:

some_mel = "ls -sl"
mm.eval(some_mel)


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/742c2f73-77cf-4175-8047-9006ca88285e%40googlegroups.com.

Geordie Martinez

unread,
Jun 1, 2015, 4:36:00 PM6/1/15
to python_inside_maya
pymel has a good converter that you can use to convert mel to a python script:

paste this code into a python panel in maya.

a little prompt will come up for you to enter in some MEL.
paste some MEL in there and
press OK.

in the script editor history panel will have the python  you need converted.
it's not perfect, but it's a good place to start learning if you already know MEL.


#MEL TO PY
import pymel.core as pm
import pymel.tools.mel2py as mel2py
result = pm.promptDialog(

            title='SPIT BACK PYMEL',
            message='Enter string:',
            button=['OK', 'Cancel'],
            defaultButton='OK',
            cancelButton='Cancel',
            dismissString='Cancel')

if result == 'OK':
    text = pm.promptDialog(query=True, text=True)
    
    # GET THE PYMEL EQUIVALENT
    pmAnswer = mel2py.mel2pyStr(text,  pymelNamespace='pm')
    
    # GET RID OF THE OLD WAY
    pmCode = pmAnswer.replace("pymel.all","pymel.core")
    print(pmCode)








Christopher.

unread,
Jun 1, 2015, 10:07:35 PM6/1/15
to python_in...@googlegroups.com
Alright;
import maya.mel as *whatever name*
*whatever name*.eval (
<MEL script>
)
Correct ?

Converters are fine for some, I rather understand the guts :) 

Justin Israel

unread,
Jun 1, 2015, 10:53:28 PM6/1/15
to python_in...@googlegroups.com
On Tue, Jun 2, 2015 at 2:07 PM Christopher. <crestchr...@gmail.com> wrote:
Alright;
import maya.mel as *whatever name*
*whatever name*.eval (
<MEL script>
)
Correct ?

Yep. Where <MEL script> is a string.
 

Converters are fine for some, I rather understand the guts :) 


On Sunday, May 31, 2015 at 3:34:38 PM UTC-4, Christopher. wrote:
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Christopher.

unread,
Jun 2, 2015, 9:36:24 AM6/2/15
to python_in...@googlegroups.com
The beginning and end of the MEL string has a nice long pink line in Sublime, I assume this is because Sublime doesn't have syntax highlighting for MEL ?

The MEL code doesn't execute, I get a SyntaxError on line 1: EOL while scanning string literal ?


On Monday, June 1, 2015 at 10:53:28 PM UTC-4, Justin Israel wrote:
On Tue, Jun 2, 2015 at 2:07 PM Christopher. <crestchr...@gmail.com> wrote:
Alright;
import maya.mel as *whatever name*
*whatever name*.eval (
<MEL script>
)
Correct ?

Yep. Where <MEL script> is a string.
 

Converters are fine for some, I rather understand the guts :) 


On Sunday, May 31, 2015 at 3:34:38 PM UTC-4, Christopher. wrote:
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Jun 2, 2015, 3:53:41 PM6/2/15
to python_in...@googlegroups.com

Please paste an example of your actual code. A big pink long probably means you have a python syntax error. The Mel code should be in an actual string so it should syntax highlight like a string.


On Wed, 3 Jun 2015 1:36 AM Christopher. <crestchr...@gmail.com> wrote:
The beginning and end of the MEL string has a nice long pink line in Sublime, I assume this is because Sublime doesn't have syntax highlighting for MEL ?

The MEL code doesn't execute, I get a SyntaxError on line 1: EOL while scanning string literal ?

On Monday, June 1, 2015 at 10:53:28 PM UTC-4, Justin Israel wrote:
On Tue, Jun 2, 2015 at 2:07 PM Christopher. <crestchr...@gmail.com> wrote:
Alright;
import maya.mel as *whatever name*
*whatever name*.eval (
<MEL script>
)
Correct ?

Yep. Where <MEL script> is a string.
 

Converters are fine for some, I rather understand the guts :) 


On Sunday, May 31, 2015 at 3:34:38 PM UTC-4, Christopher. wrote:
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/57ff7082-05fb-4a49-9a65-57a25ea97041%40googlegroups.com.

Christopher.

unread,
Jun 3, 2015, 11:58:15 AM6/3/15
to python_in...@googlegroups.com
import maya.mel as multiuvexport
multiuvexport.eval (
    "{
int $uMin=-1;
int $uMax=1;
int $vMin=-1;
int $vMax=1;

int $i,$j;
string $UVCmd;


for ($i = $uMin; $i < $uMax; $i++)
{
for ($j = $vMin; $j < $vMax; $j++)
{
$UVCmd = "uvSnapshot -o -aa -uMin "+$i+" -uMax "+($i+1)+" -vMin "+$j+" -vMax "+($j+1)+ "-n \"c:\5\uvImage_u"+($i+1)+"_v"+($j+1)+".jpg\" -xr 4096 -yr 4096 -ff jpg;" ;
eval $UVCmd;
}

}

}"

)

On Tuesday, June 2, 2015 at 3:53:41 PM UTC-4, Justin Israel wrote:

Please paste an example of your actual code. A big pink long probably means you have a python syntax error. The Mel code should be in an actual string so it should syntax highlight like a string.


On Wed, 3 Jun 2015 1:36 AM Christopher. <crestchr...@gmail.com> wrote:
The beginning and end of the MEL string has a nice long pink line in Sublime, I assume this is because Sublime doesn't have syntax highlighting for MEL ?

The MEL code doesn't execute, I get a SyntaxError on line 1: EOL while scanning string literal ?

On Monday, June 1, 2015 at 10:53:28 PM UTC-4, Justin Israel wrote:
On Tue, Jun 2, 2015 at 2:07 PM Christopher. <crestchr...@gmail.com> wrote:
Alright;
import maya.mel as *whatever name*
*whatever name*.eval (
<MEL script>
)
Correct ?

Yep. Where <MEL script> is a string.
 

Converters are fine for some, I rather understand the guts :) 


On Sunday, May 31, 2015 at 3:34:38 PM UTC-4, Christopher. wrote:
Hi, I have a script that uses the def() syntax, the problem is the original code is MEL, using the following syntax is not working ?

def acme()
[MEL code]
acme()


 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Marcus Ottosson

unread,
Jun 3, 2015, 12:50:39 PM6/3/15
to python_in...@googlegroups.com

Don’t mean to be a critic, but man, there are so many things wrong with that piece of code. :D

import maya.mel as multiuvexport

Whyyyy?

multiuvexport.eval (
...
eval $UVCmd;

Eval within an eval, whyyyy?

-xr 4096 -yr 4096

Hardcoding values, concatenating strings, whyyyy?

How are you coming up with these things?


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e2fe1755-9028-49a8-97f3-c141f7e5404e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Christopher.

unread,
Jun 3, 2015, 12:54:32 PM6/3/15
to python_in...@googlegroups.com
I can't take full responsibility for that code, only about less then 5%, that screw up being the import maya.mel as multiuvexport, I knew it was a screw up :) The rest of the code is from elsewhere !
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Joe Weidenbach

unread,
Jun 3, 2015, 1:21:49 PM6/3/15
to python_in...@googlegroups.com
Questioning the code aside:

The immediate issue you're running into seems to be that Python doesn't support multi-line strings which are just denoted with a single quotation mark.

If you're going for multi-line strings, you'll need to use the multi-line string quote-- """String here""" -- Note the triple quotations.

With that said, I agree with Marcus here. 

First, why are we calling this script from Python?  It seems like it might be better suited to be entirely in MEL. I've run into a number of situations where I need to call MEL code from my Python scripts, but this looks like primarily coding in MEL and then forcing it into Python.

You could do the same thing more like this:

# Avoid importing under other names
import maya.mel as mel

uMin = -1
uMax = 1
vMin = -1
vMax = 1

for i in range(uMin, uMax - uMin):
    for j in range(uMin, uMax - uMin):
        path = r"c:\\5\\uvImage_u{0}_v{1}.jpg".format(i+1, j+1)
        UVCmd = r'uvSnapshot -o -aa -uMin {0} -uMax {1} - vMin {2} -vMax {3} -n "{4}" -xr 4096 -yr 4096 -ff jpg;'
        UVCmd = UVCmd.format(i, i+1, j, j+1, path)
        mel.eval(UVCmd)

It's best if you're going to use Python to use it all the way through, with independent MEL commands where there is no other option (which, to be fair, happens all too often in Maya).

Let me know if you have questions on that code, I utilized a few string formatters that I find make my code easier to read, but can be a bit confusing if you're not used to them.

Hope that helps!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e2fe1755-9028-49a8-97f3-c141f7e5404e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.




This email is free from viruses and malware because avast! Antivirus protection is active.


Crest Christopher

unread,
Jun 3, 2015, 1:28:46 PM6/3/15
to python_in...@googlegroups.com
Hi Joe, before testing your code, I agree with you, the code is best run in MEL before you even brought up that concern I was thinking, it doesn't make sense, and if someone in the group brought it to the surface, it wouldn't surprise me. 

The reason; the MEL code has to be wrapped in python code, otherwise the other script, did I mention it was part of another script, regardless if I did or didn't, it can't read MEL individually, that is why, not I wanted to, or felt the desire to ;-) instead I had to wrap it in python. ;-)

Let me give your code a run ;-)

Joe Weidenbach wrote:

Questioning the code aside:

The immediate issue you're running into seems to be that Python
doesn't support multi-line strings which are just denoted with a
single quotation mark.

If you're going for multi-line string s, you'll need to use the
    <javascript:>> wrote:

        The beginning and end of the MEL string has a nice long pink
        line in Sublime, I assume this is because Sublime doesn't
& nbsp;       have syntax highlighting for MEL ?


        The MEL code doesn't execute, I get a SyntaxError on line 1:
        EOL while scanning string literal ?

        On Monday, June 1, 2015 at 10:53:28 PM UTC-4, Justin Israel
        wrote:



            On Tue, Jun 2, 2015 at 2:07 PM Christopher.
            <crestchr...@gmail.com> wrote:

                Alright;
                import maya.mel as *whatever name*
           &nbs p;    *whatever name*.eval (

                <MEL script>
                )
                Correct ?


            Yep. Where <MEL script> is a string.


                Converters are fine for some, I rather understand the
                guts :)


                On Sunday, May 31, 2015 at 3:34:38 PM UTC-4,
                Christopher. wrote:

                    Hi, I have a script that uses the def() syntax,
                    the problem is the original code is MEL, using
                    the following syntax is not working ?

                    def acme()
                    [MEL code]
                    acme()




         &nbsp ;      --
                You received this message because you are subscribed
                to the Google Groups "Python Programming for Autodesk
                Maya" group.
                To unsubscribe from this group and stop receiving
                emails from it, send an email to
                python_inside_m...@googlegroups.com.
                To view this discussion on the web vi sit

                For more options, visit
                https://groups.google.com/d/optout
                <https://groups.google.com/d/optout>.

        --
        You received this message because you a re subscribed to the

        Google Groups "Python Programming for Autodesk Maya" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to
        python_inside_m...@googlegroups.com <javascript:>.

        To view this discussion on the web visit

        For more options, visit https://groups.google.com/d/optout
 &nbsp ;      <https://groups.google.com/d/optout>.


--
You received this message because you are subscribed to the Google
Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it,

To view this discussion on the web visit

For more options, visit https://groups.google.com/d/optout.




------------------------------------------------------------------------
<https://www.avast.com/antivirus>

This email is free from viruses and malware because avast! Antivirus
<https://www.avast.com/antivirus> protection is active.


--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/T7kfPkQi68A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
python_inside_m...@googlegroups.com
<mailto:python_inside_m...@googlegroups.com>.

To view this discussion on the web visit

Christopher.

unread,
Jun 3, 2015, 1:36:33 PM6/3/15
to python_in...@googlegroups.com
Hi Joe, that works well, thank you, but, can I squeeze in a addition ? ;-)
Can choose where to save & the resolution from 1024 to max 8192 res ?
                python_inside_maya+unsub...@googlegroups.com.

                To view this discussion on the web vi sit
                https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com
                <https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com?utm_medium=email&utm_source=footer>.
                For more options, visit
                https://groups.google.com/d/optout
                <https://groups.google.com/d/optout>.

        --
        You received this message because you a re subscribed to the
        Google Groups "Python Programming for Autodesk Maya" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to
        python_inside_maya+unsub...@googlegroups.com <javascript:>.

        To view this discussion on the web visit
        https://groups.google.com/d/msgid/python_inside_maya/57ff7082-05fb-4a49-9a65-57a25ea97041%40googlegroups.com
        <https://groups.google.com/d/msgid/python_inside_maya/57ff7082-05fb-4a49-9a65-57a25ea97041%40googlegroups.com?utm_medium=email&utm_source=footer>.
        For more options, visit https://groups.google.com/d/optout
 &nbsp ;      <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to the Google
Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it,




------------------------------------------------------------------------
<https://www.avast.com/antivirus>

This email is free from viruses and malware because avast! Antivirus
<https://www.avast.com/antivirus> protection is active.


--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/T7kfPkQi68A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to

Joe Weidenbach

unread,
Jun 3, 2015, 4:00:56 PM6/3/15
to python_in...@googlegroups.com
Are you looking to specify those as code, or do you want a UI to let the use choose?  Two very different scenarios.

                python_inside_m...@googlegroups.com.

                To view this discussion on the web vi sit
                https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com
                <https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com?utm_medium=email&utm_source=footer>.
                For more options, visit
                https://groups.google.com/d/optout
                <https://groups.google.com/d/optout>.

        --
        You received this message because you a re subscribed to the
        Google Groups "Python Programming for Autodesk Maya" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to
        python_inside_m...@googlegroups.com <javascript:>.

        To view this discussion on the web visit
        https://groups.google.com/d/msgid/python_inside_maya/57ff7082-05fb-4a49-9a65-57a25ea97041%40googlegroups.com
        <https://groups.google.com/d/msgid/python_inside_maya/57ff7082-05fb-4a49-9a65-57a25ea97041%40googlegroups.com?utm_medium=email&utm_source=footer>.
        For more options, visit https://groups.google.com/d/optout
 &nbsp ;      <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to the Google
Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it,




------------------------------------------------------------------------
<https://www.avast.com/antivirus>

This email is free from viruses and malware because avast! Antivirus
<https://www.avast.com/antivirus> protection is active.


--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/T7kfPkQi68A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/797eb677-ca8d-4b01-92b5-45c72e7d4461%40googlegroups.com.

Crest Christopher

unread,
Jun 3, 2015, 5:14:27 PM6/3/15
to python_in...@googlegroups.com
I would like the UI to let the user choose.

Joe Weidenbach wrote:

Are you looking to specify those as code, or do you want a UI to let
the use choose?  Two very different scenarios.

On Wed, Jun 3, 2015 at 10:36 AM, Christopher.
<crestchr...@gmail.com <mailto:crestchr...@gmail.com>> wrote:

    Hi Joe, that works well, thank you, /but/, can I squeeze in a

    addition ? ;-)
    Can choose where to save & the resolution from 1024 to max 8192 res ?


    On Wednesday, June 3, 2015 at 1:28:46 PM UTC-4, Christopher. wrote:

        Hi Joe, before testing your code, I agree with you, the code
        is best run in MEL before you even brought up that concern I
        was thinking, it doesn't make sense, and if someone in the
        group brought it to the surface, it wouldn't surprise me.

        The reason; the MEL code has to be wrapped in python code,
        otherwise the other script, did I mention it was part of
        another script, regardless if I did or didn't, it can't read
        MEL individually, that is why, not I wanted to, or felt the
        desire to ;-) instead I had to wrap it in python. ;-)

        Let me give your code a run ;-)

        Joe Weidenbach wrote:


    & nbsp;   Questioning the code aside:
      &nb sp; through,

        with independent MEL commands where there is no other option
        (which,
        to be fair, happens all too often in Maya).

        Let me know if you have questions on that code, I utilized a few
        string formatters that I find make my code easier to read,
        but can be
        a bit confusing if you're not used to them.

        Hope that helps!

        On 6/3/2015 8:58 AM, Christopher. wrote:


        import maya.mel as multiuvexport
        multiuvexport.eval (
&nb sp;       "{

        int $uMin=-1;
        int $uMax=1;
        int $vMin=-1;
        int $vMax=1;

        int $i,$j;
        string $UVCmd;


        for ($i = $uMin; $i < $uMax; $i++)
        {
        for ($j = $vMin; $j < $vMax; $j++)
        {
        $UVCmd = "uvSnapshot -o -aa -uMin "+$i+" -uMax "+($i+1)+" -vMin
        "+$j+" -vMax "+($j+1)+ "-n
        \"c:\5\uvImage_u"+($i+1)+"_v"+($j+1)+".jpg\" -xr 4096 -yr
 &n bsp;      4096 -ff

        jpg;" ;
        eval $UVCmd;
        }

        }

        }"

        )

        On Tuesday, June 2, 2015 at 3:53:41 PM UTC-4, Justin Israel
        wrote:

            Please paste an example of your actual code. A big pink long
            probably means you have a python syntax error. The Mel code
            should be in an actual string so it should syntax
        highlight like
            a string.


            On Wed, 3 Jun 2015 1:36 AM Christopher.
        <crestchr...@gmail.com
        <javascript:>> wrote:

                The beginning and end of the MEL string has a nice
        long pink
                line in Sublime, I assume this is because Sublime
        doesn't
        & nbsp;       have syntax highlighting for MEL ?

                T he MEL code doesn't execute, I get a SyntaxError on

        line 1:
                EOL while scanning string literal ?

                On Monday, June 1, 2015 at 10:53:28 PM UTC-4, Justin
        Israel
                wrote:



                    On Tue, Jun 2, 2015 at 2:07 PM Christopher.
        <crestchr...@gmail.com> wrote:

                        Alright;
   &n bsp;                    import maya.mel as *whatever name*

        &nbs p;    *whatever name*.eval (
        <MEL script>
                        )
                        Correct ?


                    Yep. Where <MEL script> is a string.


                        Converters are fine for some, I rather
&nbs p;       understand the

                        guts :)


                        On Sunday, May 31, 2015 at 3:34:38 PM UTC-4,
                        Christopher. wrote:

                            Hi, I have a script that uses the def()
        syntax,
                         &nb sp;  the problem is the original code is MEL,

        using
                            the following syntax is not working ?

                            def acme()
                            [MEL code]
                            acme()




        &nbsp ;      --
                         You received this message because you are
        subscribed
                        to the Google Groups "Python Programming for
        Autodesk
                        Maya" group.
                        To unsubscribe from this group and stop
        receiving
                      &nbsp ; emails from it, send an email to
        python_inside_m...@googlegroups.com
        <mailto:python_inside_maya%2Bunsu...@googlegroups.com>.

                        To view this discussion on the web vi sit
        https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com
        <https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com?utm_medium=email&utm_source=footer
        <https://groups.google.com/d/msgid/python_inside_maya/e4cafeca-cf47-4477-85be-4216a8beca6e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
                        For more options, visit
        https://groups.google.com/d/optout
        <https://groups.google.com/d/optout>.

                --
                You received this message because you a re
        subscribed to the
                Google Groups "Python Programming for Autodesk Maya"
        group.
                To unsubscribe from this group and stop receiv ing
        emails from
                it, send an email to
        python_inside_m...@googlegroups.com

                For more options, visit
        https://groups.google.com/d/optout
        &nbsp ; <https://groups.google.com/d/optout>.

        --
        You received this message because you are subscribed to the
        Google
        Groups "Python Programming for Autodesk Maya" group.
        To unsubscribe from this group and stop receiving emails
        from it,
        send an email to
        python_inside_m...@googlegroups.com

        For more options, visit https://groups.google.com/d/optout.





        ------------------------------------------------------------------------
        <https://www.avast.com/antivirus>

        This email is free from viruses and malware because avast!
        Antivirus
        <https://www.avast.com/antivirus> protection is active.


        --
        You received this message because you are subscribed to a
        topic in the
  &nbsp ;     Google Groups "Python Programming for Autodesk Maya" group.

        To unsubscribe from this topic, visit
        https://groups.google.com/d/topic/python_inside_maya/T7kfPkQi68A/unsubscribe.
        To unsubscribe from this group and all its topics, send an
        email to
        python_inside_m...@googlegroups.com

        To view this discussion on the web visit


    --
    You received this message because you are subscribed to the Google
    Groups "Python Programming for Autodesk Maya" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to python_inside_m...@googlegroups.com

    To view this discussion on the web visit


    For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to a topic in the
Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/python_inside_maya/T7kfPkQi68A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
python_inside_m...@googlegroups.com

To view this discussion on the web visit

Crest Christopher

unread,
Jun 3, 2015, 5:15:51 PM6/3/15
to python_in...@googlegroups.com
You rewrote the MEL code in python correct ?

Wednesday, June 03, 2015 5:14 PM
I would like the UI to let the user choose.

Joe Weidenbach wrote:
Wednesday, June 03, 2015 4:00 PM
Are you looking to specify those as code, or do you want a UI to let the use choose?  Two very different scenarios.


--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/T7kfPkQi68A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da7bqAj08ogetFbmuEUShQbzp%3Dy-5ASg%2Bm23R%3D4AaLxwMQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.
Wednesday, June 03, 2015 1:36 PM
Hi Joe, that works well, thank you, but, can I squeeze in a addition ? ;-)
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/797eb677-ca8d-4b01-92b5-45c72e7d4461%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Wednesday, June 03, 2015 1:28 PM
Hi Joe, before testing your code, I agree with you, the code is best run in MEL before you even brought up that concern I was thinking, it doesn't make sense, and if someone in the group brought it to the surface, it wouldn't surprise me. 

The reason; the MEL code has to be wrapped in python code, otherwise the other script, did I mention it was part of another script, regardless if I did or didn't, it can't read MEL individually, that is why, not I wanted to, or felt the desire to ;-) instead I had to wrap it in python. ;-)

Let me give your code a run ;-)

Joe Weidenbach wrote:
Wednesday, June 03, 2015 1:21 PM
Questioning the code aside:

The immediate issue you're running into seems to be that Python doesn't support multi-line strings which are just denoted with a single quotation mark.

If you're going for multi-line strings, you'll need to use the multi-line string quote-- """String here""" -- Note the triple quotations.


With that said, I agree with Marcus here. 

First, why are we calling this script from Python?  It seems like it might be better suited to be entirely in MEL. I've run into a number of situations where I need to call MEL code from my Python scripts, but this looks like primarily coding in MEL and then forcing it into Python.

You could do the same thing more like this:

# Avoid importing under other names
import maya.mel as mel

uMin = -1
uMax = 1
vMin = -1
vMax = 1

for i in range(uMin, uMax - uMin):
    for j in range(uMin, uMax - uMin):
        path = r"c:\\5\\uvImage_u{0}_v{1}.jpg".format(i+1, j+1)
        UVCmd = r'uvSnapshot -o -aa -uMin {0} -uMax {1} - vMin {2} -vMax {3} -n "{4}" -xr 4096 -yr 4096 -ff jpg;'
        UVCmd = UVCmd.format(i, i+1, j, j+1, path)
        mel.eval(UVCmd)

It's best if you're going to use Python to use it all the way through, with independent MEL commands where there is no other option (which, to be fair, happens all too often in Maya).


Let me know if you have questions on that code, I utilized a few string formatters that I find make my code easier to read, but can be a bit confusing if you're not used to them.

Hope that helps!

On 6/3/2015 8:58 AM, Christopher. wrote:




This email is free from viruses and malware because avast! Antivirus protection is active.


--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/556F379A.6010608%40gmail.com.

Joe Weidenbach

unread,
Jun 3, 2015, 6:13:31 PM6/3/15
to python_in...@googlegroups.com
Yes indeed I did.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/556F6E79.1030903%40gmail.com.

Joe Weidenbach

unread,
Jun 4, 2015, 1:49:42 AM6/4/15
to python_in...@googlegroups.com
You will basically need to come up with a desired UI layout.  For a file dialog, you could do something similar to this:

import os.path

import maya.cmds as cmds

homeDir = os.path.expanduser("~")

filter = "Jpeg Images (*.jpg)"
filePath = cmds.fileDialog2(cap="Choose File Save Directory", startingDirectory=homeDir,
                            fileFilter=filter, fileMode=0)
                            
print filePath[0]

That would get you the desired folder and filename, which you could then split apart and attach your tile numbering to.  For the most part, the Python versions of the UI elements work the same as their MEL counterparts.  If you can write the UI in MEL, it's pretty easy to translate it to Python.  Python gives some extra benefits in terms of string manipulation and other things.  I haven't played with it, but it looks to me like this whole project could be written in Python.  I left the uvSnapshot command in MEL for the sake of demonstrating the appropriate use case of calling MEL code from Python in my earlier code.

If you're struggling with converting from MEL to Python, I did a basic writeup on my blog outlining some of the major differences.


I unfortunately haven't had time to continue the series beyond the basics of variables, but it's at least a start.

Marcus Ottosson

unread,
Jun 4, 2015, 2:08:25 AM6/4/15
to python_in...@googlegroups.com
I think what Christoper is asking is for you to write his software for him. But Christopher, that my friend is called taking advantage of people's goodwill. I can only speak for myself, but I'd rather help you learn to do it on your own, than to be your monkey.


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Joe Weidenbach

unread,
Jun 4, 2015, 3:51:51 AM6/4/15
to python_in...@googlegroups.com
I don't feel like the conversation started out that way, but honestly, that's where it gets to when the question about UI came up.

Christopher, I'd refer you to http://justinfx.com/2012/04/14/write-my-code-for-me/ for a reference on this.  I'm certainly glad to help wherever I can in developing software, and I understand that working with MEL or Python in Maya is one of those area's that's very woefully underdocumented, or at the very least underexplained outside of formal classes.  But, with that said, writing code for you is really not particularly helpful.  In these types of forums, it's usually the goal to develop a library of helpful techniques which can be searched and referenced again later--in other words, for this situation, here's an approach that can work.

I've been teaching programming classes, inside and outside of Maya, for the last eight years.  In every class I teach, I'll get students who don't pay attention to lectures or do the exercises I assign, and then when they try to do projects they ask me how to solve the problem--once again, asking me to do the work that I have assigned to them, after lecturing on the specific topics they needed to use.  If I were to do this, it would cause significant problems; First, and most importantly, if I give them a passing grade (which they have obviously not earned if I wrote their project), I am placing my personal seal of approval on them that they deserve to move forward in their program.  Secondly, if I do the work, they don't learn anything except to find someone who knows how to do the work.  So, it's a disservice to myself, and to the student for me to write that code from scratch.

By comparison, if a student comes to me with complete code that either doesn't quite do what they tried to accomplish, or fails due to syntax errors, it's completely beneficial to both of us--I get to do my job of teaching (which is something I love doing), and the student learns what to watch for or how to debug that type of code for the future.

I'm not implying that you are one of the former students here--the initial request was fine: some MEL code you were trying to get working in an existing Python script.  It had some issues, and areas that could be better approached, but it was an effort to make something work.

In the second case, you simply asked for a solution with a file dialog and options to change the resolution.  I can understand, if you're not used to using Python, that that could be challenging.  However, in that case, there's lots of great starting tutorials for Python.  One of my favorites is http://learnpythonthehardway.org/, which is completely free to read online.  Once you understand the basics of Python, it's really not hard to translate MEL.

So, the key here is this: I'm glad to help.  I'll gladly try to show different approaches, even going so far as to write complete systems if the question is about a complex topic that I feel doesn't get good explanation elsewhere (specifically areas that I struggled to figure out), but for the most part I'll try to point you in the right direction rather than writing your code for you.

For the UI, file dialogs are always a bit complex as far as understanding if you've never worked with them before.  But UI on the whole is something that is beyond the scope of what I'm going to write a complete solution for on a forum--it's too specialized to a specific need to be useful as a demonstration of a general technique.

So, in this case, I'm going to ask that you try to come up with code that will build a UI that you like.  I'm glad to help you in translating that code to Python if you can write it in MEL (I covered the main syntactic differences on the blog entries I listed), and I'm glad to help you in debugging code that doesn't work.  But I can't help if you don't have code to start with.

Christopher Crouzet

unread,
Jun 4, 2015, 4:58:18 AM6/4/15
to python_in...@googlegroups.com
I might be wrong but from the style of his emails, Christopher Crest seems to be the same person that showed up on the Softimage mailing list over the years under different aliases such as Christopher Nerd, Christopher, The Creative Sheep, PowerCardinal, and probably others. And that brings me some fun memories, good luck! :)




For more options, visit https://groups.google.com/d/optout.



--

Panupat Chongstitwattana

unread,
Jun 4, 2015, 8:36:04 AM6/4/15
to python_in...@googlegroups.com
If I use PySide as my main UI, can I fire up cmds.fileDialog2 instead of QtGui.QFileDialog and send the result back to PySide UI? What's the advantage of each you think?

Joe Weidenbach

unread,
Jun 4, 2015, 1:53:41 PM6/4/15
to python_in...@googlegroups.com
If you're using PySide, I'd be on the side of using QFileDialog.  It's a really simple setup with a convenience call (static function):

fileName = QtGui.QFileDialog.getSaveFileName(self, "Save File As",
                                             "C:/", "FBX Files (*.fbx)")

While you CAN integrate fileDialog2 in PySide, it's a lot of extra work, for no real gain.  Honestly, when I've been trying to throw something together quickly, I've been more likely to call QFileDialog from my Maya UI.  It's a separate window, so in the end it makes no real difference, besides which library you bring in.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages