Jump to content

How to expand an edge group in Python HOM?


magneto

Recommended Posts

Hi,

 

If you have an edge group that combines multiple edges like this, i.e. p29-20:

 

kK1UYsB.png

 

How can you expand this edge group so that you can get the full list of edges? Using geo.globEdges shows an edge of (<hou.Edge #29 - 20 of geometry in /obj/grid>), which doesn't exist.

 

Is there a way to expand this edge group?

 

 

Thanks.

Link to comment
Share on other sites

In python:
 

import hou

def test_geo():
    # init test
    n = hou.node('/obj').createNode('geo', run_init_scripts=False)
    n.moveToGoodPosition()
    g = n.createNode('grid')
    grp = n.createNode('group')
    grp.parm('entity').set(2)
    grp.parm('pattern').set('p5-6-7-8-9 p5-4')
    grp.setFirstInput(g)
    grp.moveToGoodPosition()
    grp.setDisplayFlag(True)
    grp.setRenderFlag(True)
    grp.setCurrent(True, clear_all_selected=True)

test_geo()  #prepare geometry for testing


edge_group_points = []
edge_group_pairs = []
for oNode in hou.selectedNodes():
    geo = oNode.geometry()
    for edgeGroup in geo.edgeGroups():  #iterate over existing edge groups
        #print edgeGroup.edges()
        print geo.globEdges(edgeGroup.name())   #same with globEdges

        for edge in edgeGroup.edges():  #iterate over edges in groups
            #print edge
            points = edge.points()      # get points of each edge
            point_numbers = map(hou.Point.number, points)
            point_list_string = map(str, point_numbers)
            #print points
            #print point_numbers
            #print point_list_string
            edge_group_pairs.append(point_numbers)
            for pnt in point_numbers:
                edge_group_points.append(pnt)

print edge_group_pairs

# list of int
print edge_group_points

# string
edge_group_points_string = map(str, edge_group_points)
print ', '.join(edge_group_points_string)

#string (list) of unique points
edge_group_points_string = set(map(str, edge_group_points))
print ', '.join(edge_group_points_string)
   
  • Like 1
Link to comment
Share on other sites

Thanks pezetko. It works. Do you know if there is a way to do this without having an existing group?

 

Because I have a group parameter and if the user types, a group like in my post, then

 

geo.globEdges("p29-20").edges()

 

doesn't work.

 

If not, I will try to create a new group using this parameter, but it would be nice if I can get the edges without doing this as I have to delete the group afterwards, etc.

Link to comment
Share on other sites

Actually it works, but it needs correct input. If you create Group sop and type into Pattern parameter p29-20 you get only one edge in this group (between points 29 and 20) if that edge doesn't exists on the mesh then globEdge("p29-20") returns empty list.
If you create edge selection in viewport and then in viewport you create group sop you get pattern something like this: p29-28-27-26-25-24-23-21-20 (so you get all edges between these points)

 

So you just need sanitize your (or user) input. One way is using group sop.
For processing interactive selection in viewport look at this https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=139675#139675 and just change globPoints to globEdges
For processing user input that is typed manually you need your own parser, that checks if p29-20 edge exists and if not then expand that string to the string of existing edges (p29-28-27-26-25-24-23-21-20).

Edited by pezetko
  • Like 1
Link to comment
Share on other sites

Thanks pezetko, it makes sense. Manually expanding will be too much work I think.

 

I see like you said the Group SOP shows only 1 edge. Since Houdini distinguishes this internally, it would be nice to have a python function to expand these kinds of selections.

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