From e50d0fe639ba48efac137b5de9efa4f0172509e8 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 12 Jun 2020 15:17:39 +0300 Subject: [PATCH 1/5] feat(ppro): adding support for different root per task into anatomy --- pype/hooks/premiere/prelaunch.py | 83 +++++++++++++++++++++++++++++++- pype/hosts/premiere/__init__.py | 1 - 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/pype/hooks/premiere/prelaunch.py b/pype/hooks/premiere/prelaunch.py index c2cb73645a..6f1430d9ba 100644 --- a/pype/hooks/premiere/prelaunch.py +++ b/pype/hooks/premiere/prelaunch.py @@ -1,7 +1,8 @@ import os import traceback +from avalon import api, io, lib from pype.lib import PypeHook -from pype.api import Logger +from pype.api import Logger, Anatomy from pype.hosts.premiere import lib as prlib @@ -26,6 +27,24 @@ class PremierePrelaunch(PypeHook): if not env: env = os.environ + # initialize + self._S = api.Session + + # get context variables + self._S["AVALON_PROJECT"] = env["AVALON_PROJECT"] + self._S["AVALON_ASSET"] = env["AVALON_ASSET"] + task = self._S["AVALON_TASK"] = env["AVALON_TASK"] + + # get workfile path + anatomy_filled = self.get_anatomy_filled() + workfile_search_key = f"work[{task.lower()}]" + workfile_key = anatomy_filled.get(workfile_search_key, "work") + workdir = env["AVALON_WORKDIR"] = workfile_key["folder"] + + # create workdir if doesn't exist + os.makedirs(workdir, exist_ok=True) + self.log.info(f"Work dir is: `{workdir}`") + try: __import__("pype.hosts.premiere") __import__("pyblish") @@ -36,7 +55,67 @@ class PremierePrelaunch(PypeHook): else: # Premiere Setup integration - # importlib.reload(prlib) prlib.setup(env) return True + + def get_anatomy_filled(self): + root_path = api.registered_root() + project_name = self._S["AVALON_PROJECT"] + asset_name = self._S["AVALON_ASSET"] + + io.install() + project_entity = io.find_one({ + "type": "project", + "name": project_name + }) + assert project_entity, ( + "Project '{0}' was not found." + ).format(project_name) + self.log.debug("Collected Project \"{}\"".format(project_entity)) + + asset_entity = io.find_one({ + "type": "asset", + "name": asset_name, + "parent": project_entity["_id"] + }) + assert asset_entity, ( + "No asset found by the name '{0}' in project '{1}'" + ).format(asset_name, project_name) + + project_name = project_entity["name"] + + self.log.info( + "Anatomy object collected for project \"{}\".".format(project_name) + ) + + hierarchy_items = asset_entity["data"]["parents"] + hierarchy = "" + if hierarchy_items: + hierarchy = os.path.join(*hierarchy_items) + + template_data = { + "root": root_path, + "project": { + "name": project_name, + "code": project_entity["data"].get("code") + }, + "asset": asset_entity["name"], + "hierarchy": hierarchy.replace("\\", "/"), + "task": self._S["AVALON_TASK"], + "ext": "ppro", + "version": 1, + "username": os.getenv("PYPE_USERNAME", "").strip() + } + + avalon_app_name = os.environ.get("AVALON_APP_NAME") + if avalon_app_name: + application_def = lib.get_application(avalon_app_name) + app_dir = application_def.get("application_dir") + if app_dir: + template_data["app"] = app_dir + + anatomy = Anatomy(project_name) + anatomy_filled = anatomy.format_all(template_data).get_solved() + + return anatomy_filled diff --git a/pype/hosts/premiere/__init__.py b/pype/hosts/premiere/__init__.py index ddf334c610..acba84496b 100644 --- a/pype/hosts/premiere/__init__.py +++ b/pype/hosts/premiere/__init__.py @@ -1,4 +1,3 @@ -import os from avalon import api as avalon from pyblish import api as pyblish from pype.api import Logger From 7d5328683b322501024c7265a6bf086509b3b579 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 12 Jun 2020 15:27:08 +0300 Subject: [PATCH 2/5] docs(premiere): adding example --- pype/hooks/premiere/prelaunch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pype/hooks/premiere/prelaunch.py b/pype/hooks/premiere/prelaunch.py index 6f1430d9ba..21b438c2ad 100644 --- a/pype/hooks/premiere/prelaunch.py +++ b/pype/hooks/premiere/prelaunch.py @@ -37,6 +37,9 @@ class PremierePrelaunch(PypeHook): # get workfile path anatomy_filled = self.get_anatomy_filled() + + # if anatomy template should have different root for particular task + # just add for example > work[conforming]: workfile_search_key = f"work[{task.lower()}]" workfile_key = anatomy_filled.get(workfile_search_key, "work") workdir = env["AVALON_WORKDIR"] = workfile_key["folder"] From 0b6362887e050b3d509a1abf5b8c1ed92f602faf Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 12 Jun 2020 16:07:13 +0300 Subject: [PATCH 3/5] feat(ppro): name convention for shots --- pype/hooks/premiere/prelaunch.py | 5 +++++ .../extensions/com.pype/jsx/batchRenamer.jsx | 17 +++-------------- pype/hosts/premiere/ppro/index.html | 12 +++++++----- pype/hosts/premiere/ppro/js/pype.js | 1 + 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/pype/hooks/premiere/prelaunch.py b/pype/hooks/premiere/prelaunch.py index 21b438c2ad..43631ec2fa 100644 --- a/pype/hooks/premiere/prelaunch.py +++ b/pype/hooks/premiere/prelaunch.py @@ -13,6 +13,7 @@ class PremierePrelaunch(PypeHook): path to the project by environment variable to Premiere launcher shell script. """ + project_code = None def __init__(self, logger=None): if not logger: @@ -48,6 +49,9 @@ class PremierePrelaunch(PypeHook): os.makedirs(workdir, exist_ok=True) self.log.info(f"Work dir is: `{workdir}`") + # adding project code to env + env["AVALON_PROJECT_CODE"] = self.project_code + try: __import__("pype.hosts.premiere") __import__("pyblish") @@ -87,6 +91,7 @@ class PremierePrelaunch(PypeHook): ).format(asset_name, project_name) project_name = project_entity["name"] + self.project_code = project_entity["data"]["code"] self.log.info( "Anatomy object collected for project \"{}\".".format(project_name) diff --git a/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx b/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx index 483244f3fd..b1427a7de7 100644 --- a/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx +++ b/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx @@ -61,15 +61,12 @@ var BatchRenamer = { var seq = app.project.activeSequence; var metadata = $.pype.getSequencePypeMetadata(seq, true); - var startCount = 10; - var stepCount = 10; var padding = 3; var newItems = {}; + var projectCode = data.projectCode var episode = data.ep; var episodeSuf = data.epSuffix; var shotPref = 'sh'; - var count = 0; - var seqCheck = ''; for (var c = 0; c < selected.length; c++) { // fill in hierarchy if set @@ -79,15 +76,7 @@ var BatchRenamer = { var sequenceName = name.slice(0, 5); var shotNum = Number(name.slice((name.length - 3), name.length)); - // if (sequenceName !== seqCheck) { - // seqCheck = sequenceName; - // count = 0; - // }; - // - // var seqCount = (count * stepCount) + startCount; - // count += 1; - - var newName = episode + sequenceName + shotPref + (shotNum).pad(padding); + var newName = projectCode + episode + sequenceName + shotPref + (shotNum).pad(padding); $.pype.log(newName); selected[c].clip.name = newName; @@ -113,4 +102,4 @@ var BatchRenamer = { $.pype.setSequencePypeMetadata(seq, metadata); return JSON.stringify(metadata); } -} \ No newline at end of file +} diff --git a/pype/hosts/premiere/ppro/index.html b/pype/hosts/premiere/ppro/index.html index ba2e2cdad7..e17399c22c 100644 --- a/pype/hosts/premiere/ppro/index.html +++ b/pype/hosts/premiere/ppro/index.html @@ -39,14 +39,16 @@ var ENV;
- Rename targeted text layers
- converts sc010sh020 -
to lbb201sc010sh020
and creates ftrack metadata
+ + Rename targeted text layers
+ converts `sc010sh020`
+ to `proj01ep01sc01sh01`
+ and creates ftrack metadata
- +
- +
diff --git a/pype/hosts/premiere/ppro/js/pype.js b/pype/hosts/premiere/ppro/js/pype.js index db1cadeb3b..b98cc8dff1 100644 --- a/pype/hosts/premiere/ppro/js/pype.js +++ b/pype/hosts/premiere/ppro/js/pype.js @@ -65,6 +65,7 @@ class Pype { let data = {}; data.ep = $('input[name=episode]', $renameId).val(); data.epSuffix = $('input[name=ep_suffix]', $renameId).val(); + data.projectCode = this.env.AVALON_PROJECT_CODE; if (!data.ep) { this.csi.evalScript('$.pype.alert_message("' + 'Need to fill episode code' + '")'); From 6b96a86b36fe823da7e7e853ef7c792108cb1465 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 12 Jun 2020 18:46:44 +0300 Subject: [PATCH 4/5] feat(ppro): adding support for different root per task into anatomy docs(premiere): adding example feat(ppro): name convention for shots --- pype/hooks/premiere/prelaunch.py | 91 ++++++++++++++++++- pype/hosts/premiere/__init__.py | 1 - .../extensions/com.pype/jsx/batchRenamer.jsx | 17 +--- pype/hosts/premiere/ppro/index.html | 12 ++- pype/hosts/premiere/ppro/js/pype.js | 1 + 5 files changed, 100 insertions(+), 22 deletions(-) diff --git a/pype/hooks/premiere/prelaunch.py b/pype/hooks/premiere/prelaunch.py index c2cb73645a..43631ec2fa 100644 --- a/pype/hooks/premiere/prelaunch.py +++ b/pype/hooks/premiere/prelaunch.py @@ -1,7 +1,8 @@ import os import traceback +from avalon import api, io, lib from pype.lib import PypeHook -from pype.api import Logger +from pype.api import Logger, Anatomy from pype.hosts.premiere import lib as prlib @@ -12,6 +13,7 @@ class PremierePrelaunch(PypeHook): path to the project by environment variable to Premiere launcher shell script. """ + project_code = None def __init__(self, logger=None): if not logger: @@ -26,6 +28,30 @@ class PremierePrelaunch(PypeHook): if not env: env = os.environ + # initialize + self._S = api.Session + + # get context variables + self._S["AVALON_PROJECT"] = env["AVALON_PROJECT"] + self._S["AVALON_ASSET"] = env["AVALON_ASSET"] + task = self._S["AVALON_TASK"] = env["AVALON_TASK"] + + # get workfile path + anatomy_filled = self.get_anatomy_filled() + + # if anatomy template should have different root for particular task + # just add for example > work[conforming]: + workfile_search_key = f"work[{task.lower()}]" + workfile_key = anatomy_filled.get(workfile_search_key, "work") + workdir = env["AVALON_WORKDIR"] = workfile_key["folder"] + + # create workdir if doesn't exist + os.makedirs(workdir, exist_ok=True) + self.log.info(f"Work dir is: `{workdir}`") + + # adding project code to env + env["AVALON_PROJECT_CODE"] = self.project_code + try: __import__("pype.hosts.premiere") __import__("pyblish") @@ -36,7 +62,68 @@ class PremierePrelaunch(PypeHook): else: # Premiere Setup integration - # importlib.reload(prlib) prlib.setup(env) return True + + def get_anatomy_filled(self): + root_path = api.registered_root() + project_name = self._S["AVALON_PROJECT"] + asset_name = self._S["AVALON_ASSET"] + + io.install() + project_entity = io.find_one({ + "type": "project", + "name": project_name + }) + assert project_entity, ( + "Project '{0}' was not found." + ).format(project_name) + self.log.debug("Collected Project \"{}\"".format(project_entity)) + + asset_entity = io.find_one({ + "type": "asset", + "name": asset_name, + "parent": project_entity["_id"] + }) + assert asset_entity, ( + "No asset found by the name '{0}' in project '{1}'" + ).format(asset_name, project_name) + + project_name = project_entity["name"] + self.project_code = project_entity["data"]["code"] + + self.log.info( + "Anatomy object collected for project \"{}\".".format(project_name) + ) + + hierarchy_items = asset_entity["data"]["parents"] + hierarchy = "" + if hierarchy_items: + hierarchy = os.path.join(*hierarchy_items) + + template_data = { + "root": root_path, + "project": { + "name": project_name, + "code": project_entity["data"].get("code") + }, + "asset": asset_entity["name"], + "hierarchy": hierarchy.replace("\\", "/"), + "task": self._S["AVALON_TASK"], + "ext": "ppro", + "version": 1, + "username": os.getenv("PYPE_USERNAME", "").strip() + } + + avalon_app_name = os.environ.get("AVALON_APP_NAME") + if avalon_app_name: + application_def = lib.get_application(avalon_app_name) + app_dir = application_def.get("application_dir") + if app_dir: + template_data["app"] = app_dir + + anatomy = Anatomy(project_name) + anatomy_filled = anatomy.format_all(template_data).get_solved() + + return anatomy_filled diff --git a/pype/hosts/premiere/__init__.py b/pype/hosts/premiere/__init__.py index ddf334c610..acba84496b 100644 --- a/pype/hosts/premiere/__init__.py +++ b/pype/hosts/premiere/__init__.py @@ -1,4 +1,3 @@ -import os from avalon import api as avalon from pyblish import api as pyblish from pype.api import Logger diff --git a/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx b/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx index 483244f3fd..b1427a7de7 100644 --- a/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx +++ b/pype/hosts/premiere/extensions/com.pype/jsx/batchRenamer.jsx @@ -61,15 +61,12 @@ var BatchRenamer = { var seq = app.project.activeSequence; var metadata = $.pype.getSequencePypeMetadata(seq, true); - var startCount = 10; - var stepCount = 10; var padding = 3; var newItems = {}; + var projectCode = data.projectCode var episode = data.ep; var episodeSuf = data.epSuffix; var shotPref = 'sh'; - var count = 0; - var seqCheck = ''; for (var c = 0; c < selected.length; c++) { // fill in hierarchy if set @@ -79,15 +76,7 @@ var BatchRenamer = { var sequenceName = name.slice(0, 5); var shotNum = Number(name.slice((name.length - 3), name.length)); - // if (sequenceName !== seqCheck) { - // seqCheck = sequenceName; - // count = 0; - // }; - // - // var seqCount = (count * stepCount) + startCount; - // count += 1; - - var newName = episode + sequenceName + shotPref + (shotNum).pad(padding); + var newName = projectCode + episode + sequenceName + shotPref + (shotNum).pad(padding); $.pype.log(newName); selected[c].clip.name = newName; @@ -113,4 +102,4 @@ var BatchRenamer = { $.pype.setSequencePypeMetadata(seq, metadata); return JSON.stringify(metadata); } -} \ No newline at end of file +} diff --git a/pype/hosts/premiere/ppro/index.html b/pype/hosts/premiere/ppro/index.html index ba2e2cdad7..e17399c22c 100644 --- a/pype/hosts/premiere/ppro/index.html +++ b/pype/hosts/premiere/ppro/index.html @@ -39,14 +39,16 @@ var ENV;
- Rename targeted text layers
- converts sc010sh020 -
to lbb201sc010sh020
and creates ftrack metadata
+ + Rename targeted text layers
+ converts `sc010sh020`
+ to `proj01ep01sc01sh01`
+ and creates ftrack metadata
- +
- +
diff --git a/pype/hosts/premiere/ppro/js/pype.js b/pype/hosts/premiere/ppro/js/pype.js index db1cadeb3b..b98cc8dff1 100644 --- a/pype/hosts/premiere/ppro/js/pype.js +++ b/pype/hosts/premiere/ppro/js/pype.js @@ -65,6 +65,7 @@ class Pype { let data = {}; data.ep = $('input[name=episode]', $renameId).val(); data.epSuffix = $('input[name=ep_suffix]', $renameId).val(); + data.projectCode = this.env.AVALON_PROJECT_CODE; if (!data.ep) { this.csi.evalScript('$.pype.alert_message("' + 'Need to fill episode code' + '")'); From 64b7a79b5efc425abfd92a6f421b315c0cb9ec67 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 12 Jun 2020 20:35:36 +0300 Subject: [PATCH 5/5] fix(ppro): improving prelaunch hook --- pype/hooks/premiere/prelaunch.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pype/hooks/premiere/prelaunch.py b/pype/hooks/premiere/prelaunch.py index 43631ec2fa..118493e9a7 100644 --- a/pype/hooks/premiere/prelaunch.py +++ b/pype/hooks/premiere/prelaunch.py @@ -42,7 +42,10 @@ class PremierePrelaunch(PypeHook): # if anatomy template should have different root for particular task # just add for example > work[conforming]: workfile_search_key = f"work[{task.lower()}]" - workfile_key = anatomy_filled.get(workfile_search_key, "work") + workfile_key = anatomy_filled.get( + workfile_search_key, + anatomy_filled.get("work") + ) workdir = env["AVALON_WORKDIR"] = workfile_key["folder"] # create workdir if doesn't exist @@ -91,7 +94,7 @@ class PremierePrelaunch(PypeHook): ).format(asset_name, project_name) project_name = project_entity["name"] - self.project_code = project_entity["data"]["code"] + self.project_code = project_entity["data"].get("code") self.log.info( "Anatomy object collected for project \"{}\".".format(project_name) @@ -106,7 +109,7 @@ class PremierePrelaunch(PypeHook): "root": root_path, "project": { "name": project_name, - "code": project_entity["data"].get("code") + "code": self.project_code }, "asset": asset_entity["name"], "hierarchy": hierarchy.replace("\\", "/"),