Home | Lesson 1 | Lesson 2 | Lesson 3 | Lesson 4 | Lesson H | ||
Lesson 5 - Maya Functions/Challenges In this lesson we'll learn a few frequently used Maya functions and use them to solve some problems. -----------------------------------------------------------------------------------------------------Maya List Objects: Without any arguements like this, this will return all objects in the scene in an array. So if we run (you'll see this line in most of my scripts): then all objects in the scene will be stored in allObjects. A useful arguments you can pass to filter the selection is typ. For example Select Object: Pretty self explanatory. nodeName should be a string of the object you want to select. You can pass the argument r=True, to force the selection to replace other selections: Node Type: This one is very useful. It returns the type of the node you pass -----------------------------------------------------------------------------------------------------We saw above how we could use mc.ls with the typ argument to return all transform nodes. Using nodeType and ls, we could select achieve the same goal with:
This may seem like a bit of a waste (5 lines to do one line's job) but it may give us some extra control over how we filter our list. In fact we could achieve the same thing in one line using list comprehension (which I won't explain here but you can read about here
List Relatives: This lists child/parent related nodes to an input node called nodeName (string). For example if we have a shape node called 'pSphereShape1', we can query it's transform node using the 'p' argument: This will return an array of all parent nodes, so if we want to store just the first one in a variable called transformNode, we would execute this: List Connections: This lists all input/output connections to the given node. If this function is called without any arguments, it will query connections on selected objects -----------------------------------------------------------------------------------------------------Get Attribute: This return the value of "nodeName.attributeName". It will error if the attribute doesn't exist: Set Attribute: This sets the value of "nodeName.attributeName". It will error if the attribute doesn't exist: Test if Object Exists: This queries maya for a node or an attribute and returns True if it exists and False if it doesn't: LESSON 5 TASKS:
lesson5_tasks.py |