Maya Maya MEL and Python Scripting 2 — Questions and Answers
Question 1: What does `cmds.setAttr('pSphere1.translateX', 5)` do in Maya Python?
- Sets the X translation of pSphere1 to 5 units (Correct answer)
- Gets the current X translation of pSphere1
- Connects the translateX attribute to a keyframe at value 5
- Locks the translateX attribute so it cannot be changed
Correct answer: Sets the X translation of pSphere1 to 5 units
`cmds.setAttr` sets the value of a specified attribute on a node — here it moves pSphere1 five units along the X axis.
Question 2: What does the `select` command do in MEL?
- Selects one or more objects or components in the scene (Correct answer)
- Opens a selection dialog box for the user
- Highlights a node in the Outliner only
- Creates a new named selection set
Correct answer: Selects one or more objects or components in the scene
The `select` command in MEL programmatically selects scene objects or components, equivalent to clicking them in the viewport.
Question 3: What is a 'shelf button' in Maya scripting?
- A button on the Maya shelf that executes a MEL or Python script when clicked (Correct answer)
- A shelf reserved for quick-access deformer tools
- A custom keyboard shortcut stored in the shelf
- A tool preset button added from the tool settings panel
Correct answer: A button on the Maya shelf that executes a MEL or Python script when clicked
Shelf buttons store custom MEL or Python scripts and can be triggered with a single click, making repetitive tasks faster and more accessible.
Question 4: In Maya Python, what does `cmds.connectAttr('obj1.tx', 'obj2.tx')` do?
- Creates a live connection so obj1's translateX drives obj2's translateX (Correct answer)
- Copies obj1's current translateX value to obj2
- Constrains obj2 to follow obj1's position permanently
- Links the two objects' keyframe animation curves
Correct answer: Creates a live connection so obj1's translateX drives obj2's translateX
`connectAttr` creates a live dependency graph connection between two attributes so any change to the source attribute immediately affects the destination.
Question 5: What does the `expression` node in Maya allow you to do?
- Write mathematical formulas that drive attribute values procedurally (Correct answer)
- Write custom GLSL shaders for the viewport
- Define custom Python classes for tool development
- Create procedural animation curves in the Graph Editor
Correct answer: Write mathematical formulas that drive attribute values procedurally
Expression nodes contain MEL-like mathematical formulas that are evaluated every frame to drive attribute values, enabling procedural animation and rigs.
Question 6: What is 'MayaPy' (mayapy.exe) used for?
- A standalone Python interpreter with full Maya API access for batch scripts (Correct answer)
- A version of Maya optimized for Python-heavy scenes
- A plugin manager for Python-based Maya extensions
- A Python linter integrated into Maya's Script Editor
Correct answer: A standalone Python interpreter with full Maya API access for batch scripts
MayaPy is the standalone Python interpreter shipped with Maya that includes all Maya Python modules, enabling batch processing without opening the GUI.
What does `cmds.setAttr('pSphere1.translateX', 5)` do in Maya Python?