Jump to content

Python: Merge into a new geo, the prims of a group


fsimerey

Recommended Posts

  • 3 weeks later...

You can't merge group selectively nor you can't add primitives one by one. You need to have a hou.Geometry() which will contain only the primitives you need, and then hou.Geometry.merge them to main geo. 

 

source_geo = get_geo_from_somwhere()  # source_geo will contain group_A for example
tmp_geo = hou.Geometry()
tmp_geo.merge(source_geo)

# Build a list of prims which are not in group_A
prim_grp = tmp_geo.findPrimGroup("group_A")
prims_to_delete = []
for prim in tmp_geo.prims():
  if not prim_grp.containts(prim):
    prims_to_delete.append(prim)

# Now delete everything except group_A prims    
tmp_geo.deletePrims(prims_to_delete)

# Now tmp_geo contains only prims from group_A
geo.merge(tmp_geo)

 

Link to comment
Share on other sites

Is there a specific reason you need to use python?  

I would bet it's not the call to merge that's slowing you down, but iterating over the prims to build the list, plus the delete call as well.  All in all that's 3 or more iterations per primitive(not including duplicating the geometry).

The fastest way to handle this (outside of using nodes, or VEX) would probably be exposing GEO_Detail::merge to hou, using inlinecpp this way you can merge the prim groups directly.

http://www.sidefx.com/docs/hdk/class_g_e_o___detail.html#ac18c35b3d974d251890af70fd3d5fe2b

 

 Also you could send an RFE to sidefx about it, they may be able to help you.

 

Link to comment
Share on other sites

Yes, i need python because it's an HDA to parse and recreate SVG files (some heavy files from DWG).

But it's not so bad, a file of 175 Mo takes 30-60 sec depending the numbers of paths/groups/attributes/transforms.

Thanks anyway, but i'm not a programmer, i know python and vex but not c++ ;)

Link to comment
Share on other sites

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...