Jump to content

Cpio Useful Stuff


Librarian

Recommended Posts

//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.

Link to comment
Share on other sites

  • 3 weeks later...

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!

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...