cgartashish Posted July 11, 2019 Share Posted July 11, 2019 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 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted July 11, 2019 Share Posted July 11, 2019 Hi Ashish, try the foreach() function in a primitive wrangle. foreach(int s; i[]@sourceprim){ setprimgroup(0, 'sprims', s, 1, 'set'); } Quote Link to comment Share on other sites More sharing options...
cgartashish Posted July 12, 2019 Author Share Posted July 12, 2019 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. Quote Link to comment Share on other sites More sharing options...
flcc Posted July 12, 2019 Share Posted July 12, 2019 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); } Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted July 13, 2019 Share Posted July 13, 2019 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'); } Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted July 13, 2019 Share Posted July 13, 2019 (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 July 13, 2019 by konstantin magnus Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted July 13, 2019 Share Posted July 13, 2019 (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 July 14, 2019 by konstantin magnus 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.