Hi guys
I have a geometry with n number of primitives. I've a grouped a portion of the geometry by bounding box. How do I get the list of primitives selected in the bounding box and the primgroups those primitives belong to?
Any help much appreciated.
Thanks
List Primitives inside bounding box
5409 6 1- jjayakumar
- Member
- 106 posts
- Joined: June 2011
- Offline
- asnowcappedromance
- Member
- 512 posts
- Joined: July 2009
- Offline
- jjayakumar
- Member
- 106 posts
- Joined: June 2011
- Offline
- rdg
- Member
- 401 posts
- Joined:
- Offline
All primitives in your group:
hou.Geometry.findPrimGroup
All primitive groups:
hou.Geometry.primGroups
Is a primitive in a group:
hou.primGroup.contains
Houdini python help:
http://www.sidefx.com/docs/houdini12.0/hom/ [sidefx.com]
hou.Geometry.findPrimGroup
All primitive groups:
hou.Geometry.primGroups
Is a primitive in a group:
hou.primGroup.contains
Houdini python help:
http://www.sidefx.com/docs/houdini12.0/hom/ [sidefx.com]
this is not a science fair.
- jjayakumar
- Member
- 106 posts
- Joined: June 2011
- Offline
Thanks for your reply. But hou.Geometry.findPrimGroup takes the group name as argument which is not what I'm looking for. I have a set of selected primitives from two different primgroups in a bounding box. I need to find what are the two primgroup names that those selected primitives belong to. How do I get that using python ?
- asnowcappedromance
- Member
- 512 posts
- Joined: July 2009
- Offline
unfortunately there's no way of accessing a primitive's groups directly, like rdg said you have to do it the other way around:
>>> geo = hou.node('/obj/grid_object1/boundGroup').geometry()
>>> foundGroups =
>>> groupList =
>>> bound = geo.findPrimGroup(“boundGroup”)
>>> bound
<hou.PrimGroup boundGroup of geometry in /obj/grid_object1/boundGroup>
>>> for g in geo.primGroups():
… if g.name() != bound.name():
… groupList.append(g)
>>> for i in bound.prims():
… for j in groupList:
… if not j.name() in foundGroups and j.contains(i) == True:
… foundGroups.append(j.name())
>>> geo = hou.node('/obj/grid_object1/boundGroup').geometry()
>>> foundGroups =
>>> groupList =
>>> bound = geo.findPrimGroup(“boundGroup”)
>>> bound
<hou.PrimGroup boundGroup of geometry in /obj/grid_object1/boundGroup>
>>> for g in geo.primGroups():
… if g.name() != bound.name():
… groupList.append(g)
>>> for i in bound.prims():
… for j in groupList:
… if not j.name() in foundGroups and j.contains(i) == True:
… foundGroups.append(j.name())
- jjayakumar
- Member
- 106 posts
- Joined: June 2011
- Offline
Thanks Manu. It works perfectly. Here's what I came up with.
p = ‘primlist(“/obj/sphere_object1”, “boundGroup”)’
r = hou.hscriptExpression(p)
nums = r.split()
g = ‘primgrouplist(“/obj/sphere_object1”)’
t = hou.hscriptExpression(g)
items = t.split()
list =
for num in nums:
for grp in items:
m = ‘hasprim(“’+str(grp)+'”,“/obj/sphere_object1”,“' + str(num) + ‘”)’
n = hou.hscriptExpression(m)
if n == 1.0:
if not grp in list and grp != “boundGroup”:
list.append(grp)
print list
I'm not sure whether I'm doing it the right way but it gives the result. I hope it helps others also.
Thank you so much!!
p = ‘primlist(“/obj/sphere_object1”, “boundGroup”)’
r = hou.hscriptExpression(p)
nums = r.split()
g = ‘primgrouplist(“/obj/sphere_object1”)’
t = hou.hscriptExpression(g)
items = t.split()
list =
for num in nums:
for grp in items:
m = ‘hasprim(“’+str(grp)+'”,“/obj/sphere_object1”,“' + str(num) + ‘”)’
n = hou.hscriptExpression(m)
if n == 1.0:
if not grp in list and grp != “boundGroup”:
list.append(grp)
print list
I'm not sure whether I'm doing it the right way but it gives the result. I hope it helps others also.
Thank you so much!!
-
- Quick Links