All is very simple:
using group SOP we selected few points, after we want to use them in Python script, but I have no idea how to get list of this points.
in the python code it would looks like:
G = getPointsFromGroup(“GroupName”)
for pt in G:
…
Thank you very much.
Python. How address points in group?
8029 5 2- Suvo
- Member
- 19 posts
- Joined: July 2005
- Offline
- symek
- Member
- 1390 posts
- Joined: July 2005
- Offline
Maybe someone can correct me if I'm wrong but it seams that groups are not implemented yet in general. I hardly can find any groups related method in docs nor docstring.
Your issue is doable via hscript though, for example like this:
geo = hou.pwd().geometry()
group = hou.pwd().parm(“group”).eval()
path = hou.pwd().parm(“path”).eval()
for point in geo.points():
if hou.hscriptExpression('haspoint(“%s”, “%s”, %s)' % (group, path, point.number())): print point.number()
Now, this snipped assumes that you have two parameters on your PythonSOP, “groups” and “path” namely. “Path” is probably needed because hscript expression raise an error of infinite recursion so we need to evaluate it on previous node. Not sure of that, It just a quick attempt.
Alternative to that approach is generation of group list and iterate on it:
grouplist = hou.hscriptExpression('pointlist(“%s”,“%s”)' % (path, group))
Does it help?
sy.
Your issue is doable via hscript though, for example like this:
geo = hou.pwd().geometry()
group = hou.pwd().parm(“group”).eval()
path = hou.pwd().parm(“path”).eval()
for point in geo.points():
if hou.hscriptExpression('haspoint(“%s”, “%s”, %s)' % (group, path, point.number())): print point.number()
Now, this snipped assumes that you have two parameters on your PythonSOP, “groups” and “path” namely. “Path” is probably needed because hscript expression raise an error of infinite recursion so we need to evaluate it on previous node. Not sure of that, It just a quick attempt.
Alternative to that approach is generation of group list and iterate on it:
grouplist = hou.hscriptExpression('pointlist(“%s”,“%s”)' % (path, group))
Does it help?
sy.
- k0diak
- Member
- 56 posts
- Joined: April 2007
- Offline
To avoid calling the hexpression engine too often (as it could have a performance hit with a large amount of points), you could do something like (combined with SYmek's ideas) to get the indexes of the points. Then on the points of hou.pwd().geometry().points run this as a filter.
Don't forget to cast them to the appropriate type:
pointList = hou.hscriptExpression(“”“pointlist(”/obj/geo1/group1“, group1)”“”).split()
Don't forget to cast them to the appropriate type:
pointList = hou.hscriptExpression(“”“pointlist(”/obj/geo1/group1“, group1)”“”).split()
- symek
- Member
- 1390 posts
- Joined: July 2005
- Offline
- Suvo
- Member
- 19 posts
- Joined: July 2005
- Offline
SYmek and k0diak THANK YOU BOTH VARY MUCH!
It's exactly what necessary!
The final code (if interesting) I use is:
def check(seq, item):
try:
i = seq.index(item)
except ValueError:
i = -1
return i
pointNumbers = map(lambda x: float(x), hou.hscriptExpression('pointlist(“/obj/geo1/group1”, groupName)').split)
points =
So points now has all points which we define in node /obj/geo1/group1 and group name: groupName.
Thanks again to you!!!
It's exactly what necessary!
The final code (if interesting) I use is:
def check(seq, item):
try:
i = seq.index(item)
except ValueError:
i = -1
return i
pointNumbers = map(lambda x: float(x), hou.hscriptExpression('pointlist(“/obj/geo1/group1”, groupName)').split)
points =
So points now has all points which we define in node /obj/geo1/group1 and group name: groupName.
Thanks again to you!!!
- catlee
- Member
- 139 posts
- Joined: July 2005
- Offline
-
- Quick Links