Automatic geometry separation, depending on group membership

   3804   3   0
User Avatar
Member
464 posts
Joined: Aug. 2014
Offline
Hello.

I'm trying to find an automated solution to separate geometry into multiple SOPs depending on group membership.

In the uploaded example. The file SOP contains a geometry that has predefined four groups: smallBox, medBox, largeBox and sphere.

I have separated them manually, by linking multiple Delete SOPs (Delete Non-Selected) to the file SOP - one for each group, but while it's okay when there are only a few groups, it gets tedious when there are more.

What would be the best approach to this problem?
Maybe forEach node? But if so, then how do I determine names of groups to iterate on, if they don't follow some sort of pattern? And how do I fork the pipes later on?

P.S. I realise I can do this with a Python script, but I'd rather like to use nodes if possible.

Attachments:
test_groups.hipnc (77.3 KB)
obj_geometry_file.zip (2.0 KB)

User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
Put * in the Group Mask parameter of for each sop to process all groups.

If you want just save them, put File SOP inside forEach and set the name based on current loop (FORIDXVALUE or FORVALUE stamp expression).

If you want to create forking in the network view, I would use python script to iterate over each group and putting blast/delete sop by it.

E.g.:

import hou
#select file sop
selectedNode = hou.selectedNodes()

groups = selectedNode.geometry().primGroups()
for group in groups:
blastNode = selectedNode.createOutputNode('blast')
blastNode.setName(“keep”+group.name())
blastNode.parm('group').set(group.name())
blastNode.parm('negate').set(1)
User Avatar
Member
464 posts
Joined: Aug. 2014
Offline
pezetko
Put * in the Group Mask parameter of for each sop to process all groups.
If you want just save them, put File SOP inside forEach and set the name based on current loop (FORIDXVALUE or FORVALUE stamp expression).
Thanks for your reply, Pezetko.
I'm running into some problems with this one.
I use “$HIP/output/$FORVALUE.obj” string as a “Geometry File” parameter inside file SOP. I expected from $FORVALUE to assume values of each PrimGroup.name() of the input, similar to loops:
for primGroup in geo.primGroups(): # (…)
with $FORVALUE stamp being the equivalent of the primGroup variable in the example above. Turns out I'm wrong, because when I place the file node just before the ‘each’ node inside the forEach SOP, all I get is just one output file called ‘.obj’ - it doesn't even have a name, just an extension. It contains all groups from the input. What am I doing wrong here?

import hou
#select file sop
selectedNode = hou.selectedNodes()

groups = selectedNode.geometry().primGroups()
for group in groups:
blastNode = selectedNode.createOutputNode('blast')
blastNode.setName(“keep”+group.name())
blastNode.parm('group').set(group.name())
blastNode.parm('negate').set(1)
Yes, this is how I do it ATM.
I understand that it is not possible to fork the flow into n-streams without scripting?
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
Use:
`stamps(“..”, chs(“../forstamp”), “”)`.obj

The back ticks evaluates stamps expression that returns string (Instead of stamp(“..”, “FORVALUE”, “”) expression that returns number). The result is name of each group.obj file (you need to go out of the ForEach SOP to save them all to the disk)
  • Quick Links