Getting started with PyMel

151 views
Skip to first unread message

bradle...@gmail.com

unread,
Jun 9, 2014, 1:26:42 AM6/9/14
to python_in...@googlegroups.com
I'm following the "Getting Started with PyMel" docs here: http://download.autodesk.com/us/maya/2011help/PyMel/tutorial.html#an-intro-to-pymel-objects-in-maya

My question is how to translate arguments and flags in the documentation into PyMel synatx. I'm confused what "f=1" means in the following code:

f=newFile(f=1) #start clean

The docs for newFile are as follows. Does f=1 correspond to the force flag=true? How do you specify the type of file?

def newFile(*args, **kwargs):
"""
Initialize the scene. Returns untitled scene with default location.

Flags:
- force:
Force an action to take place. (new, open, save, remove reference) Used with removeReference to force remove reference
namespace even if it has contents. Cannot be used with removeReference if the reference resides in the root namespace.
- type:
Set the type of this file. By default this can be any one of: "mayaAscii", "mayaBinary", "mel", "OBJ", "directory",
"plug-in", "audio", "move", "EPS", "Adobe(R) Illustrator(R)", "image" plug-ins may define their own types as well.Return
a string array of file types that match this file.

Derived from mel command `maya.cmds.file`
"""

pass

Geordie Martinez

unread,
Jun 9, 2014, 2:06:25 AM6/9/14
to python_inside_maya
for the most part if you see an argument in maya.cmds as as someArg=1  then you can try it with someArg=True to see if it works.

try this for your newFile example.
f means don't bother to ask the user if they want to save the file. force unload it and start fresh.

import pymel.core as pm
f = pm.newFile(f=True)

pymel didn't want to collide with the existing "file" built-in in python. maya.cmds.file is wrapped





--
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/b7a28bcd-08e6-4d9e-bbc7-6856f65592d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bradley Newman

unread,
Jun 9, 2014, 2:19:14 AM6/9/14
to python_in...@googlegroups.com
I'm generally confused about how to translate the PyMel docs into syntax, so I'll just ask a few questions to try and understand:
- Are the flags listed in PyMel docs the only available flags? Or are the flags listed in maya.cmds also available?
- What's the general workflow for writing PyMel code? I'm setup with Eclipse and the PyMel interpreter but am having trouble writing code because I'm not sure what docs to refer to and how to translate code from the docs...

Brad

Geordie Martinez

unread,
Jun 9, 2014, 2:44:16 AM6/9/14
to python_inside_maya
it's a bit different from maya.cmds
pymel is object-oriented not string-passing-oriented
* however it is actually doing the string passing in most cases under the hood but you don't have to worry about it.

I like using the "see" module to view what methods are on pynode objects.
download it and put it in your scripts dir
http://inky.github.com/see/

you make an object and then you "see" the methods and attributes on the object.

example:
import pymel.core as pm
from see import see
jnt = pm.joint()

# CHECK OUT ALL THE METHODS YOU CAN DO
see(jnt)

and it will give you a list of methods you can run on a joint. this applies to all pynodes created or cast by pymel.

pymel wraps maya.cmds under-the-hood so for some methods in pymel you can pass in the same arguments

like for instance the .inputs() and .outputs() methods are wrapping maya.cmds listConnections so you can pass the same arguments.

so if you did help(jnt.inputs)

you would see it's wrapping maya.cmds version of listConnections as a method on the object.

check this out (begin shameless self promotion):
http://www.cgcircuit.com/course/intro-to-pymel-part-1






haggi krey

unread,
Jun 9, 2014, 6:34:10 AM6/9/14
to python_in...@googlegroups.com
I agree that the pymel docs are often a bit confusing. My approach is often to look at the mel description to see how the normal commands work.
The translation is 1:1 in most cases. With objects it is a little bit different because it is a mixture between mel commands and advanced object oriented design.
This is extremly helpful if you create UI's with pymel:

b = pm.button(label="GreatButton")
b.setEnable(False);
b.label = "Still great button"

This is cool because you can save the ui objects in your own class and create UI's without any global procedures.
If you have a object like:

particleObj = pm.ls(type="nParticle")[0]

You can directly manipulate and query attributes what is much more complicated with maya.cmds or mel.
A simple dir(particleObj) give you an overview of available commands. The objects often have the same attributes and methods
as the API describes in the SDK manual.

haggi
--
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.

Marcus Ottosson

unread,
Jun 9, 2014, 7:02:18 AM6/9/14
to python_in...@googlegroups.com

Bradley Newman

unread,
Jun 10, 2014, 1:51:19 AM6/10/14
to python_in...@googlegroups.com
From what I can piece together it seems like the general flow of translating code is as follows?

PyMel doc for exportAll()

def exportAll(exportPath, **kwargs):

   """

   Export everything into a single file. Returns the name of the exported file.

   

   Flags:

     - force:

         Force an action to take place. (new, open, save, remove reference) Used with removeReference to force remove reference

         namespace even if it has contents. Cannot be used with removeReference if the reference resides in the root namespace.

     - preserveReferences:

         When used with the import/export flags this tells the importer/exporter to import/export references as references

         instead of copies of those references.

     - type:

         Set the type of this file. By default this can be any one of: "mayaAscii", "mayaBinary", "mel", "OBJ", "directory",

         "plug-in", "audio", "move", "EPS", "Adobe(R) Illustrator(R)", "image" plug-ins may define their own types as well.Return

         a string array of file types that match this file.

   

   Derived from mel command `maya.cmds.file`

   """


   pass


Lookup maya.cmds.file in Pythons Command Reference to find the flag types

[force=boolean]

[preserveReferences=boolean]

[type=string]


PyMel code translation

exportAll( "exportFileName", preserveReferences=1, force=1, type="mayaAscii")

exportPath argument doesn't have a type specified anywhere, string type simply implied by argument name.

Reply all
Reply to author
Forward
0 new messages