Access points by number in python

   5496   7   1
User Avatar
Member
5 posts
Joined: Dec. 2017
Offline
Does anybody know of a way to access points by number in python? You can access the number of a point by point.number(), but is there a way to get the corresponding point from a given number. Such as providing 2 to get point 2? Thanks
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
Not sure what you mean by “..providing 2 to get point 2”

But the following is something I use sometimes to get a position of a specific point using a parameter to select the point.

At the very end of the last line the zero in square brackets is for accessing the x position value. Just put in 1 and 2 for y and z respectively.

Point_Selected = ch("point_select")
Point_list = hou.node("../sphere1").geometry().points()
if( (Point_Selected >= len(Point_list)) or (Point_Selected < 0)):
Point_Selected = 0

return Point_list[Point_Selected].position()[0]
Edited by BabaJ - Jan. 15, 2018 12:41:23
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
If you have the geo just go:
pt2 = geo.iterPoints()[1]
http://www.racecar.no [www.racecar.no]
User Avatar
Member
5 posts
Joined: Dec. 2017
Offline
The problem is I am storing points in a python dictionary then trying to access these in a different python node that stores new references to points. If I can access them by number then my implementation will work. I am currently accessing the points by checking that their numbers match by
if point.number() == meshPoint.number(): do stuff

The problem with this is the node runs slowly because it's checking all points to find the matching number. If there was a way to getPointFromPointNumber(2) to get point 2. This is what I mean. Thanks.
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Can you store the pointnumbers as keys in the dictionary first. Would give you fast access later.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
5 posts
Joined: Dec. 2017
Offline
That's what I planned to do. I wanted a way to access the points from the point number. I solved the issue though. I can use
geo = node.geometry()
geo.globPoints('2')
To get point 2. Using 2 as an example.
User Avatar
Member
16 posts
Joined: June 2017
Offline
bonsak
Can you store the pointnumbers as keys in the dictionary first. Would give you fast access later.

-b

Hi I placed points numbers into a dictionary and now I am trying to add the points back to a new group but its changed it to a string.

Is there a way to change the string back to a point number? and add it to a group.

Thanks
Imran
User Avatar
Member
1 posts
Joined: July 2018
Offline
how to convert this vex code to python code to use in python sop node?

int pts = primpoints(0, @primnum);

int prim = addprim(0, “poly”);
for(int i=0; i<len(pts); i++){
int pt1 = pts;
int pt2 = pts;
vector pos1 = point(0, “P”, pt1);
vector pos2 = point(0, “P”, pt2);

vector npos1 = pos1 + (pos2-pos1) / 3.0;
vector npos2 = pos1 + (pos2-pos1) * 2.0 / 3.0;
matrix mat = ident();
rotate(mat, radians(-60), set(0, 1, 0));
vector npos3 = npos1 + (pos2 - pos1) / 3.0 * mat;
int npt1 = addpoint(0, npos1);
int npt2 = addpoint(0, npos2);
int npt3 = addpoint(0, npos3);

addvertex(0, prim, pt1);
addvertex(0, prim, npt1);
addvertex(0, prim, npt3);
addvertex(0, prim, npt2);
}

removeprim(0, @primnum, 1);
Edited by thihaA - Dec. 7, 2020 21:12:57
  • Quick Links