Jump to content

Bug? attribute value dont refresh in a loop


pangzi2015

Recommended Posts

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;
 
 post-13172-0-06946900-1455759149_thumb.j
And result in the termial as below:
 post-13172-0-66908400-1455759183_thumb.j
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.
post-13172-0-89279300-1455759198_thumb.j
Any help to write the value in the loop?

TEST.hipnc

Edited by pangzi2015
Link to comment
Share on other sites

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

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

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