Jump to content

store point number in array


mrcoolmen

Recommended Posts

1 hour ago, Hartman- said:

What you want to do here is to run a wrangle as a detail (so it will only run once) and then loop through the points. This way, you can build upon the array and then set the array to each point. See attached file!

Create_Point_Array.hiplc

Hey Hartman,

 

Just a follow up question, the idea of append(points,i) it make sense to me.

 

however, i tried to append a custom attribute than it return me a weird result such as

 

  append(points,@id)

 

den it does not really work, just curious wat did i do wrong?

 

 

Link to comment
Share on other sites

@mrcoolmen

you are running over the detail, so append(points,@id) looks for @id as a detail attribute, you may need to read @ from point first, and then append

for (int i=0; i<@numpt; i++) {
    int id = point(0,"id",i);
    append(points, id);
}

@Hartman-

please, why is this line necessary? and why is it outside the loop?
addpointattrib(0, "allpoints", points);

Link to comment
Share on other sites

to write point numbers to an array in detail mode you could just do:
 

i[]@points = expandpointgroup(@OpInput1, "!");

or in point mode:
 

int point[] = array(@ptnum);
setdetailattrib(geoself(), "points", point, "append");

however, depending on the number of points, the second method might be slightly slower compared to iterating over points in detail mode ...

 

  • Like 4
Link to comment
Share on other sites

3 hours ago, petz said:

to write point numbers to an array in detail mode you could just do:
 


i[]@points = expandpointgroup(@OpInput1, "!");

or in point mode:
 


int point[] = array(@ptnum);
setdetailattrib(geoself(), "points", point, "append");

however, depending on the number of points, the second method might be slightly slower compared to iterating over points in detail mode ...

 

Those are much simpler than mine, now I'm learning!

Link to comment
Share on other sites

6 hours ago, ikoon said:

@mrcoolmen

you are running over the detail, so append(points,@id) looks for @id as a detail attribute, you may need to read @ from point first, and then append

for (int i=0; i<@numpt; i++) {
    int id = point(0,"id",i);
    append(points, id);
}

@Hartman-

please, why is this line necessary? and why is it outside the loop?
addpointattrib(0, "allpoints", points);

It's what made sense to me at the time, it works but I should probably revisit my logic. Was a bit tired when I made the example!

  • 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...