📋 Metadata
- Author: roaoao
- Date: 2018-05-12 08:34:59
- Type:
answer - Reply to: post_01395
💬 Content
Zimlorog:
when I try to add the following code (from the pie menu tooltip) to one of the popup buttons, it says “invalid syntax”.
Example:
bpy.ops.align.2xyz(axis=‘0’)
One of the variables starts with a numeral (2xyz). We can’t use it like this in python. Try this code:
getattr(bpy.ops.align, "2xyz")('INVOKE_DEFAULT', True, axis="0")
Note that we need to add INVOKE_DEFAULT and True positional arguments in this case.
- INVOKE_DEFAULT starts the operator in interactive mode (if supported)
- True adds undo/redo features (if supported)
PME adds them automatically when the code starts with bpy.ops.