user: Show practical ways to work with Your First Add-on in a Blender add-on or script – include code.

assistant: The simplest possible add-on above is useful as an example but not much else.
This next add-on is simple but shows how to integrate a script into Blender using an `Operator`
which is the typical way to define a tool accessed from menus, buttons and keyboard shortcuts.

For the first example we will make a script that simply moves all objects in a scene.

### Write the Script

Add the following script to the Text editor in Blender:

```
import bpy

scene = bpy.context.scene
for obj in scene.objects:
    obj.location.x += 1.0
```

Click the [Run Script button](../../editors/text_editor.xhtml#editors-text-run-script),
all objects in the active scene are moved by 1.0 unit.

### Write the Add-on (Simple)

This add-on takes the body of the script above, and adds it to an operator’s `execute()` function.

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

import bpy

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 = context.scene
        for obj in scene.objects:
            obj.location.x += 1.0

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

def menu_func(self, context):
    self.layout.operator(ObjectMoveX.bl_idname)

def register():
    bpy.utils.register_class(ObjectMoveX)
    bpy.types.VIEW3D_MT_object.append(menu_func)  # Adds the new operator to an existing menu.

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

# This allows you to run the script directly from Blender's Text editor
# to test the add-on without having to install it.
if __name__ == "__main__":
    register()
```

To test the script, you can copy and paste it into Blender’s Text editor and run it.
This will execute the script directly and call register immediately.

However running the script won’t move any objects. For this, you need to execute the newly registered operator.

[image reference removed]

Operator Search menu.

Open the [Operator Search](../../interface/operators.xhtml#bpy-ops-wm-search-operator) menu
and type in “Move X by One” (the `bl_label`), then `Return`.

The objects should move as before.

*Keep this add-on open in Blender for the next step - Installing.*

### Install the Add-on

Once you have your add-on within in Blender’s Text editor,
you will want to be able to install it so it can be enabled in the Preferences to load on startup.

Even though the add-on above is a test, let’s go through the steps anyway so you know how to do it for later.

To install the Blender text as an add-on, you will first have to save it on drive. Take care to obey the naming
restrictions that apply to Python modules and end with a `.py` extension.

Once the file is on drive, you can install it as you would for an add-on downloaded online.

Open the Preferences ‣ Add-ons ‣ Install… and select the file.

Now the add-on will be listed and you can enable it by pressing the checkbox,
if you want it to be enabled on restart, press *Save as Default*. The operator
can be run in the same way as described in the [previous section](#advanced-scripting-write-the-add-on-simple).

When the add-on is enabled, Blender executes the code and runs the `register()` function.
When the add-on is disabled, Blender runs the `unregister()` function.