Christoph_H Posted November 23, 2018 Share Posted November 23, 2018 Hi, whats the best way? I have a digital asset with 4 parameters. I want to create some copies of this based of different parameter values from a table file. It would be cool to read and create automatically geos. My python skills are very very rough. I don't know how to begin. Can you help me? thanks. Quote Link to comment Share on other sites More sharing options...
3dome Posted November 23, 2018 Share Posted November 23, 2018 (edited) import csv file = hou.ui.readInput('Enter the full path of the csv file', buttons=('OK', 'Cancel')) if(file[0]==0): with open(file[1], 'rb') as f: doc = csv.reader(f) for row in doc: node = hou.node('/obj').createNode('geo') #create instances of your HDA here instead node.parm('px').set(row[0]) #set the correct parameter of your HDA node.parm('py').set(row[1]) node.parm('pz').set(row[2]) node.parm('prx').set(row[3]) node.moveToGoodPosition() edit: attached sample CSV to go along with code testtable.csv Edited November 23, 2018 by 3dome attached sample csv Quote Link to comment Share on other sites More sharing options...
Christoph_H Posted November 26, 2018 Author Share Posted November 26, 2018 (edited) Thank you. It's really helpfull. But I have two questions: How exactly do I set the HDA? I could not use the asset name in my scene. Or do I have to specify the directory path of the hda? How do I define the selection of certain vertical columns in combination with horizontal rows? thank you. Edited November 26, 2018 by Christoph_H Quote Link to comment Share on other sites More sharing options...
acey195 Posted November 26, 2018 Share Posted November 26, 2018 In this case you just type the name of the HDA name (not label) where it says: 'geo' I believe Quote Link to comment Share on other sites More sharing options...
Christoph_H Posted November 26, 2018 Author Share Posted November 26, 2018 (edited) Sorry. My mistake. it works. Edited November 26, 2018 by Christoph_H Quote Link to comment Share on other sites More sharing options...
3dome Posted November 26, 2018 Share Posted November 26, 2018 (edited) 5 hours ago, Christoph_H said: Sorry. My mistake. it works. But the other question would still remain. How can I additionally work with the vertical columns? I don't think you can directly read columns with the python csv module. You gotta do some search in the documentation or on stackexchange, etc 5 hours ago, Christoph_H said: How do I define the selection of certain vertical columns in combination with horizontal rows? You mean something like directly accessing a cell like B3? https://stackoverflow.com/questions/5757743/how-can-i-get-a-specific-field-of-a-csv-file See first answer, Update 2 Edited November 26, 2018 by 3dome Quote Link to comment Share on other sites More sharing options...
Christoph_H Posted November 27, 2018 Author Share Posted November 27, 2018 (edited) thank you so far. hopefully the last question: I want add setName to my created nodes, but it doesn't work. import csv with open('path', 'rb') as f: doc = csv.reader(f) for row in doc: node = hou.node('/obj').createNode('hda') node.parm('w').set(row[0]) node.parm('t').set(row[1]) node.parm('angle').set(row[2]) node.setName("test_") node.moveToGoodPosition() Edited November 27, 2018 by Christoph_H Quote Link to comment Share on other sites More sharing options...
3dome Posted November 27, 2018 Share Posted November 27, 2018 it doens't work because if you look in the very helpful Houdini python documentation you see that the argument unique_name defaults to False. So the script tries to create a node with a name that already exists (created in the first iteration of the loop). 2 ways to fix that: 1) import csv file = hou.ui.readInput('Enter the full path of the csv file.', buttons=('OK', 'Cancel')) if(file[0]==0): with open(file[1], 'rb') as f: doc = csv.reader(f) for idx,row in enumerate(doc): #using enumerate to get the iteration node = hou.node('/obj').createNode('geo') node.parm('px').set(row[0]) node.parm('py').set(row[1]) node.parm('pz').set(row[2]) node.parm('prx').set(row[3]) node.moveToGoodPosition() node.setName('test_' + str(idx)) #adding the iteration number to the string to create unique names 2) node.setName('test_', True) Quote Link to comment Share on other sites More sharing options...
Christoph_H Posted November 29, 2018 Author Share Posted November 29, 2018 Ok. Thank you for the help. 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.