batch export OBJ using attributes to split geometry
642 4 2-
- fs_reddog
- Member
- 7 posts
- Joined: June 2024
- Offline
I've generated a number of different objects (not objects in the Houdini sense) within a single geometry object. I can see from the geometry spreadsheet of my final node, that I have an attribute against the points that make up these objects that can distinguish them from one another. I'd like to set up some sort of foreach node chain that will select each distinct value in this attribute column, and then export only the geometry associated with those points to a file named dynamically by the attribute value. I'm assuming that what seems relatively simple is achievable, but have so far been unable to accomplish it, can anyone help?
-
- alex_sidefx
- Staff
- 5 posts
- Joined: May 2024
- Offline
Hi fs_reddog,
I recently did a similar approach, here's a solution I found.
I have a basic setup where I have a bunch of cubes, and each primitive face has its own random value of a set attribute, called 'test'. Not a very creative name, I know.
You'll likely need to do your own setup in terms of getting the specific mesh not just a primitive face, but this reply should hopefully give you a nudge in the right direction.
![](/forum/attachment/e20b8dbdacbfd636f71c364dec98446d20d4388d/)
We then create a foreach loop over primitives.
We then wrangle our test attribute which is a point float attribute, and convert it to a string detail attribute. Make sure you're running over detail so it doesn't make it a string prim attribute.
![](/forum/attachment/927c69c41b53d190c5c98863c573b9438e7a12cf/)
Then we use a python node to actually run the execute button on our ROP node.
![](/forum/attachment/9da42e5f981ee1819920b0a1dc8a53366f93ab50/)
As for having each file be named dynamically, use this script with details() to grab the string detail attribute on the null node.
![](/forum/attachment/a49b492509fb721441ac4109ca924b2d7fc27b8b/)
And as you can see as the result when you run the loop:
![](/forum/attachment/481f178bd91bcb2bf21f74b84ba4719183bbdf9f/)
Please note this is a fairly hacky solution so that you don't have to leave sops. There are simpler solutions with PDG/TOPs
I recently did a similar approach, here's a solution I found.
I have a basic setup where I have a bunch of cubes, and each primitive face has its own random value of a set attribute, called 'test'. Not a very creative name, I know.
You'll likely need to do your own setup in terms of getting the specific mesh not just a primitive face, but this reply should hopefully give you a nudge in the right direction.
We then create a foreach loop over primitives.
We then wrangle our test attribute which is a point float attribute, and convert it to a string detail attribute. Make sure you're running over detail so it doesn't make it a string prim attribute.
Then we use a python node to actually run the execute button on our ROP node.
As for having each file be named dynamically, use this script with details() to grab the string detail attribute on the null node.
And as you can see as the result when you run the loop:
Please note this is a fairly hacky solution so that you don't have to leave sops. There are simpler solutions with PDG/TOPs
Edited by alex_sidefx - July 12, 2024 12:16:36
-
- Tom_SideFx
- Staff
- 29 posts
- Joined: Jan. 2024
- Offline
-
- fs_reddog
- Member
- 7 posts
- Joined: June 2024
- Offline
alexhsidefx
Please note this is a fairly hacky solution so that you don't have to leave sops. There are simpler solutions with PDG/TOPs
Hi Alex, thanks for the reply. Unless I'm misunderstanding what's going on(which wouldn't be surprising given I'm only just starting out with Houdini), you're going to export each primitive in turn ie each face, rather than each cube separately yes? So for a cube you're going to get 6 files? My use case would be that I want to export each cube in one go. I've already got an attribute against each primitive line in the geometry spreadsheet which is able to group the primitives together.
Tom_SideFxThanks Tom, I've managed to get this to work although I have zero idea HOW it's working but I can now at least do some research.
Hey ! While Alex's example is valid, this is the perfect use case for PDG / TOPs. Here's an example file
Thanks both.
-
- alex_sidefx
- Staff
- 5 posts
- Joined: May 2024
- Offline
-
- Quick Links