Jump to content
Sign in to follow this  
konstantin magnus

Turn selected folder into an absolute path

Recommended Posts

I am building a shelf tool that imports all *.PLY-files from a folder. It works, just how can I convert this into an absolute path?

hipdir = os.environ["HIP"]
folder = hou.ui.selectFile(title="Choose directory:", file_type=hou.fileType.Directory)

 

 

Share this post


Link to post
Share on other sites
abspath = hou.expandString(folder)

 

Share this post


Link to post
Share on other sites
Posted (edited)

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 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×