Skip to content

Locator Strategy

Marcus Ottosson edited this page Apr 28, 2015 · 3 revisions

A Selector strategy used to identify an asset via it's absolute path.




Goals

Paths are at the base of any organisation and odds are you already have access to a well-defined directory schema with plentiful of data available for you to make decisions about assets during development.




Implementation

Mining for data is typically implemented as either string operations or regular expressions.

>>> import os
>>> import re
>>> path = "/server/MyProject/model/Peter.mb"
>>> family = os.path.basename(os.path.split(path)[0])
>>> print family
'model'

Example

"""Locator Strategy

The absolute path of a file or folder is used
to determine a type of asset.

"""

import os
import pyblish.api as pyblish


class SelectInstances(pyblish.Selector):
    hosts = ["*"]

    def process_context(self, context):
        # E.g. /server/MyProject/model/Peter.mb
        current_file = context.data("currentFile")
        current_directory = os.path.dirname(current_file)

        # Name is "Peter", family is `model`
        name = os.path.basename(current_file)
        family = os.path.basename(current_directory)

        instance = context.create_instance(name)
        instance.set_data("family", family)
Clone this wiki locally