Publish to AYON using command line

Hello,

Some time ago, I was searching for a method to automatically publish a large number of files. Here’s what I discovered.

Use ayon.exe (Windows) or ayon (Linux) as the executable file. If you are utilizing the Launcher from the source code, run it using ayon-launcher\tools\manage.ps1 (Windows) or ayon-launcher/tools/make.sh (Linux).
In my example, I will use the Launcher from the source code on Linux.

Method One

Let’s use standard Python with the default families. To correctly specify the family, check its name in the settings of the addon Traypublisher > Simple Create Plugins and add it at the beginning of settings_. For instance, if I’m publishing an image using the image family, I specify the identifier as settings_image.

start_publish1.sh

#!/bin/bash
export USE_AYON_SERVER=1
export AYON_HEADLESS_MODE=1
export AYON_SERVER_URL=http://localhost:5000
export AYON_API_KEY=veryinsecurapikey
export AVALON_APP_NAME=traypublisher
export AVALON_PROJECT=TestProject
export AVALON_ASSET=fox
export AVALON_TASK=concept

ayon-launcher/tools/make.sh run publish_example.py

publish_example.py

from pathlib import Path
import pyblish
from openpype.lib import FileDefItem
from openpype.hosts.traypublisher.api import TrayPublisherHost
from openpype.pipeline.create import CreateContext
from openpype.pipeline import install_host

host = TrayPublisherHost()
install_host(host)

create_context = CreateContext(host, headless=True)
pyblish_context = pyblish.api.Context()
pyblish_context.data["create_context"] = create_context
pyblish_plugins = create_context.publish_plugins
# print('All creators:', create_context.creators.keys())
files_to_publish = [Path('~/fox-concept.png').expanduser().as_posix()]
create_context.create(
    creator_identifier='settings_image',
    variant='main',
    pre_create_data={
        "representation_files": [item.to_dict() for item in FileDefItem.from_paths(files_to_publish, allow_sequences=False)],
        "reviewable": {}
    }
)


for result in pyblish.util.publish_iter(context=pyblish_context, plugins=pyblish_plugins):
    for record in result["records"]:
        logging.info("{}: {}".format(result["plugin"].label, record.msg))
    if result["error"]:
        error_message = "Failed {plugin.__name__}: {error} -- {error.traceback}".format(**result)
        logging.error(error_message)

Method Two

Publishing from DCC. For this approach, we will utilize a specialized add-on launch_script developed by Roy Nieterau (@bigroynl).
Follow the add-on installation instructions outlined in the documentation. Once installed, a new module launch_scripts will become available.

Additionally, we will need a prepared working file. As an example, I will use a working file from Houdini. You can use any other registered application. This file includes an output node for publishing geometry.

start_publish2.sh

#!/bin/bash
export USE_AYON_SERVER=1
export AYON_HEADLESS_MODE=1
export AYON_SERVER_URL=http://localhost:5000
export AYON_API_KEY=veryinsecurapikey

workfile="~/fox_modeling_v001.hip"

ayon-launcher/tools/make.sh run module launch_scripts publish -project TestProject -asset fox -task modeling -path "${workfile}" -app houdini/20.0.547

I thank the AYON developers for their responsiveness and help in finding solutions.

4 Likes