Skip to content

Commit

Permalink
fix template updating
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitConnan authored and ClementHector committed Feb 8, 2022
1 parent 6c59ea0 commit 004e522
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
4 changes: 4 additions & 0 deletions openpype/hosts/maya/api/lib_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def create_placeholder():
cmds.addAttr(
placeholder, longName="parent",
hidden=True, dataType="string")
cmds.addAttr(
placeholder, longName="index",
hidden=True, attributeType="short",
defaultValue=-1)


def update_placeholder():
Expand Down
41 changes: 20 additions & 21 deletions openpype/hosts/maya/api/template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def template_already_imported(self, err_msg):
self.import_template(self.template_path)
self.populate_template()
elif answer == updateButton:
loaded_containers_ids = self.get_loaded_containers_id()
self.populate_template(ignored_ids=loaded_containers_ids)
self.update_missing_containers()
elif answer == abortButton:
return

Expand Down Expand Up @@ -108,6 +107,15 @@ def get_data(self, node):
cmds.getAttr(node + '.parent', asString=True)
or node.rpartition('|')[0] or "")
user_data['node'] = node
if user_data['parent']:
siblings = cmds.listRelatives(user_data['parent'], children=True)
else:
siblings = cmds.ls(assemblies=True)
node_shortname = user_data['node'].rpartition('|')[2]
current_index = cmds.getAttr(node + '.index', asString=True)
user_data['index'] = (
current_index if current_index >= 0
else siblings.index(node_shortname))

self.data = user_data

Expand Down Expand Up @@ -137,16 +145,11 @@ def parent_in_hierarchy(self, containers):
nodes_to_parent.append(root)

if self.data['parent']:
siblings = cmds.listRelatives(self.data['parent'], children=True)
cmds.parent(nodes_to_parent, self.data['parent'])
else:
siblings = cmds.ls(assemblies=True)

# Move loaded nodes to correct index in outliner hierarchy to keep
index = siblings.index(self.data['node'].rpartition('|')[2])
# Move loaded nodes to correct index in outliner hierarchy
for node in set(nodes_to_parent):
cmds.reorder(node, front=True)
cmds.reorder(node, relative=index)
cmds.reorder(node, relative=self.data['index'])

node = self.data['node']
holding_sets = cmds.listSets(object=node)
Expand All @@ -156,30 +159,26 @@ def parent_in_hierarchy(self, containers):
cmds.sets(roots, forceElement=holding_set)

def clean(self):
"""Hide placeholder
parent them to root
add them to placeholder set
and register placeholder's parent
to keep placeholder info available
for future use
"""Hide placeholder, parent them to root
add them to placeholder set and register placeholder's parent
to keep placeholder info available for future use
"""
node = self.data['node']
if self.data['parent']:
cmds.setAttr(node + '.parent', self.data['parent'], type='string')
if cmds.getAttr(node + '.index') < 0:
cmds.setAttr(node + '.index', self.data['index'])

holding_sets = cmds.listSets(object=node)
if not holding_sets:
return
for set in holding_sets:
cmds.sets(node, remove=set)
if holding_sets:
for set in holding_sets:
cmds.sets(node, remove=set)

if cmds.listRelatives(node, p=True):
node = cmds.parent(node, world=True)[0]
cmds.sets(node, addElement=PLACEHOLDER_SET)
cmds.hide(node)

cmds.setAttr(node + '.hiddenInOutliner', True)
node = self.data['node'].rpartition('|')[2]

def convert_to_db_filters(self, current_asset, linked_asset):
if self.data['builder_type'] == "context_asset":
Expand Down
6 changes: 5 additions & 1 deletion openpype/lib/abstract_template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def populate_template(self, ignored_ids=None):
linked_asset_docs = get_linked_assets(current_asset_docs)
linked_assets = [asset['name'] for asset in linked_asset_docs]

ignored_ids = [] or ignored_ids
ignored_ids = ignored_ids or []
sorted_placeholders = self.get_sorted_placeholders()
for placeholder in sorted_placeholders:
placeholder_db_filters = placeholder.convert_to_db_filters(
Expand Down Expand Up @@ -265,6 +265,10 @@ def populate_template(self, ignored_ids=None):
placeholder.parent_in_hierarchy(container)
placeholder.clean()

def update_missing_containers(self):
loaded_containers_ids = self.get_loaded_containers_by_id()
self.populate_template(ignored_ids=loaded_containers_ids)

def get_sorted_placeholders(self):
placeholder_class = self.placeholder_class
placeholders = map(placeholder_class, self.get_template_nodes())
Expand Down
2 changes: 1 addition & 1 deletion openpype/lib/build_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def build_workfile_template(args):

def update_workfile_template(args):
template_loader = build_template_loader()
template_loader.update_template()
template_loader.update_missing_containers()


def build_template_loader():
Expand Down

0 comments on commit 004e522

Please sign in to comment.