bjs Posted June 20, 2017 Share Posted June 20, 2017 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(): a.write(str(bdl.name())) a.write("\n") a.close b.write(str(bdl.pattern())) b.write("\n") b.close c.write(str(bdl.filter())) c.write("\n") c.close 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, Bastian. Quote Link to comment Share on other sites More sharing options...
bjs Posted June 20, 2017 Author Share Posted June 20, 2017 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! Quote Link to comment Share on other sites More sharing options...
bjs Posted June 20, 2017 Author Share Posted June 20, 2017 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") a.close 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') a.write(str(hou.node('../../OUT').findGlobalAttrib('myattrib'))) a.close 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') a.write(str(hou.node('../../OUT'))) a.close What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
f1480187 Posted June 20, 2017 Share Posted June 20, 2017 (edited) 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: f.write(data) 3. Add new Button parameter and choose Python in the callback language. Then enter the callback like this: kwargs['node'].hdaModule().dump() Here is a bit more complex examples with vector arrays: attribute_dump.hipnc attribute_dump_numpy.hipnc (surprisingly for me, slower) Edited June 20, 2017 by f1480187 4 Quote Link to comment Share on other sites More sharing options...
bjs Posted June 22, 2017 Author Share Posted June 22, 2017 Awesome, F1! Works beautifully – and thanks for the additional examples (how to link to a texfield and format those vector arrays)! Quote Link to comment Share on other sites More sharing options...
sherlockHound Posted January 9, 2020 Share Posted January 9, 2020 This is great! Thank you! Does anybody have any idea how to Dump automatically every frame? Quote Link to comment Share on other sites More sharing options...
sherlockHound Posted January 29, 2020 Share Posted January 29, 2020 Hi All - I used the attribute_dump.hipnc file as a guide and it works great, but I would like to save out as just floats (not vectors) Does anybody know what I need to do in the code to change that? Right now I have: for (int i = 0; i < @numpt; i++) { vector pos = point(0, "P", i); float h = pos.y; append(v[]@point_colors, h); } But that writes a vector where all three values are h for each line. I'd like to just write a float to save space and time. Any ideas? Thanks! Quote Link to comment Share on other sites More sharing options...
dleonhardt Posted January 30, 2020 Share Posted January 30, 2020 15 hours ago, sherlockHound said: Hi All - I used the attribute_dump.hipnc file as a guide and it works great, but I would like to save out as just floats (not vectors) Does anybody know what I need to do in the code to change that? Right now I have: for (int i = 0; i < @numpt; i++) { vector pos = point(0, "P", i); float h = pos.y; append(v[]@point_colors, h); } But that writes a vector where all three values are h for each line. I'd like to just write a float to save space and time. Any ideas? Thanks! Hello David you are getting vectors because you are writing to v[]@point_colors which is a vector array. To write floats you need to replace the v[](vector array) with a f[](float array). Quote Link to comment Share on other sites More sharing options...
sherlockHound Posted January 30, 2020 Share Posted January 30, 2020 6 hours ago, dleonhardt said: Hello David you are getting vectors because you are writing to v[]@point_colors which is a vector array. To write floats you need to replace the v[](vector array) with a f[](float array). Thank you, Dennis! I looked into that on your recommendation, but I can not find a float array to use. Any ideas? I am very new to this, despite having used Houdini for many years! Quote Link to comment Share on other sites More sharing options...
dleonhardt Posted January 30, 2020 Share Posted January 30, 2020 18 minutes ago, sherlockHound said: Thank you, Dennis! I looked into that on your recommendation, but I can not find a float array to use. Any ideas? I am very new to this, despite having used Houdini for many years! Change line 5 to append(f[]@point_colors, h); and you should get floats. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.