Jump to content

Recommended Posts

Hi,

I have attached a screenshot, in the following, I want to create a group that will have all the primitves mentioned in the sourceprim attribute, it is an array type attribute and I am unable to combine them all to create a group, please help.

Thanks

Capture.JPG

Share this post


Link to post
Share on other sites

Hi Ashish, try the foreach() function in a primitive wrangle.

foreach(int s; i[]@sourceprim){
    setprimgroup(0, 'sprims', s, 1, 'set');
}

 

Share this post


Link to post
Share on other sites
18 hours ago, konstantin magnus said:

Hi Ashish, try the foreach() function in a primitive wrangle.


foreach(int s; i[]@sourceprim){
    setprimgroup(0, 'sprims', s, 1, 'set');
}

 

Hi,

Thank you for your help, but Its not working. Say, I want to create an array which will have all the values of the array in attribute named sourceprim. So, how can I loop over each point for the sourceprim attribute and append all the different values from the array into one single array variable?

Suppose, I created int my_array[] and then I want this array to have all the values of the sourceprim attribute array. How to do that?? Please help.

Share this post


Link to post
Share on other sites

This is from a piece of code I get on sidefx forum sometime ago. (can't retrieve the page)
I think it can help. however it's a "post process"

int n = nuniqueval(0, "primitive", "primAtt");
for (int i=0; i<n; i++){
    int uVal = uniqueval(0, "primitive", "primAtt", i);
    append(i[]@uarray, uVal);
}

Share this post


Link to post
Share on other sites

Well, do you want to create an array or a group as the title suggests? For a point group just enter pretty much the same code in a point wrangle:

foreach(int s; i[]@sourceprim){
    setpointgroup(0, 'sprims', s, 1, 'set');
}

 

Share this post


Link to post
Share on other sites
Posted (edited)
On 12.7.2019 at 6:22 PM, flcc said:

This is from a piece of code I get on sidefx forum sometime ago. (can't retrieve the page)
I think it can help. however it's a "post process"


int n = nuniqueval(0, "primitive", "primAtt");
for (int i=0; i<n; i++){
    int uVal = uniqueval(0, "primitive", "primAtt", i);
    append(i[]@uarray, uVal);
}

Neat solution, but this does not seem to work for arrays. Here is a python code that flattens arrays from all points to one global array:

node = hou.pwd()
geo = node.geometry()

all = []
for point in geo.points():
    s = point.intListAttribValue('source')
    all.append(s)
    
all = [element for tuple in all for element in tuple]
all = sorted(set(all))

geo.addArrayAttrib(hou.attribType.Global, 'sources', hou.attribData.Int, 1)
geo.setGlobalAttribValue('sources', all)
  • Loop through all arrays of the attribute 'source' and append them to a tuple named 'all'.
  • The tuple gets converted to a list from which double entries and the order get sorted.
  • The list gets assigned to a global aka detail attribute named 'sources'.
Edited by konstantin magnus

Share this post


Link to post
Share on other sites
Posted (edited)

Transferring point arrays to a detail wrangle with VEX (slow!):

i[]@all;

for(int i = 0; i < npoints(0); i++){
    int source[] = point(0, 'source', i);
    foreach(int s; source){
        int found[] = find(@all, s);
        if(len(found) == 0){
            append(@all, s);
        }
    }
}

@all = sort(@all);

We also had this discussion a few years ago:

 

Edited by konstantin magnus

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

×