Access points by number in python
5504 7 1- carmo
- Member
- 5 posts
- Joined: Dec. 2017
- Offline
- BabaJ
- Member
- 2038 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.
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
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- carmo
- 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
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.
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.
- bonsak
- Member
- 459 posts
- Joined: Oct. 2011
- Offline
- carmo
- Member
- 5 posts
- Joined: Dec. 2017
- Offline
- im_a
- 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
- thihaA
- 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);
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