Merge pull request #3949 from pypeclub/feature/get_subset_name_support_origin_instance

Publisher: Pass instance to subset name method on update
This commit is contained in:
Jakub Trllo 2022-10-12 11:25:07 +02:00 committed by GitHub
commit c46c4f052a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 4 deletions

View file

@ -246,7 +246,7 @@ class BaseCreator:
return self.icon
def get_dynamic_data(
self, variant, task_name, asset_doc, project_name, host_name
self, variant, task_name, asset_doc, project_name, host_name, instance
):
"""Dynamic data for subset name filling.
@ -257,7 +257,13 @@ class BaseCreator:
return {}
def get_subset_name(
self, variant, task_name, asset_doc, project_name, host_name=None
self,
variant,
task_name,
asset_doc,
project_name,
host_name=None,
instance=None
):
"""Return subset name for passed context.
@ -271,16 +277,21 @@ class BaseCreator:
Asset document is not used yet but is required if would like to use
task type in subset templates.
Method is also called on subset name update. In that case origin
instance is passed in.
Args:
variant(str): Subset name variant. In most of cases user input.
task_name(str): For which task subset is created.
asset_doc(dict): Asset document for which subset is created.
project_name(str): Project name.
host_name(str): Which host creates subset.
instance(str|None): Object of 'CreatedInstance' for which is
subset name updated. Passed only on subset name update.
"""
dynamic_data = self.get_dynamic_data(
variant, task_name, asset_doc, project_name, host_name
variant, task_name, asset_doc, project_name, host_name, instance
)
return get_subset_name(

View file

@ -1080,7 +1080,11 @@ class GlobalAttrsWidget(QtWidgets.QWidget):
try:
new_subset_name = instance.creator.get_subset_name(
new_variant_value, new_task_name, asset_doc, project_name
new_variant_value,
new_task_name,
asset_doc,
project_name,
instance=instance
)
except TaskNotSetError:
invalid_tasks = True

View file

@ -198,6 +198,37 @@ class RenderLayerCreator(Creator):
- **`get_dynamic_data`** (method) - Can be used to extend data for subset templates which may be required in some cases.
Methods are used before instance creation and on instance subset name update. Update may require to have access to existing instance because dynamic data should be filled from there. Because of that is instance passed to `get_subset_name` and `get_dynamic_data` so the creator can handle that cases.
This is one example where subset name template may contain `"{layer}"` which is filled during creation because the value is taken from selection. In that case `get_dynamic_data` returns value for `"layer"` -> `"{layer}"` so it can be filled in creation. But when subset name of already existing instance is updated it should return already existing value. Note: Creator must make sure the value is available on instance.
```python
from openpype.lib import prepare_template_data
from my_host import get_selected_layer
class SomeCreator(Creator):
def get_dynamic_data(
self, variant, task_name, asset_doc, project_name, host_name, instance
):
# Before instance is created return unfilled key
# - the key will be filled during creation
if instance is None:
return {"layer": "{layer}"}
# Take value from existing instance
# - creator must know where to look for the value
return {"layer": instance.data["layer"]}
def create(self, subset_name, instance_data, pre_create_data):
# Fill the layer name in
layer = get_selected_layer()
layer_name = layer["name"]
layer_fill_data = prepare_template_data({"layer": layer_name})
subset_name = subset_name.format(**layer_fill_data)
instance_data["layer"] = layer_name
...
```
#### *HiddenCreator*
Creator which is not showed in UI so artist can't trigger it directly but is available for other creators. This creator is primarily meant for cases when creation should create different types of instances. For example during editorial publishing where input is single edl file but should create 2 or more kind of instances each with different family, attributes and abilities. Arguments for creation were limited to `instance_data` and `source_data`. Data of `instance_data` should follow what is sent to other creators and `source_data` can be used to send custom data defined by main creator. It is expected that `HiddenCreator` has specific main or "parent" creator.