Jump to content

Generate Text File out of Houdini

Recommended Posts

Hey there –

I hope, this is the right forum. I am creating an HDA on SOP level that creates a detail attribute on a geo. What I would like to do now is create a textfile (on the desktop, the current directory or a directory chosen by the user – not too important right now) containing this detail attribute (a string) when the user clicks a button.

What I came about on https://tosinakinwoye.com/2014/05/04/houdini-python-snippets/ is this snippet:

# write bundle names, filter and pattern to file
import hou
namedumpfile = '/u/toa/Desktop/b_name.txt'
patterndumpfile = '/u/toa/Desktop/b_pattern.txt'
filterdumpfile = '/u/toa/Desktop/b_filter.txt'
a = file(namedumpfile, 'w')
b = file(patterndumpfile, 'w')
c = file(filterdumpfile, 'w')

# write bundle names, filter and pattern
for bdl in hou.nodeBundles():



Copied into a python node at the end of my setup, this lets me write a string to textfile – but several problems arise: I suspect that the code is run everytime the Python SOP is cooked (but I rather want to let the user decide when to write the file, not have Houdini do it automatically). And the resulting file is also locked (meaning that it can't be edited or deleted).

What I would like better would be the behaviour of a ROP Output Driver – meaning a node that generates the file only when the button is clicked.

So my suspicion is that the Python SOP is probably not the best choice?!

I would greatly appreciate your help. Thanks,


Share this post

Link to post
Share on other sites

I am currently looking into the Shell ROP inside a ROP Network, which looks promising. I now need to find a possibility to get that detail attribute from outside that ROP Network, but I think I saw something like this yesterday, I just have to find it again.

I'll keep you posted, thanks for your help!

Share this post

Link to post
Share on other sites

Alright, getting closer. This first snippet in the "Pre-Render Script" field is working:

myfile = '$HIP/myfile.txt'
a = file(myfile, 'w')
a.write("test abc")

Just like you would expect, every time you hit the "Run Command" button, it writes to the textfile in the current directory.

Now I would like to get a detail attribute from outside the ROP Network and write it into the file. Since I only have very basic knowledge of Python inside Houdini, this is what I tried:

myfile = '$HIP/myfile.txt'
a = file(myfile, 'w')

But I get an error message now, stating "'SopNode' object has no attribute 'findGlobalAttrib'" ...

If I leave out the "findGlobalAttrib" method, it writes "OUT" in the textfile, so Python seams to find the SOP, right?

myfile = '$HIP/myfile.txt'
a = file(myfile, 'w')

What am I doing wrong?

Share this post

Link to post
Share on other sites

1. Add new PythonModule to Scripts tab in Type Properties window.

2. Define your dump function.

def dump():
    # Retrieve values.
    geo = hou.pwd().geometry()
    data = geo.stringAttribValue('my_attrib')

    # Write on disk.
    path = '$HIP/attribute_dump.txt'
    path = hou.expandString(path)  # Expand Houdini variables.
    with open(path, 'w') as f:

3. Add new Button parameter and choose Python in the callback language. Then enter the callback like this:



Here is a bit more complex examples with vector arrays:

Edited by f1480187
  • Like 4

Share this post

Link to post
Share on other sites

Awesome, F1! Works beautifully – and thanks for the additional examples (how to link to a texfield and format those vector arrays)!

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