Blog of


APyTA_05: Self learning:Exploring the RAM

APyTA_05: Self learning:Exploring the RAM

Now you apprehend objects, I will show you the pythonic holy trinity: print, help, dir
Personally, I use them aaaall the time, and we can call that section: forget the doc !

import pymel.core
polyCubeReturnValue  = pymel.core.modeling.polyCube()
help(polyCubeReturnValue) #Display all the embeded doc of your object (DOCSTRING)
print type(polyCubeReturnValue) , len(polyCubeReturnValue) #<type 'list'> 2

You can use print statement without parenthesis, and with several arguments (comma separated).
Help will display directly the help of your object (when it is written of course...)

print type(polyCubeReturnValue[0]) #<class 'pymel.core.nodetypes.Transform'>
print type(polyCubeReturnValue[1]) #<class 'pymel.core.nodetypes.PolyCube'>
myCube = polyCubeReturnValue[1]
print myCube #polyCube1 (Notice that the print of a class just return object name.
print dir(myCube) #['MAttrClass', 'MdgTimerMetric', '__add__',... ,'setSubdivisionsHeight',..., 'type', 'unlock', 'upper']

See how we can be really sure about what's our variables with type statement, and then explore the object capabilities with dir ?
Sometimes the doc are wrong, Sometimes documentation is unclear, unfinished, unprecise.
So keep in mind a saving-ass maxim: RAM DO NOT LIE.

myTransform = polyCubeReturnValue[0] #Let's explore the first return class of polyCube, the Transform
print dir(myTransform)  #['LimitType', ..., 'getShape' ,..., 'upper', 'zeroTransformPivots']
print myTransform.getShape() #pCubeShape1
print dir( myTransform.getShape() )

Notice that in the last line, I could make another variable myShape = myTransform.getShape()
But if I don't really need to reuse it, you can call methods and members in cascade like this.

A lot of time, you will have to verify the content or the type of your variable.
Print can display it into the Maya script editor, giving you the best feedback.
Tips : Script Editor could be a pain in the as* when printing a lot of stuff.
Performance are very bad, so for huge logging (like all vertices of your mesh).
Why not print into the Output window of Maya ?

print('Hello world 1')
import sys
sys.stdout.write('Hello world 2')
sys.__stdout__.write('Hello world 3') #This way, the print display your string in output editor of Maya.
Comments (1) Trackbacks (0)
  1. In addition to that, I encounter today a case where a function is not documented.
    So how knowing the numbers of arguments, their names ?
    Here is the code to find that :

    import inspect

Leave a comment


No trackbacks yet.