Jump to content

Create group from array attribute


Recommended Posts

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.

Link to comment
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);
}
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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...