Skip to content

Commit

Permalink
Added script to get projectcode data from Shotgun, and replace keywor…
Browse files Browse the repository at this point in the history
…d {projectcode} in Hiero to corresponding projectcode.
  • Loading branch information
gillesvink committed Aug 21, 2020
1 parent 432fa40 commit 4f513d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 21 additions & 2 deletions hooks/hiero_resolve_custom_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

import sgtk
from tank.util import shotgun
from tank import Hook


Expand All @@ -33,7 +34,25 @@ def execute(self, task, keyword, **kwargs):
associated string.
:rtype: str
"""
shot_code = task._item.name()
if keyword == "{projectcode}":
# Getting shotgun credentials
sg = shotgun.get_sg_connection()

# Finding current project name
current_engine = sgtk.platform.current_engine()
current_context = current_engine.context
projectname_entity = current_context.project["name"]

# Searching for projectcode in entity's of project
def returnProjectId(projectname):
for p in sg.find("Project",[["name", "is", projectname]], ["name","sg_projectcode"]):
return p["sg_projectcode"]

# Executing function to find projectcode
projectcode_entity = returnProjectId(projectname_entity)

# Returning projectcode as a replacement of the keyword
return projectcode_entity

# grab the shot from the cache, or the get_shot hook if not cached
sg_shot = self._sg_lookup_cache.get(shot_code)
Expand Down
1 change: 0 additions & 1 deletion python/base_hooks/hiero_resolve_custom_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class HieroResolveCustomStrings(HookBaseClass):
This class implements a hook that is used to resolve custom tokens into
their concrete value when paths are being processed during the export.
"""

def execute(self, task, keyword, **kwargs):
"""
The default implementation of the custom resolver simply looks up
Expand Down

0 comments on commit 4f513d5

Please sign in to comment.