Librarian Posted February 14, 2023 Share Posted February 14, 2023 //save nodes import hou # set directory to save cpio dirPath = "DIRECTORY" def SaveTemplate(name): sel = hou.selectedNodes() path = sel[0].path() nodeCategoryName = sel[0].type().category().name() pathSplit = path.split("/") pathSplit.pop(-1) getRootPath = "/".join(pathSplit) rootName = getRootPath[1:].replace("/","_") contextnode = hou.node(getRootPath) filename = "{}/{}_{}".format(dirPath, nodeCategoryName, name + ".cpio") contextnode.saveItemsToFile(sel, filename, save_hda_fallbacks = False) hou.ui.displayMessage("Success!\n" + "Save File: "+filename) print("Save File: "+filename) Dialog = hou.ui.readInput(message ="Save Select Nodes?\n",title = "Save Template",severity=hou.severityType.Message,buttons=["Save","Cancel"]) //import nodes import hou import os # directory to open cpio dirPath = "DIRECTORY" files = os.listdir(dirPath) fileList = [f for f in files if os.path.isfile(os.path.join(dirPath, f))] def ImportTemplate(filename): desktop = hou.ui.curDesktop() pane = desktop.paneTabOfType(hou.paneTabType.NetworkEditor) current_context = pane.pwd().path() hou.clearAllSelected() contextnode = hou.node(current_context) nodes = contextnode.loadItemsFromFile(filename, ignore_load_warnings=False) sel = hou.selectedNodes() firstNodePos = sel[0].position() for node in sel: node.setPosition( node.position() + hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor).visibleBounds().center() - firstNodePos ) Dialog = hou.ui.selectFromList(fileList, message='Select Import File') if len(Dialog)!=0: for i in Dialog: ImportTemplate("{}/{}".format(dirPath, fileList[i])) For Speed.Save Nodes-Open Nodes , endless possibility for making a Diff Setups . Have Fun. Quote Link to comment Share on other sites More sharing options...
ftaswin Posted March 4, 2023 Share Posted March 4, 2023 Hi Tesan, Just a thought to consider, you might want to look into using selectedItems() instead of selectedNodes(). Items includes dot, sticky notes and networkBoxes. If you use selectedNodes, then all the dots are not going to get copied over and the connections are lost. Very frustrating if you find it mid production and you rely on the tool. Great stuff! 1 Quote Link to comment Share on other sites More sharing options...
Librarian Posted March 4, 2023 Author Share Posted March 4, 2023 thanx for Info! @ftaswin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.