Jump to content

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


Christoph_H

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.

Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
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)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...