Useful AYON utility functions

Hello,

As I take a deeper look at AYON code base, I found out that there are many useful utility functions such as

get_folder_by_path and get_task_by_name from ayon_api

However, there might be situation where we need a bit of customization that would help with plugins development. For example, I used the following code to find the episode of a given task:

def getEpisodeFolderName(ayon_project_name, ayon_folder_path):
    """A recursive function to get the episode name from the folder path.

    Each recursive call will either return the episode name
    or run the function again with the parent folder path.

    Args:
        ayon_project_name (str): the name of the project.
        ayon_folder_path (str): the relative ayon folder path.

    Returns:
        str: the name of the episode folder
    """

    folder = get_folder_by_path(ayon_project_name, ayon_folder_path)

    folder_type = folder.get("folderType", None)
    if folder_type.lower() == "episode":
        return folder.get("name", None)
    
    if ayon_folder_path == "":
        return None
    
    parent_folder = os.path.dirname(ayon_folder_path)
    return getEpisodeFolderName(ayon_project_name, parent_folder)

As there will be many utility functions that would be extremely helpful during development, it would be great if we can have a place where we share quick snippets like this to make our lives easier.

Thus, I’m creating this post as an initial place for AYON enthusiasts and developers to share their utility snippets.

Resource:
AYON Python API Doc: Welcome to AYON Python API documentation! — ayon-python-api 1.0.9 documentation

2 Likes

Hello,
Thanks for your initiative.
Currently, we don’t have a Hub for community snippets.


At present there are scattered snippets around the forums and there are also some on GH, for instance:

1 Like