Jump to content
Sign in to follow this  
konstantin magnus

Python: Loop delete geometry

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

Share this post


Link to post
Share on other sites
On 28.12.2018 at 1:53 AM, petz said:

for high polycount meshes, however, python might be fairly slow ...

Thank you again! It performs nicely for exporting some sliced cityscapes that need 3d printing.

munich_slices.png.2c44d37498b8495847b2f10fd08ded9d.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×