batch export OBJ using attributes to split geometry

   912   4   2
User Avatar
Member
8 posts
Joined: 6月 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?
User Avatar
スタッフ
5 posts
Joined: 5月 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.


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 - 2024年7月12日 12:16:36

Attachments:
Screenshot_3.png (870.2 KB)
Screenshot_7.png (93.2 KB)
Screenshot_1.png (93.9 KB)
Screenshot_2.png (119.5 KB)
Screenshot_8.png (74.0 KB)

User Avatar
スタッフ
37 posts
Joined: 1月 2024
Offline
Hey ! While Alex's example is valid, this is the perfect use case for PDG / TOPs. Here's an example file

Attachments:
export_pieces.hip (120.2 KB)

User Avatar
Member
8 posts
Joined: 6月 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_SideFx
Hey ! While Alex's example is valid, this is the perfect use case for PDG / TOPs. Here's an example file
Thanks 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.

Thanks both.
User Avatar
スタッフ
5 posts
Joined: 5月 2024
Offline
Hi fs_reddog.

I was showing you a proof of concept for how you would use a for loop to export based on an attribute. I used primitives as an example. My solution is fairly hacky and was more valid a year ago but PDG can do this much more efficiently, I'd suggest going with Tom's route.
  • Quick Links