Skip to content

Commit

Permalink
add simple loading options feature in placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitConnan authored and ClementHector committed Feb 8, 2022
1 parent 90f137e commit 554c487
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
11 changes: 11 additions & 0 deletions openpype/hosts/maya/api/lib_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def create_placeholder():
Defines what openpype loader will be used to load assets.
Useable loader depends on current host's loader list.
Field is case sensitive.
"""),
qargparse.String(
"loader_args",
default="",
label="Loader Arguments",
placeholder='ex: {"camera":"persp", "lights":True}',
help="""Loader
Defines a dictionnary of arguments used to load assets.
Useable arguments depend on current placeholder Loader.
Field should be a valid python dict. Anything else will be ignored.
"""),
qargparse.Integer(
"order",
Expand Down
28 changes: 24 additions & 4 deletions openpype/lib/abstract_template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ def update_representations(entities, entity):

return entities

def parse_loader_args(loader_args):
if not loader_args:
return dict()
try:
parsed_args= eval(loader_args)
if not isinstance(parsed_args, dict):
return dict()
else:
return parsed_args
except Exception as err:
print(
"Error while parsing loader arguments '{}'.\n{}: {}\n\n"
"Continuing with default arguments. . .".format(
loader_args,
err.__class__.__name__,
err))
return dict()

@six.add_metaclass(ABCMeta)
class AbstractTemplateLoader:
"""
Expand Down Expand Up @@ -181,7 +199,8 @@ def populate_template(self, override=None):
continue
container = avalon.api.load(
loaders_by_name[placeholder.loader],
last_representation['_id'])
last_representation['_id'],
options=parse_loader_args(placeholder.data['loader_args']))
placeholder.parent_in_hierarchy(container)
placeholder.clean()
# Merge to populate_template
Expand Down Expand Up @@ -222,7 +241,8 @@ def update_template(self):
continue
container = avalon.api.load(
loaders_by_name[placeholder.loader],
last_representation['_id'])
last_representation['_id'],
options=parse_loader_args(placeholder.data['loader_args']))
placeholder.parent_in_hierarchy(container)
placeholder.clean()

Expand Down Expand Up @@ -292,8 +312,8 @@ class AbstractPlaceholder:
"""

attributes = {'builder_type', 'family',
'representation', 'order', 'loader'}
attributes = {'builder_type', 'family', 'representation',
'order', 'loader', 'loader_args'}
optional_attributes = {}

def __init__(self, node):
Expand Down

0 comments on commit 554c487

Please sign in to comment.