Post #2906: Hi roaoao.

📋 Metadata

  • Author: anminmakura
  • Date: 2019-12-02 06:02:19
  • Type: question
  • Quality Score: 7/10
  • Replies (1): post_02908

🏷️ Tags

macro python-scripting intermediate unsolved

  • Macro Editor
  • Python Scripting

💬 Content

Hi roaoao.
This is also a rudimentary question, but I’m not sure about Pie Menu Editor’s “if definition”.
For example, I understand that the if syntax is written like this:

if [condition] [execution] [else] [execution 2]
if [condition] [execution] [elif] [condition 2] [execution 2] …

However, in the case of Pie Menu Editor, even if you first write if in the command field as shown in the image, it becomes “Invalid syntax” and you are confused because you do not know the cause of the malfunction.

2019-12-02 14_37_22-Blender

For example, the syntax for the QuickOrigin Add-On that I often use is written like this:
How can I write the following execution processes in order in the command field?

    if bpy.context.object.mode == "EDIT":
        saved_location = bpy.context.scene.cursor.location.copy()
        bpy.ops.view3d.snap_cursor_to_selected()
        bpy.ops.object.mode_set(mode="OBJECT")
        bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
        bpy.context.scene.cursor.location = saved_location
        bpy.ops.object.mode_set(mode="EDIT")
        
    if bpy.context.object.mode == "OBJECT":
        bpy.ops.object.origin_set(type='ORIGIN_CURSOR')

🔗 View on Blender Artists