-
Notifications
You must be signed in to change notification settings - Fork 129
Publisher: Create context has shared data for collection phase #3995
Publisher: Create context has shared data for collection phase #3995
Conversation
Task linked: OP-4178 Add Shared data for collection phase |
How about |
I wonder whats gonna happen if user will add new instance during one session where the publisher window will be opened on second desktop for example. To be more specific, is it recached in case of altering the scene after the first caching? |
I think I didn't explain it properly. It's not for caching instance data, it's for caching any data that may be common for multiple creators during
I think this question was raised because of misunderstanding the feature. |
I feel like just having a Each Creator would then automatically get that dict assigned like e.g.: creator.collection_cache = cache I feel like the example is much better as a parent class to be inherited from. # NOTE: This is made up code based on Nuke knowledge
def _collect_instance_nodes():
instance_data_with_node = []
for node in nuke.allNodes(recurseGroups=True):
if node.Class() in ["Viewer", "Dot"]:
continue
try:
if node["disable"].value():
continue
except Exception as _exc:
log.debug("Node {} have no disable knob - {}".format(
node.fullName(), _exc))
# get data from avalon knob
instance_data = get_node_data(
node, INSTANCE_DATA_KNOB)
if (
not instance_data
or instance_data.get("id") != "pyblish.avalon.instance"
):
continue
instance_data_with_node.append((node, instance_data))
return instance_data_with_node
class CachedNodeCreator(Creator):
def get_nodes(self):
key = "openpype.nuke.instance_data_with_node"
if key in self.collection_cache:
return self.collection_cache[key]
nodes = _collect_instance_nodes()
self.collection_cache[key] = nodes
return nodes
def iter_nodes_by_identifier(self, identifier=None):
if identifier is None:
identifier = self.identifier
for node, instance_data in self.get_nodes():
if instance_data["creator_identifier"] == identifier:
yield node, instance_data
class NukeAutoCreator(CachedNodeCreator):
def collect_instances(self):
for node, instance_data in self.iter_nodes_by_identifier():
...
class NukeCreator(BaseCreator):
def collect_instances(self):
for node, instance_data in self.iter_nodes_by_identifier():
... The cache could directly be cleared after "reset" has finished in the controller. |
The only reason to use methods was to raise specific exception in case someone would try access it out of collection phase. But I'm ok with it. EDITED: Just realized I can do it anyway using property.... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it in Houdini and it seems to be working well.
Brief description
Create context allow access to shared data for time during it's reset. This gives creat plugins ability to cache common data so they're not recollected in each creator again (e.g. nodes with
avalon.pyblish.instance
in scene).Description
In most of host implementations is this benefitial for creators to run some data collection only once. Data can be stored under specific keys and are cleaned up when collection finishes. Out of collection phase are not data available.
This has been added to TrayPublisher's default creator as an example. In TrayPublisher it has almost none advantage.
Additional information
Has anyone better suggestion for the method names thenOutdated questioncollection_shared_data_contains
,get_collection_shared_data
andset_collection_shared_data
?Testing notes
Example usage