Jump to content

Python: Loop delete geometry


konstantin magnus

Recommended Posts

I want to export single tiles of a grid by their id attribute with Python.

grid_tiles.png.b9a75e07a5cdc40b03255305660d97fa.png

Because saveToFile() is lacking any filter options, I am trying to use a loop for deleting all redundant primitives before each export.

Unfortunately once primitives have been deleted for the first time, they are gone for all subsequent loops, too.

node = hou.pwd()
geo = node.geometry()

dir_exp = node.evalParm('dir_export')

id_values = geo.primIntAttribValues("id")
id_count = len(set(id_values)) # is there a more hou way to count unique attribute values?

for iteration in range(id_count):
    geo_change = geo
    path_export = dir_exp + 'segment' + str(iteration) + '.obj'
    prims = [p for p in geo_change.prims() if p.attribValue('id') != iteration]
    geo_change.deletePrims(prims) # how can I keep the full geo data for the remaining loops? 
    geo_change.saveToFile(path_export)

How can I keep the full geometry for each loop? And are there any better ways to export geometry parts based on attributes with Python?

 

landscape_slice_export.hiplc

Edited by konstantin magnus
Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...