diff --git a/openpype/hosts/maya/api/lib_template_builder.py b/openpype/hosts/maya/api/lib_template_builder.py index f25d2ebd1d0..1d425c7b254 100644 --- a/openpype/hosts/maya/api/lib_template_builder.py +++ b/openpype/hosts/maya/api/lib_template_builder.py @@ -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", diff --git a/openpype/lib/abstract_template_loader.py b/openpype/lib/abstract_template_loader.py index aebb4600b32..763f45e84ad 100644 --- a/openpype/lib/abstract_template_loader.py +++ b/openpype/lib/abstract_template_loader.py @@ -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: """ @@ -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 @@ -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() @@ -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):