Jump to content
Sign in to follow this  
Christoph_H

Creating some different copies of digital asset with different values from a table

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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 by 3dome
attached sample csv

Share this post


Link to post
Share on other sites

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 by Christoph_H

Share this post


Link to post
Share on other sites

In this case you just type the name of the HDA name (not label) where it says:

'geo'

I believe

Share this post


Link to post
Share on other sites
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 by 3dome

Share this post


Link to post
Share on other sites

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 by Christoph_H

Share this post


Link to post
Share on other sites

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)

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  

×