Skip to content

Commit 54eeb59

Browse files
committed
Revised content browser template logic to better match Shotgun tk-config-default2 layout
1 parent a790b36 commit 54eeb59

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

hooks/tk-multi-loader2/tk-unreal_actions.py

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -219,60 +219,55 @@ def _get_destination_path_and_name(self, sg_publish_data):
219219
# Enable if needed while in development
220220
# self.sgtk.reload_templates()
221221

222-
# Get the publish context which should be for an asset, task or project
222+
# Get the publish context to determine the template to use
223223
context = self.sgtk.context_from_entity_dictionary(sg_publish_data)
224-
# unreal.log("Publish data Context: {}".format(context))
225224

226-
# Query the fields that will be applied to templates
227-
# We will select a template that matches the fields available
228-
query_template = self.sgtk.templates["unreal_fields_query"]
229-
fields = context.as_template_fields(query_template)
230-
unreal.log("Template fields: {}".format(fields))
231-
232-
# By default, use the most basic template based on asset type and name
233-
destination_template = self.sgtk.templates["unreal_asset_template"]
234-
235-
if fields:
236-
# Check for project-specific templates that use specific fields
237-
if fields["sg_category_3"] is not None:
238-
destination_template = self.sgtk.templates["unreal_asset_3_categories"]
239-
elif fields["sg_category_2"] is not None:
240-
destination_template = self.sgtk.templates["unreal_asset_2_categories"]
241-
elif fields["sg_category_1"] is not None:
242-
destination_template = self.sgtk.templates["unreal_asset_1_category"]
243-
elif fields["sg_asset_type"] is None:
244-
# Case of asset with no type
245-
destination_template = self.sgtk.templates["unreal_asset_notype"]
225+
# Get the destination templates based on the context
226+
# Assets and Shots supported by default
227+
# Other entities fall back to Project
228+
if context.entity is None:
229+
destination_template = self.sgtk.templates["unreal_loader_project_path"]
230+
destination_name_template = self.sgtk.templates["unreal_loader_project_name"]
231+
elif context.entity["type"] == "Asset":
232+
destination_template = self.sgtk.templates["unreal_loader_asset_path"]
233+
destination_name_template = self.sgtk.templates["unreal_loader_asset_name"]
234+
elif context.entity["type"] == "Shot":
235+
destination_template = self.sgtk.templates["unreal_loader_shot_path"]
236+
destination_name_template = self.sgtk.templates["unreal_loader_shot_name"]
246237
else:
247-
# fields is empty in the case of the project context, which indicates
248-
# that we are trying to load a published file not linked to any task or asset
249-
# In that case, use the published file template
250-
destination_template = self.sgtk.templates["unreal_published_file"]
251-
252-
# Derive the destination name from the published file name without the extension
253-
# Use publish name from "code" property, fallback to "name" in "path" if there
254-
if "code" in sg_publish_data:
255-
name = sg_publish_data["code"]
256-
elif "path" in sg_publish_data and "name" in sg_publish_data["path"]:
257-
name = sg_publish_data["path"]["name"]
258-
259-
name = os.path.splitext(name)[0]
260-
unreal.log("Published file name: {}".format(name))
261-
262-
# Add it as sg_asset_name in fields to apply it to the template
263-
fields["sg_asset_name"] = name
264-
265-
if "sg_asset_name" in fields:
266-
fields["sg_asset_name"] = _sanitize_name(fields["sg_asset_name"])
238+
destination_template = self.sgtk.templates["unreal_loader_project_path"]
239+
destination_name_template = self.sgtk.templates["unreal_loader_project_name"]
240+
241+
# Get the name field from the Publish Data
242+
name = sg_publish_data["name"]
243+
name = os.path.splitext(name)[0]
244+
245+
# Query the fields needed for the destination template from the context
246+
fields = context.as_template_fields(destination_template)
247+
248+
# Add the name field from the publish data
249+
fields["name"] = name
267250

268-
unreal.log("Selected destination template: {}".format(destination_template))
269-
destination_path = destination_template.apply_fields(fields)
270-
unreal.log("Destination path after applying fields: {}".format(destination_path))
251+
# Get destination path by applying fields to destination template
252+
# Fall back to the root level if unsuccessful
253+
try:
254+
destination_path = destination_template.apply_fields(fields)
255+
except Exception:
256+
destination_path = "/Game/Assets/"
271257

272-
destination_name = None
273-
if "sg_asset_name" in fields:
274-
destination_name = fields["sg_asset_name"]
275-
258+
# Query the fields needed for the name template from the context
259+
name_fields = context.as_template_fields(destination_name_template)
260+
261+
# Add the name field from the publish data
262+
name_fields["name"] = name
263+
264+
# Get destination name by applying fields to the name template
265+
# Fall back to the filename if unsuccessful
266+
try:
267+
destination_name = destination_name_template.apply_fields(name_fields)
268+
except Exception:
269+
destination_name = _sanitize_name(sg_publish_data["code"])
270+
276271
return destination_path, destination_name
277272

278273
"""

0 commit comments

Comments
 (0)