Post #1397: ![](https://blenderartists.org/user_avatar/blenderartists.org/zimlorog/48/536415

📋 Metadata

  • Author: roaoao
  • Date: 2018-05-12 08:34:59
  • Type: answer
  • Quality Score: 8/10
  • Reply to: post_01395

🏷️ Tags

pie-menu popup-dialog python-scripting intermediate solved

  • Pie Menu Editor
  • Popup Dialog Editor
  • Python Scripting

💬 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.


🔗 View on Blender Artists