Jump to content
mrcoolmen

store point number in array

Recommended Posts

mrcoolmen    0

Hey,

 

thank you so much for your time to look at my post, just wondering how to store the point number in a attribute arrary?

 

what i mean is if i have 4 points how can i loop through the point and get i[]@myarray={1,2,3,4} ?

 

Share this post


Link to post
Share on other sites
mrcoolmen    0
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?

 

 

Share this post


Link to post
Share on other sites
ikoon    102

@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);

Share this post


Link to post
Share on other sites
petz    306

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

Share this post


Link to post
Share on other sites
Hartman-    4
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!

Share this post


Link to post
Share on other sites
Hartman-    4
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×