From 246a3cff52f0f4d6bd69aff4dafc44260f01d7de Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Jul 2021 18:05:17 +0200 Subject: [PATCH 1/3] create the project in avalon if does not exist yet --- .../action_prepare_project.py | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py index 5298c06371..e9b0b2a58a 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py +++ b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py @@ -1,6 +1,8 @@ import json +from avalon.api import AvalonMongoDB from openpype.api import ProjectSettings +from openpype.lib import create_project from openpype.modules.ftrack.lib import ( BaseAction, @@ -48,13 +50,22 @@ class PrepareProjectLocal(BaseAction): project_entity = entities[0] project_name = project_entity["full_name"] - try: - project_settings = ProjectSettings(project_name) - except ValueError: - return { - "message": "Project is not synchronized yet", - "success": False - } + # Try to find project document + dbcon = AvalonMongoDB() + dbcon.install() + dbcon.Session["AVALON_PROJECT"] = project_name + project_doc = dbcon.find_one({ + "type": "project" + }) + # Create project if is not available + # - creation is required to be able set project anatomy and attributes + if not project_doc: + project_code = project_entity["name"] + create_project(project_name, project_code, dbcon=dbcon) + + dbcon.uninstall() + + project_settings = ProjectSettings(project_name) project_anatom_settings = project_settings["project_anatomy"] root_items = self.prepare_root_items(project_anatom_settings) From 0e38083a014446acc56e0043d67e0f25914d96e9 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Jul 2021 18:05:27 +0200 Subject: [PATCH 2/3] add basic order of attributes --- .../action_prepare_project.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py index e9b0b2a58a..4bcd058ca8 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py +++ b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py @@ -26,6 +26,21 @@ class PrepareProjectLocal(BaseAction): # Key to store info about trigerring create folder structure item_splitter = {"type": "label", "value": "---"} + _keys_order = ( + "fps", + "frameStart", + "frameEnd", + "handleStart", + "handleEnd", + "clipIn", + "clipOut", + "resolutionHeight", + "resolutionWidth", + "pixelAspect", + "applications", + "tools_env", + "library_project", + ) def discover(self, session, entities, event): """Show only on project.""" @@ -211,7 +226,18 @@ class PrepareProjectLocal(BaseAction): str([key for key in attributes_to_set]) )) - for key, in_data in attributes_to_set.items(): + attribute_keys = set(attributes_to_set.keys()) + keys_order = [] + for key in self._keys_order: + if key in attribute_keys: + keys_order.append(key) + + attribute_keys = attribute_keys - set(keys_order) + for key in sorted(attribute_keys): + keys_order.append(key) + + for key in keys_order: + in_data = attributes_to_set[key] attr = in_data["object"] # initial item definition From 1f4c644fc0aab6d64d34762c799bfad34a13b3b4 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Jul 2021 18:28:56 +0200 Subject: [PATCH 3/3] create project when values are confirmed, not before --- .../action_prepare_project.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py index 4bcd058ca8..5c40ec0d30 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py +++ b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py @@ -65,21 +65,6 @@ class PrepareProjectLocal(BaseAction): project_entity = entities[0] project_name = project_entity["full_name"] - # Try to find project document - dbcon = AvalonMongoDB() - dbcon.install() - dbcon.Session["AVALON_PROJECT"] = project_name - project_doc = dbcon.find_one({ - "type": "project" - }) - # Create project if is not available - # - creation is required to be able set project anatomy and attributes - if not project_doc: - project_code = project_entity["name"] - create_project(project_name, project_code, dbcon=dbcon) - - dbcon.uninstall() - project_settings = ProjectSettings(project_name) project_anatom_settings = project_settings["project_anatomy"] @@ -375,7 +360,27 @@ class PrepareProjectLocal(BaseAction): self.log.debug("Setting Custom Attribute values") - project_name = entities[0]["full_name"] + project_entity = entities[0] + project_name = project_entity["full_name"] + + # Try to find project document + dbcon = AvalonMongoDB() + dbcon.install() + dbcon.Session["AVALON_PROJECT"] = project_name + project_doc = dbcon.find_one({ + "type": "project" + }) + # Create project if is not available + # - creation is required to be able set project anatomy and attributes + if not project_doc: + project_code = project_entity["name"] + self.log.info("Creating project \"{} [{}]\"".format( + project_name, project_code + )) + create_project(project_name, project_code, dbcon=dbcon) + + dbcon.uninstall() + project_settings = ProjectSettings(project_name) project_anatomy_settings = project_settings["project_anatomy"] project_anatomy_settings["roots"] = root_data