def deserialize_from_dict( nodes_data: List[Dict[str, Any]], parent: hou.Node ) -> List[hou.Node]: nodes = [] for node_data in nodes_data: node_instance = node.deserialize_from_dict(node_data, parent) nodes.append(node_instance) # create connections for node_data in nodes_data: node_instance: hou.Node = parent.node(node_data["name"]) if node_instance: for connection_data in node_data["inputConnections"]: input_node = parent.node(connection_data["inputNode"]) if input_node: node_instance.setInput( input_index=connection_data["inputIndex"], item_to_become_input=input_node, output_index=connection_data["outputIndex"], ) return nodes
def deserialize_from_dict( node_data: Dict[str, Any], parent: hou.Node ) -> hou.Node: node_instance: hou.Node = parent.node(node_data["name"]) if not node_instance: node_instance = parent.createNode( node_type_name=node_data["type"]["name"], node_name=node_data["name"], ) node_instance.setPosition( vector2.deserialize_from_dict(node_data["position"]) ) # apply parameter changes exceptions: List[str] = [] for parm_name, parm_data in node_data["parms"].items(): parm: hou.Parm = node_instance.parm(parm_name) try: if parm: node_instance.parm(parm_name).set(parm_data["rawValue"]) except TypeError: exceptions.append(parm_data) if exceptions: print( "Unable to set the following parameters on '{}': {}".format( node_instance.name(), ", ".join(exceptions) ) ) # deserialize children children = nodes.deserialize_from_dict( node_data["children"].values(), node_instance ) return node_instance