List Primitives inside bounding box

   5151   6   1
User Avatar
Member
106 posts
Joined: June 2011
Offline
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
User Avatar
Member
512 posts
Joined: July 2009
Offline
a cheap and quick way would be to blast the prims that you've selected with the bounding box and type this in your textport:


/ -> cd /obj/grid_object1/
/obj/grid_object1 -> echo `primgrouplist(“./blast1”)`

Attachments:
primGroupList_example_Manu.hip (111.8 KB)

http://vimeo.com/user2522760 [vimeo.com]
http://stormbornvfx.com/ [stormbornvfx.com]
Manuel Tausch
User Avatar
Member
106 posts
Joined: June 2011
Offline
Thanks Manuel. But Can I do this using Python. I want to list the primitives inside the bounding box and the groups they belong to.
User Avatar
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]
this is not a science fair.
User Avatar
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 ?
User Avatar
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())
http://vimeo.com/user2522760 [vimeo.com]
http://stormbornvfx.com/ [stormbornvfx.com]
Manuel Tausch
User Avatar
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!!
  • Quick Links