Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0

A Geometry Object For Each File On Disk

Hi All,

I put together a small shelf tool that populates a subnet with an object for each .bgeo.sc file found in a supplied folder path. The end goal was to leverage s@instance for file based objects. s@instance can only reference objects, not disk files.


In this hard coded example file I am fetching 144 debris shards into 144 geometry objects which instancing can reference.

# Populates an existing subnet with a geometry node for each file found in the supplied folder.
# The File node inside the default geometry node is populated with the filename from the folder.
# The end result is you get an object for each disk object in a folder.
import os, re

def returnValidHoudiniNodeName(passedItem):
    # Thanks to Graham on OdForce for this function!
    # Replace any illegal characters for node names here.
    return re.sub("[^0-9a-zA-Z\.]+", "_", passedItem)
def returnFilesLike(passedFolderName, passedFileExtension = ".obj"):
    result = []
    for file in os.listdir(passedFolderName):
        if file.endswith(passedFileExtension):
    return result
def createSubnetOfFileNodes(passedPath, passedType):
    root = hou.node("/obj/geo_debris_container")        # Make sure it exists before running, choose your own name.
    if root != None:
        lst_files = returnFilesLike(passedPath, passedType)
        if len(lst_files):
            for i,file in enumerate(lst_files):
                # Create a file node for each geometry in our list.
                local_name = os.path.basename(file)
                local_name_only = os.path.splitext(local_name)[0]
                geo_name = returnValidHoudiniNodeName("geo_%s" % local_name_only)
                geo_name = geo_name.replace(".","_")

                node_geo = root.createNode("geo", geo_name)
                if node_geo:
                    # The first child is a default File node.
                    n = node_geo.children()[0]
                    if n:
                        # Assign this filename as the filepath for this file node.
                print "No subnet container found to contain generated results."
createSubnetOfFileNodes ("F:/Keep/Models/Rocks/debris_sharp",".bgeo.sc")


Share this post

Link to post
Share on other sites

Hmm..never heard of that attribute.

Do you know how to use it?

I have a working instance that is successfully instancing objects from within the scene using s@instance. When I change to s@instancefile and reference valid geometry path on my disk I get no output at all?


I tried both full and fast point instancing.



Edited by Atom

Share this post

Link to post
Share on other sites

It's been awhile since I did instancing in Houdini last time, but it was working back then. Maybe there something else you have to toggle on.

1 person likes this

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  
Followers 0