Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion hooks/secondary_publish_tk-maya.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def __publish_alembic_cache(self, item, output, work_template, primary_publish_p
self.parent.ensure_folder_exists(publish_folder)

# determine the publish name:
publish_name = fields.get("name")
publish_name = self._get_publish_name(publish_path, publish_template, fields)
if not publish_name:
publish_name = os.path.basename(publish_path)

Expand Down Expand Up @@ -223,6 +223,71 @@ def __publish_alembic_cache(self, item, output, work_template, primary_publish_p
}
tank.util.register_publish(**args)

def _get_publish_name(self, path, template, fields=None):
"""
Return the 'name' to be used for the file - if possible
this will return a 'versionless' name
"""
# first, extract the fields from the path using the template:
fields = fields.copy() if fields else template.get_fields(path)
if "name" in fields and fields["name"]:
# well, that was easy!
name = fields["name"]
else:
# find out if version is used in the file name:
template_name, _ = os.path.splitext(os.path.basename(template.definition))
version_in_name = "{version}" in template_name

# extract the file name from the path:
name, _ = os.path.splitext(os.path.basename(path))
delims_str = "_-. "
if version_in_name:
# looks like version is part of the file name so we
# need to isolate it so that we can remove it safely.
# First, find a dummy version whose string representation
# doesn't exist in the name string
version_key = template.keys["version"]
dummy_version = 9876
while True:
test_str = version_key.str_from_value(dummy_version)
if test_str not in name:
break
dummy_version += 1

# now use this dummy version and rebuild the path
fields["version"] = dummy_version
path = template.apply_fields(fields)
name, _ = os.path.splitext(os.path.basename(path))

# we can now locate the version in the name and remove it
dummy_version_str = version_key.str_from_value(dummy_version)

v_pos = name.find(dummy_version_str)
# remove any preceeding 'v'
pre_v_str = name[:v_pos].rstrip("v")
post_v_str = name[v_pos + len(dummy_version_str):]

if (pre_v_str and post_v_str
and pre_v_str[-1] in delims_str
and post_v_str[0] in delims_str):
# only want one delimiter - strip the second one:
post_v_str = post_v_str.lstrip(delims_str)

versionless_name = pre_v_str + post_v_str
versionless_name = versionless_name.strip(delims_str)

if versionless_name:
# great - lets use this!
name = versionless_name
else:
# likely that version is only thing in the name so
# instead, replace the dummy version with #'s:
zero_version_str = version_key.str_from_value(0)
new_version_str = "#" * len(zero_version_str)
name = name.replace(dummy_version_str, new_version_str)

return name

def _find_scene_animation_range(self):
"""
Find the animation range from the current scene.
Expand Down