Skip to content

create_workfile

Creator plugin for creating workfiles.

CreateWorkfile

Bases: AutoCreator

Workfile auto-creator.

Source code in client/ayon_resolve/plugins/create/create_workfile.py
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class CreateWorkfile(AutoCreator):
    """Workfile auto-creator."""
    settings_category = "resolve"

    identifier = "io.ayon.creators.resolve.workfile"
    label = "Workfile"
    product_type = "workfile"

    default_variant = "Main"

    def _dumps_data_as_project_setting(self, data):
        """Store workfile as project setting.

        Args:
            data (dict): The data to store on the timeline.
        """
        # Store info as project setting data.
        # Use this hack instead: 
        # https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=
        # 189685&hilit=python+database#p991541
        note = json.dumps(data)
        proj = lib.get_current_project()
        proj.SetSetting("colorVersion10Name", note)

    def _loads_data_from_project_setting(self):
        """Retrieve workfile data from project setting."""
        proj = lib.get_current_project()
        setting_content = proj.GetSetting("colorVersion10Name")

        if setting_content:
            return json.loads(setting_content)

        return None

    def _create_new_instance(self):
        """Create new instance."""
        variant = self.default_variant
        project_name = self.create_context.get_current_project_name()
        host_name = self.create_context.host_name
        folder_entity = self.create_context.get_current_folder_entity()
        task_entity = self.create_context.get_current_task_entity()
        folder_path = folder_entity["path"]
        task_name = task_entity["name"]
        product_name = self.get_product_name(
            project_name,
            folder_entity,
            task_entity,
            self.default_variant,
            host_name,
        )
        data = {
            "folderPath": folder_path,
            "task": task_name,
            "variant": variant,
            "productName": product_name,
        }
        data.update(
            self.get_dynamic_data(
                variant,
                task_name,
                folder_entity,
                project_name,
                host_name,
                False,
            )
        )

        return data

    def collect_instances(self):
        """Collect from timeline marker or create a new one."""
        data = self._loads_data_from_project_setting()
        if not data:
            return

        current_instance = CreatedInstance(
            self.product_type, data["productName"], data, self)
        self._add_instance_to_context(current_instance)

    def create(self, options=None):
        """Auto-create an instance by default."""
        data = self._loads_data_from_project_setting()
        if data:
            return

        self.log.info("Auto-creating workfile instance...")
        data = self._create_new_instance()
        current_instance = CreatedInstance(
            self.product_type, data["productName"], data, self)
        self._add_instance_to_context(current_instance)

    def update_instances(self, update_list):
        """Store changes in project metadata so they can be recollected.

        Args:
            update_list(List[UpdateData]): Gets list of tuples. Each item
                contain changed instance and its changes.
        """
        for created_inst, _ in update_list:
            data = created_inst.data_to_store()
            self._dumps_data_as_project_setting(data)

collect_instances()

Collect from timeline marker or create a new one.

Source code in client/ayon_resolve/plugins/create/create_workfile.py
82
83
84
85
86
87
88
89
90
def collect_instances(self):
    """Collect from timeline marker or create a new one."""
    data = self._loads_data_from_project_setting()
    if not data:
        return

    current_instance = CreatedInstance(
        self.product_type, data["productName"], data, self)
    self._add_instance_to_context(current_instance)

create(options=None)

Auto-create an instance by default.

Source code in client/ayon_resolve/plugins/create/create_workfile.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def create(self, options=None):
    """Auto-create an instance by default."""
    data = self._loads_data_from_project_setting()
    if data:
        return

    self.log.info("Auto-creating workfile instance...")
    data = self._create_new_instance()
    current_instance = CreatedInstance(
        self.product_type, data["productName"], data, self)
    self._add_instance_to_context(current_instance)

update_instances(update_list)

Store changes in project metadata so they can be recollected.

Parameters:

Name Type Description Default
update_list(List[UpdateData])

Gets list of tuples. Each item contain changed instance and its changes.

required
Source code in client/ayon_resolve/plugins/create/create_workfile.py
104
105
106
107
108
109
110
111
112
113
def update_instances(self, update_list):
    """Store changes in project metadata so they can be recollected.

    Args:
        update_list(List[UpdateData]): Gets list of tuples. Each item
            contain changed instance and its changes.
    """
    for created_inst, _ in update_list:
        data = created_inst.data_to_store()
        self._dumps_data_as_project_setting(data)