Run Custom Python Scripts Directly from Shelves

Sharing Python scripts created through Mari's powerful Python API encourages collaboration between artists and storing these scripts in shelves means you can execute a script by double-clicking it in the shelf. For example, a colleague may have created a Python script that automatically imports certain textures for a show you're working on. By importing this script to a Shelf Item, you no longer need to install this script manually. Instead, simply run the script each time you start on a new asset for the show - keeping the look of the show consistent and reducing project setup time.

You can edit scripts directly in the Shelf using the Edit Script widget or drag and drop the script from the shelf to the Python Console. You can also change the default shelf script thumbnail to describe its function at a glance.

Adding and Removing Python Scripts in Shelves

Python scripts are added to shelves by importing .py files from disk or by dragging code from the Python Console in Mari.

Note:  You can't edit the shelves that ship with Mari, so you'll have to create a custom shelf to hold your Python Scripts. See Creating a Custom Shelf for more information.

To create shelf items by importing Python scripts from disk:

  1. Open the Shelf palette by clicking Shelf in the right-hand toolbar.
  2. Select the shelf you want to use for script storage.
  3. Click the Import Items button and then browse to the location of your script.
  4. Select the script and click Open to add the script to your selected shelf.

To create shelf items from the Python Console:

  1. Enter the Python code you want to save as a shelf item manually or import a script from disk into the console.
  2. Select the entire script in the console editor and drag and drop the text into the Shelf palette in the shelf you want to use.
  3. The new Python shelf item takes its name from the Python Console default, Script1, or from the Python file you imported.

To delete a shelf item:

  1. Select the shelf you're using for script storage.
  2. Select the script or scripts you want to delete.
  3. Press Backspace on your keyboard or right-click a selected script and click Delete Items.

Editing Python Scripts in Shelves

Mari's Shelf palette includes an editing widget that saves you time if you want to edit a Python script in a shelf. You can drag and drop a script into the Python Console, but for small changes, using the editor means you don't have to open another palette to make an edit.

To edit a script in a shelf:

  1. Select the shelf you're using for script storage.
  2. Select the script you want to edit.
  3. Right-click the selected script and click Edit Script.
  4. The Edit Script widget is displayed.

  5. Edit the script as required and then click Save to update the script in the shelf.
  6. Tip:  You can change the default shelf script thumbnail to describe a scripts function at a glance. Right-click a script in the shelf and select Edit Thumbnail to browse to an image file on disk.

Executing a Python Script from a Shelf

Once you've imported a shelf script or created your own, you can run a script by double-clicking it in the shelf or by dragging the script to the Python Console and running it from there.

To run a script from the shelf:

  1. Select the shelf you're using for script storage.
  2. Double-click the script you want to run.
  3. Mari executes the script automatically, you don't need to do anything else.

To run a script from the Python Console:

  1. Select the shelf you're using for script storage.
  2. Drag the script into the Python Console.
  3. Click the Evaluate button or press Ctrl+Enter to execute the script.