pangzi2015 Posted February 18, 2016 Share Posted February 18, 2016 (edited) Hi, everyone! Recently i am packaging an otl , a question occur to me. To simplify, i create a point , then create an attribute called "test". Finally i add a wrange node , code as below; And result in the termial as below: So , it turned out that the setpointattrib function didnt actually write the value to the attribute , maybe write to the cache? When i right click the pointwrangle2 node, select Spreadsheet , you can see , at the end it changed.Any help to write the value in the loop? TEST.hipnc Edited February 18, 2016 by pangzi2015 Quote Link to comment Share on other sites More sharing options...
Atom Posted February 18, 2016 Share Posted February 18, 2016 (edited) What did you expect, you only have one point? The last value from the loop gets stored on the test attribute for the only point that exists. You are also using i twice you realize? You are clobbering your loop value with the return value from getattrib. Code no-no 101. If you want four attributes you need four points. But there is no reason to run from the Details context to Manipulate Point attributes. Simply set the wrangle to run over Point attributes to begin with then your code will scale as the point count changes. f@test = @ptnum; // Or any float value. int success = 0; int i = getattrib(geoself(),"point","test",@ptnum,success); if (success) { printf("test value:%s \n",i); } @ptnum, takes the place of the i loop variable in your previous code attempt. It is the index of the current point the wrangle is processing. ap_TEST_point_attribute.hipnc Edited February 18, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
pangzi2015 Posted February 19, 2016 Author Share Posted February 19, 2016 (edited) Thanks for your answer Atom!sorry for the typo, and it has many points , pointwrangle is good, but it is multi-thread in which case maybe one thread changed the attribute value ,and the other thread read the unchanged value. I just want to simpify the question , concentrate on the obstacle. I made a more accurate Hip File ,and compare the value after the setattrib funtion, it is not consistent! test_1.hipnc Edited February 19, 2016 by pangzi2015 Quote Link to comment Share on other sites More sharing options...
Atom Posted February 19, 2016 Share Posted February 19, 2016 (edited) Quit thinking of Detail as some kind of master loop where you can control everything. It is mainly used if you want to attach a global variable to an object. However, you can modify your PointWrangle3, which is running over points. int i = 10; printf("%s : %s\n",@ptnum,i); setpointattrib(geoself(),"set_index",@ptnum,i,"set"); printf("%s : %s\n",@ptnum,@set_index); There is no need to make the second getattrib call when running over points. Simply fetch the attribute name directly using the @ symbol. You can also break your read and writes into two separate wrangles to verify the success of your initial setattrib. Write Wrangle: int success; int i = 0; { for(int j=0;j<4;j++) { setattrib(geoself(),"point","set_index",j,-1,i,"set"); printf(">%s : %s\n",j,i); } } Read Wrangle: int success; { for(int j=0;j<4;j++) { int vv = getattrib(geoself(),"point","set_index",j,success); printf("<%s : %s\n",j,vv); } } Edited February 19, 2016 by Atom Quote Link to comment Share on other sites More sharing options...
pangzi2015 Posted February 20, 2016 Author Share Posted February 20, 2016 Thank you so much , Atom! That`s awesome. 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.