Jump to content

acess previous point attribute in wrangle


vijayakumar

Recommended Posts

Hi guys,

need help in vex. I tried creating an attribute in for loop and access the previous point value . But i couldn't access the created value. Here is the code. in this i am creating an integer a and storing the value. i am trying to use point(geoself) and access the previous point attribute but it defaults to zero. help me out with this.. thanks..

 

int @a=1;
int @test[];
int @inst;
if(@ptnum==0)
@test[0]=1;
for(int i=0;i<=@ptnum;i++)
{
@a=@a+i;
if(@ptnum>0)
{
@inst=point(geoself(),'a',i-1);   //cannot access the previous value
@test=point(geoself(),'a',i-1);

}

}

Link to comment
Share on other sites

You need to do such things in different wrangles, because geometry wrangles are writing attribute values at the very end of execution.

// First Point wrangle.
i@a = (@ptnum+1) * @ptnum / 2;

// Second Point wrangle.
i@a_prev = point(0, "a", @ptnum-1);

 

Or use Detail wrangle, use explicit functions for setting attributes and keep track of previous values manually:

// Detail wrangle.
int a = 0;
int a_prev = 0;

addpointattrib(0, "a", a);
addpointattrib(0, "a_prev", a_prev);

for (int i = 0; i < @numpt; i++)
{
    a_prev = a;
    a = (i+1) * i / 2;

    setpointattrib(0, "a", i, a);
    setpointattrib(0, "a_prev", i, a_prev);
}

The drawback of using Detail wrangle is that you need to use explicit functions, which is a bit more lines of code. It is also single-threaded, but still very fast in most cases.

 

previous_point_value.hipnc

Edited by f1480187
  • Like 1
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...