def remove(self, container): """Remove container. Args: container (dict): container definition. """ node = harmony.find_node_by_name(container["name"], "GROUP") harmony.send({"function": "PypeHarmony.deleteNode", "args": [node]})
def remove(self, container): node = harmony.find_node_by_name(container["name"], "READ") func = """function deleteNode(_node) { node.deleteNode(_node, true, true); } deleteNode """ harmony.send({"function": func, "args": [node]})
def check_inventory(): if not lib.any_outdated(): return host = avalon.api.registered_host() outdated_containers = [] for container in host.ls(): representation = container['representation'] representation_doc = io.find_one( { "_id": io.ObjectId(representation), "type": "representation" }, projection={"parent": True} ) if representation_doc and not lib.is_latest(representation_doc): outdated_containers.append(container) # Colour nodes. func = """function func(args){ for( var i =0; i <= args[0].length - 1; ++i) { var red_color = new ColorRGBA(255, 0, 0, 255); node.setColor(args[0][i], red_color); } } func """ outdated_nodes = [] for container in outdated_containers: if container["loader"] == "ImageSequenceLoader": outdated_nodes.append( harmony.find_node_by_name(container["name"], "READ") ) harmony.send({"function": func, "args": [outdated_nodes]}) # Warn about outdated containers. print("Starting new QApplication..") app = Qt.QtWidgets.QApplication(sys.argv) message_box = Qt.QtWidgets.QMessageBox() message_box.setIcon(Qt.QtWidgets.QMessageBox.Warning) msg = "There are outdated containers in the scene." message_box.setText(msg) message_box.exec_() # Garbage collect QApplication. del app
def update(self, container, representation): node = harmony.find_node_by_name(container["name"], "READ") path = api.get_representation_path(representation) collections, remainder = clique.assemble( os.listdir(os.path.dirname(path))) files = [] if collections: for f in list(collections[0]): files.append( os.path.join(os.path.dirname(path), f).replace("\\", "/")) else: files.append( os.path.join(os.path.dirname(path), remainder[0]).replace("\\", "/")) harmony.send({ "function": copy_files + replace_files, "args": [files, node, 1] }) # Colour node. func = """function func(args){ for( var i =0; i <= args[0].length - 1; ++i) { var red_color = new ColorRGBA(255, 0, 0, 255); var green_color = new ColorRGBA(0, 255, 0, 255); if (args[1] == "red"){ node.setColor(args[0], red_color); } if (args[1] == "green"){ node.setColor(args[0], green_color); } } } func """ if pype.lib.is_latest(representation): harmony.send({"function": func, "args": [node, "green"]}) else: harmony.send({"function": func, "args": [node, "red"]}) harmony.imprint(node, {"representation": str(representation["_id"])})
def update(self, container, representation): """Update loaded containers. Args: container (dict): Container data. representation (dict): Representation data. """ node_name = container["name"] node = harmony.find_node_by_name(node_name, "GROUP") self_name = self.__class__.__name__ update_and_replace = False if pype.lib.is_latest(representation): self._set_green(node) else: self._set_red(node) update_and_replace = harmony.send( { "function": f"PypeHarmony.Loaders.{self_name}." "askForColumnsUpdate", "args": [] } )["result"] if update_and_replace: # FIXME: This won't work, need to implement it. harmony.send( { "function": f"PypeHarmony.Loaders.{self_name}." "replaceNode", "args": [] } ) else: self.load( container["context"], container["name"], None, container["data"]) harmony.imprint( node, {"representation": str(representation["_id"])} )
def update(self, container, representation): path = api.get_representation_path(representation) with open(path) as json_file: data = json.load(json_file) layers = list() for child in data['children']: if child.get("filename"): print(child["filename"]) layers.append(child["filename"]) else: for layer in child['children']: if layer.get("filename"): print(layer["filename"]) layers.append(layer["filename"]) bg_folder = os.path.dirname(path) path = api.get_representation_path(representation) print(container) for layer in sorted(layers): file_to_import = [os.path.join(bg_folder, layer).replace("\\", "/")] print(20*"#") print(f"FILE TO REPLACE: {file_to_import}") print(f"LAYER: {layer}") node = harmony.find_node_by_name(layer, "READ") print(f"{node}") if node in container['nodes']: harmony.send( { "function": copy_files + replace_files, "args": [file_to_import, node, 1] } ) else: read_node = harmony.send( { "function": copy_files + import_files, "args": ["Top", file_to_import, layer, 1] } )["result"] container['nodes'].append(read_node) # Colour node. func = """function func(args){ for( var i =0; i <= args[0].length - 1; ++i) { var red_color = new ColorRGBA(255, 0, 0, 255); var green_color = new ColorRGBA(0, 255, 0, 255); if (args[1] == "red"){ node.setColor(args[0], red_color); } if (args[1] == "green"){ node.setColor(args[0], green_color); } } } func """ if pype.lib.is_latest(representation): harmony.send({"function": func, "args": [node, "green"]}) else: harmony.send({"function": func, "args": [node, "red"]}) harmony.imprint( container['name'], {"representation": str(representation["_id"]), "nodes": container['nodes']} )