Where to learn the basics of Python?

https://www.w3schools.com/python/default.asp

Searching documentation

Get better results on google by adding DOCUMENTATION to your search google searches. ie: “pymel xform documentation”

Importing Pymel

import pymel.core as pm

ls - Get selected objects

ls returns an array with all the selected objects in order of selection so sel[0] would be the first object selected then sel[1] and so on. The order you select the objects is the same in the resulting array, use it for more complex scripts.

sel = [pm.ls](<http://pm.ls/>)(selection=True)

xform - transforms objects and pivots

xform is useful to get/set transform and also works to manipulate pivots. When using xform on pivots just know it has different flags to get the rotate or scale pivots, there is none for translate, I don’t know why. I use rotate pivot for convenience and never had issues.

pm.xform([OBJECT_NAME], [ARGs])

PyNode

Use PyNode to get a scene object in Maya as a python object. That allows you call functions and change variables in a cleaner way.

pm.PyNode

# USE
objNode = pm.PyNode("Node_Name")

Documentation:

https://help.autodesk.com/cloudhelp/2022/ENU/Maya-Tech-Docs/PyMel/pynodes.html

PyNode Setting and Getting Values

To get or set values to a variable (attributes) of a PyNode use the following commands. Say a joint node is named “legJoint”