Jump to content

save selected nodes as


Recommended Posts

Here is some code you can put into a shelf tool (only tested under Linux):

import os, time, subprocess

sel = hou.selectedNodes()
parentNode = "hou.node('/obj')"
filePath = "/tmp/myTempNodes"
p = sel[0].parent()
p.saveChildrenToFile(sel,"",filePath)

if p.parent is not hou.node("/obj"):
    parentNode = "hou.node('/obj').createNode('%s','newparent')" %(p.type().name())
    
saveCode = '"' + "import os, time; newParent = "+parentNode+"; newParent.loadChildrenFromFile('"+filePath+"'); newPath = '/tmp/hipFromSel_' + time.strftime('%Y%m%d_%H%M%S') + '.hip'; hou.hipFile.save(newPath)" + '"'

pyCmd = os.environ["HFS"] + '/bin/hython -c ' + saveCode
os.system(pyCmd)
print "Saved new hip file"

You can save nodes to a file using saveChildrenToFile(); then use loadChildrenFromFile() to read them in as they were saved.

Link to comment
Share on other sites

  • 7 years later...
On 6/25/2016 at 11:18 AM, goldleaf said:

Here is some code you can put into a shelf tool (only tested under Linux):

import os, time, subprocess

sel = hou.selectedNodes()
parentNode = "hou.node('/obj')"
filePath = "/tmp/myTempNodes"
p = sel[0].parent()
p.saveChildrenToFile(sel,"",filePath)

if p.parent is not hou.node("/obj"):
    parentNode = "hou.node('/obj').createNode('%s','newparent')" %(p.type().name())
    
saveCode = '"' + "import os, time; newParent = "+parentNode+"; newParent.loadChildrenFromFile('"+filePath+"'); newPath = '/tmp/hipFromSel_' + time.strftime('%Y%m%d_%H%M%S') + '.hip'; hou.hipFile.save(newPath)" + '"'

pyCmd = os.environ["HFS"] + '/bin/hython -c ' + saveCode
os.system(pyCmd)
print "Saved new hip file"

You can save nodes to a file using saveChildrenToFile(); then use loadChildrenFromFile() to read them in as they were saved.

filePath = "D:/test/myTempNodes.cpio",Need to add suffix,Only then did it run successfully
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...