Valent Posted November 16, 2018 Share Posted November 16, 2018 Hi! I'm struggling to understand how arrays work Could somebody please explain why am I seeing different results in geometry spreadsheet and in console made by 'printf' function? I mean, why does every primitive in spreadsheet contain the same set of points in its arrays? I'm puzzled. One more question: How can I compare contents of different arrays? primitives_array_q.hipnc Quote Link to comment Share on other sites More sharing options...
Atom Posted November 16, 2018 Share Posted November 16, 2018 You have the same results because you are assigning the i[]@neighs attribute in side a loop, in your case 5 times. So the fifth result is all you will ever see. Maybe you want.. i[]@neighs=primpoints(0, @primnum); instead? 1 Quote Link to comment Share on other sites More sharing options...
davpe Posted November 17, 2018 Share Posted November 17, 2018 hi, maybe take a look at this article: https://vfxbrain.wordpress.com/2018/06/14/using-arrays-with-vex/ 1 Quote Link to comment Share on other sites More sharing options...
Valent Posted November 19, 2018 Author Share Posted November 19, 2018 @AtomIt makes sense, thanks. On 11/16/2018 at 7:22 PM, Atom said: i[]@neighs=primpoints(0, @primnum); no, I need to get 'primpoints' for these five primitives only because I want to check if any of them are direct neighbors. (but I don't need to declare them as an attribute) @davpe Thanks, that was useful. Quote Link to comment Share on other sites More sharing options...
Valent Posted November 19, 2018 Author Share Posted November 19, 2018 (edited) I'm trying to rebuild this wrangle to be able to work on 'detail', but it seems that I can't access @primnum there, what should I use instead? Edited November 19, 2018 by Valent Quote Link to comment Share on other sites More sharing options...
3dome Posted November 19, 2018 Share Posted November 19, 2018 (edited) 1 hour ago, Valent said: I'm trying to rebuild this wrangle to be able to work on 'detail', but it seams that I can't access @primnum there, what should I use instead? @primnum would access the primitive the primitivewrangle currently processes. Since detail wrangles dont run over anything but just one time, you have to build your own loop over primtives for(int i = 0; i != nprimitives(0); ++i) { //do stuff here and instead of @primnum use i } Edit: change the input for nprimitives() according to your needs Edited November 19, 2018 by 3dome 1 Quote Link to comment Share on other sites More sharing options...
Valent Posted November 19, 2018 Author Share Posted November 19, 2018 Thanks, it works!) Btw it looks I can use @numprim instead of nprimitives(0) Quote Link to comment Share on other sites More sharing options...
Valent Posted November 19, 2018 Author Share Posted November 19, 2018 Could you please explain why it works this way? My initial idea was to randomly select primitives, then put selected primitive's numbers to an array. But if you look at the file provided, in one 'wrangle' each of the primitives has their own array which contains that point only. And in another wrangle which differs from the first one only by absence of 'if(faces==@primnum)' all the primitives are in the array. array_append_qq.hipnc Quote Link to comment Share on other sites More sharing options...
3dome Posted November 20, 2018 Share Posted November 20, 2018 (edited) 11 hours ago, Valent said: Could you please explain why it works this way? My initial idea was to randomly select primitives, then put selected primitive's numbers to an array. But if you look at the file provided, in one 'wrangle' each of the primitives has their own array which contains that point only. And in another wrangle which differs from the first one only by absence of 'if(faces==@primnum)' all the primitives are in the array. array_append_qq.hipnc well if you don't understand what your code is doing I suggest learning the foundations of coding first. A primwrangle runs over all primitives, so in the left wrangle, you give every primitive numbers chances that the @primnum==random_number(faces). Only then it is appended to the array, but of course the appended value will be the primnum. The wrangle on the right appends numbers times to the array, no condition applys. The value that gets appended is whatever random_number is generated. Because random_number is not dependend on the current primitive the wrangle iterates over, therefor the array is the same for all prims. If you want different arrays, make the seed change per prim by adding +@primnum after ch("seed") Edited November 20, 2018 by 3dome 1 Quote Link to comment Share on other sites More sharing options...
Valent Posted November 20, 2018 Author Share Posted November 20, 2018 @3dome Thanks, it maketh sense) Can I somehow create the array on detail (because I need all the numbers of the selected primitives to be in one array) while my 'wrangle' works on primitives? Quote Link to comment Share on other sites More sharing options...
acey195 Posted November 20, 2018 Share Posted November 20, 2018 (edited) you can use setdetailattrib() http://www.sidefx.com/docs/houdini16.0/vex/functions/setdetailattrib something like: int yourArray[]; /* stuff to build your array */ string selection = sprintf("selectionOfPrim%d", @primnum); setdetailattrib(0, selection, yourArray); note that, if this is what you actually want to do, its better just to save it as a prim attribute of course. if you just want one attribute, then run the wrangle in detail mode and build rebuild the logic to work with that. (you'll need to change the way you read and write your data) Edited November 20, 2018 by acey195 1 Quote Link to comment Share on other sites More sharing options...
Valent Posted November 20, 2018 Author Share Posted November 20, 2018 Thanks, I've remade my wrangle to be able to run on detail, and it works!) But as a result I have a couple of questions: For some reason I have to split the wrangle into two parts because the last part was not working, but when I made separate wrangle out of it, it worked. and the second question: If I have my wrangle on primitives/points, is it possible to use an array which is on one point/primitive and ignore other point's/primitive's arrays. array_detail_a.hipnc Quote Link to comment Share on other sites More sharing options...
acey195 Posted November 22, 2018 Share Posted November 22, 2018 Hey, didn't have time to check the file, but I have a hunch you used the setdetailattrib(0, "foo", yourArray); and then tried to read from it. This you cannot do inside the same wrangle. all the functions that write attributes, are only applied in the output of the node, not in the local data. so if you want to keep using it, use "yourArray" instead of "detail(0, "foo")" this restriction is not there for bound attribs like: "@foo" to your other question, of course. You can for example use the group parameter at the top of the node, to only process a subset (or a single) of your primitives 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.