Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- from NodeGraphQt import (
- NodeGraph,
- BaseNode,
- )
- from avalon import io, style
- from avalon.vendor import qtawesome as qta
- # todo: Don't reference from cbloader.tools but make reusable widgets more public
- from avalon.tools.cbloader import lib
- def get_inputs(representation_id):
- representation = io.find_one({"_id": io.ObjectId(representation_id),
- "type": "representation"})
- return representation["data"].get("inputs", [])
- class AvalonDependencyNode(BaseNode):
- """Simple in/out node."""
- # set a unique node identifier.
- __identifier__ = 'avalon'
- # set the initial default node name.
- NODE_NAME = 'representation'
- def __init__(self):
- BaseNode.__init__(self)
- self.set_color(25, 58, 51)
- # create input and output port.
- self.add_input('input', color=(200, 10, 0), multi_input=True)
- self.add_output('output', multi_output=True)
- def create_representation_node(graph, representation):
- name = "{asset}_{subset} v{version:03d}".format(**representation.get("context", {}))
- return graph.create_node('avalon.AvalonDependencyNode',
- name=name,
- color='#771e20',
- text_color='#cccb20')
- def create_inputs(graph, representation_id, attach_to_node=None):
- for input_representation_id in get_inputs(representation_id):
- input_representation = io.find_one({"_id": io.ObjectId(input_representation_id),
- "type": "representation"})
- node = create_representation_node(graph, input_representation)
- if attach_to_node:
- node.set_output(0, attach_to_node.input(0))
- create_inputs(graph,
- representation_id=input_representation_id,
- attach_to_node=node)
- if __name__ == '__main__':
- # create node graph.
- graph = NodeGraph()
- # viewer widget used for the node graph.
- viewer = graph.viewer()
- viewer.resize(1100, 800)
- viewer.show()
- # registered nodes.
- reg_nodes = [
- AvalonDependencyNode,
- ]
- for n in reg_nodes:
- # Note: The registry of a node can only
- # happen once. Next iteration it will
- # raise an error!
- try:
- graph.register_node(n)
- except Exception as exc:
- print(exc)
- print("Ignoring..")
- # Hardcoded sample representation id for now
- representation_id = "5d0265dad332f851fa2c4651"
- representation = io.find_one({"_id": io.ObjectId(representation_id),
- "type": "representation"})
- node = create_representation_node(graph, representation)
- create_inputs(graph, representation_id, attach_to_node=node)
- # Set different color for the original node
- node.set_color(121, 151, 42)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement