Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. import os
  2. import sys
  3.  
  4.  
  5. from NodeGraphQt import (
  6. NodeGraph,
  7. BaseNode,
  8. )
  9.  
  10. from avalon import io, style
  11. from avalon.vendor import qtawesome as qta
  12. # todo: Don't reference from cbloader.tools but make reusable widgets more public
  13. from avalon.tools.cbloader import lib
  14.  
  15.  
  16. def get_inputs(representation_id):
  17. representation = io.find_one({"_id": io.ObjectId(representation_id),
  18. "type": "representation"})
  19. return representation["data"].get("inputs", [])
  20.  
  21.  
  22. class AvalonDependencyNode(BaseNode):
  23. """Simple in/out node."""
  24.  
  25. # set a unique node identifier.
  26. __identifier__ = 'avalon'
  27.  
  28. # set the initial default node name.
  29. NODE_NAME = 'representation'
  30.  
  31. def __init__(self):
  32. BaseNode.__init__(self)
  33. self.set_color(25, 58, 51)
  34.  
  35. # create input and output port.
  36. self.add_input('input', color=(200, 10, 0), multi_input=True)
  37. self.add_output('output', multi_output=True)
  38.  
  39.  
  40. def create_representation_node(graph, representation):
  41.  
  42. name = "{asset}_{subset} v{version:03d}".format(**representation.get("context", {}))
  43. return graph.create_node('avalon.AvalonDependencyNode',
  44. name=name,
  45. color='#771e20',
  46. text_color='#cccb20')
  47.  
  48.  
  49. def create_inputs(graph, representation_id, attach_to_node=None):
  50.  
  51. for input_representation_id in get_inputs(representation_id):
  52.  
  53. input_representation = io.find_one({"_id": io.ObjectId(input_representation_id),
  54. "type": "representation"})
  55. node = create_representation_node(graph, input_representation)
  56.  
  57. if attach_to_node:
  58. node.set_output(0, attach_to_node.input(0))
  59.  
  60. create_inputs(graph,
  61. representation_id=input_representation_id,
  62. attach_to_node=node)
  63.  
  64.  
  65.  
  66.  
  67. if __name__ == '__main__':
  68.  
  69. # create node graph.
  70. graph = NodeGraph()
  71.  
  72. # viewer widget used for the node graph.
  73. viewer = graph.viewer()
  74. viewer.resize(1100, 800)
  75. viewer.show()
  76.  
  77. # registered nodes.
  78. reg_nodes = [
  79. AvalonDependencyNode,
  80. ]
  81. for n in reg_nodes:
  82. # Note: The registry of a node can only
  83. # happen once. Next iteration it will
  84. # raise an error!
  85. try:
  86. graph.register_node(n)
  87. except Exception as exc:
  88. print(exc)
  89. print("Ignoring..")
  90.  
  91. # Hardcoded sample representation id for now
  92. representation_id = "5d0265dad332f851fa2c4651"
  93. representation = io.find_one({"_id": io.ObjectId(representation_id),
  94. "type": "representation"})
  95. node = create_representation_node(graph, representation)
  96. create_inputs(graph, representation_id, attach_to_node=node)
  97.  
  98. # Set different color for the original node
  99. node.set_color(121, 151, 42)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement