Query amount of primitives in a primitive group?

   6483   3   1
User Avatar
Member
77 posts
Joined: July 2006
Offline
I'm trying to figure out how to find the primitive group with the largest amount of primitives in it. Is there a Python function for querying primitive counts of primitive groups? I would expect there to be since you get the prim group list and number of primitives when you middle mouse click on a node.
As a start I tried getting a list of primitives from my node: hou.hscriptExpression(primgrouplist(“/obj/geo1/partition1”))

That didn't seem to work too well.
Anyone have any pointers on how to approach this?
User Avatar
Member
7025 posts
Joined: July 2005
Offline
If you get the contents of the primgroup, you can count the contents with the argc() function.

You'd have to iterate over all prim groups to find the one with the largest number in it of course.

I think you're on the right track!

Cheers,

Peter B
User Avatar
Member
77 posts
Joined: July 2006
Offline
Thanks Peter,

I took a little while, but I finally got a method that works:

p = ‘primgrouplist(“/obj/geo1/partition1”)’
t = hou.hscriptExpression(p)
items = t.split()
d1 = {}
for i in items:
r = ‘primlist(“/obj/geo1/partition1”,’+ i +')'
c = hou.hscriptExpression(r)
primcount = len(c.split())
d1 =
hiCount_primGroup = max(d1, key=lambda x: d1)

Probably the biggest pain was figuring out the syntax for using hscript expressions in Python.

Still easier than doing it by hand for
1500 objects though!
User Avatar
Member
7025 posts
Joined: July 2005
Offline
Yeah, to be honest I still use Hscript for all expression work, but Python for more general scripting. Thanks for posting this though, it helps me think about it Pythonically too

One thing I'm a bit concerned about is speed of Hscript vs Python especially if you're running the expression in a node's Parameter. My initial tests (admittedly a year ago) showed Hscript about 3x faster, but like I said, I haven't tested it recently.

Cheer,s

Peter B
  • Quick Links