Jump to content

Turn selected folder into an absolute path


konstantin magnus

Recommended Posts

Btw. here is the code I have so far. It merges all geometry files from a folder into a single merge node. I am more than open to suggestions and improvements..

import os

# CHOOSE DIRECTORY
folder = hou.ui.selectFile(title="Choose directory:", file_type=hou.fileType.Directory)
path = hou.expandString(folder)

# FILE LIST
extensions = ['obj', 'ply', 'dae']
files = [file for file in sorted(os.listdir(path))
        if any(file.endswith(ext) for ext in extensions)]
file_count = len(files)
print "Importing " + str(file_count) + " files from " + path

# CREATE GEO NODE
container = hou.node('/obj').createNode('geo')
container.setName('cache_import')
for child in container.children():
    child.destroy()

# CREATE MERGE AND FILE-NODES
merge = container.createNode('merge')

for i in range(file_count):
    file_node = container.createNode('file')
    file_name = path + files[i]
    file_node.parm('file').set(file_name)
    merge.setNextInput(file_node, 0, False)
 
# CREATE OUT-NODE
out = container.createNode('null')
out.setName('OUT')
out.setInput(0, merge, 0)
out.setDisplayFlag(True)

container.layoutChildren()
Edited by konstantin magnus
  • Like 2
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...