Page MenuHome

Tutorial addon sample (Move X by One) doesn't get executed and/or added as available voice when installed.
Needs Triage, NormalPublic

Description

System Information
Operating system: Mac OS 10.15.7 (19H114) Catalina
Graphics card: ATI Radeon Vega

Blender Version
Broken: (example: 2.92, 02948a2cab44, master)
Worked: dunno

Running the script inside the Scripting editor doesn't do anything (

).

I tried also to install as an addon (Preferences->Addons->Install) it adds the voice to add-ons and let to enable it but it

won't add the option in the editor, so searching as reported in the tutorial doesn't work.

There is no syntax error reported (tried also running form terminal the app to check if there were some error reported).

Code copied from https://docs.blender.org/manual/en/latest/advanced/scripting/addon_tutorial.html:

bl_info = {
    "name": "Move X Axis",
    "blender": (2, 80, 0),
    "category": "Object"
    }

import bpy
from bpy import context

class ObjectMoveX(bpy.types.Operator):
    """My Object Moving Script"""      # Use this as a tooltip for menu items and buttons.
    bl_idname = "object.move_x"        # Unique identifier for buttons and menu items to reference.
    bl_label = "Move X by One"         # Display name in the interface.
    bl_options = {'REGISTER', 'UNDO'}  # Enable undo for the operator.

    def execute(self, context):        # execute() is called when running the operator.

        # The original script
        scene = bpy.context.scene
        for obj in scene.objects:
            obj.location.x += 1.0

        return {'FINISHED'}            # Lets Blender know the operator finished successfully.

def register():
    bpy.utils.register_class(ObjectMoveX)

def unregister():
    bpy.utils.unregister_class(ObjectMoveX)

if __name__ == "__main__":
    register()

Event Timeline

Running it from the text editor will only register it, you have to call the operator to move the object as explained in the tutorial:

However running the script won’t move any objects. For this, you need to execute the newly registered operator.
Open the Operator Search menu and type in “Move X by One” (the bl_label), then Return.
The objects should move as before.

The steps to run the add-on from the text editor are:

  1. Create a new text data-block by pressing the New button in the text editor
  2. Copy and paste the script
  3. Run the script. Since executing the script like this will have __name__ set to "__main__" this will result in register() being called. The function registers the operator, but doesn't execute it.
  4. Since the operator is not part of any menu, Blender won't show it anywhere and it also won't appear in the regular search. Open the preferences Edit > Preferences > Interface and enable the Developer Extras and Python Tooltips. Once Developer Extras is enabled the search will also show operators that aren't in menus.
  5. Use Edit > Operator Search or press F3 and search for "Move X by One". Select the entry and press enter or double click on it. The operator will be executed.

Alternatively you can also run the operator without enabling the Developer Extras by using the Python console. Typing bpy.ops.object.move_x() and pressing enter will execute the operator.

@Aaron Carlisle (Blendify) Since operators that aren't in menus are omitted from the search by default, the tutorial should explain that the Developer Extras have to be enabled or showcase it by calling the operator from the console.

@Aaron Carlisle (Blendify) Since operators that aren't in menus are omitted from the search by default, the tutorial should explain that the Developer Extras have to be enabled or showcase it by calling the operator from the console.

Yes I found to enable python in the tutorial and not also the developer extras. Thanks, after enabling it appeared and I managed to use and debug properly.