Jump to content

Convert a group into string using Python


SciMunk

Recommended Posts

Hello, I'm trying to extract the content of a group into a strings to manually set a 'basegroup' parameter

geo = hou.node("/obj/geo/geowithgroup").geometry()
edges = geo.findEdgeGroup("mygroup").edges()
sel = hou.Selection(edges)
mystring = sel.selectionString(geo)

the line "hou.Selection(edges)" don't work however, I get this issues : 

The attempted operation failed.
Traceback (most recent call last):
  File "hou.session", line 10, in <module>
  File "C:/PROGRA~1/SideFX/HOUDIN~1.360/houdini/python2.7libs\hou.py", line 52675, in __init__
    this = _hou.new_Selection(*args)
TypeError: in method 'new_Selection', argument 1 of type 'std::vector<HOM_Prim *,std::allocator<HOM_Prim * > > const &'

I've been looking at the doc for hours now and to me, it seam like it the only way to do that, but I just don't understand why it don't work since I provide to the function what it should expect from the doc : https://www.sidefx.com/docs/houdini/hom/hou/Selection.html

I couldn't find any other way to do that.

 

any help please ?

Link to comment
Share on other sites

43 minutes ago, SciMunk said:

the line "hou.Selection(edges)" don't work however

I'm not a python specialist, but if your goal is to get a basegroup string, I would do this:

geo = hou.node("/obj/geo/geowithgroup").geometry()
edges = geo.findEdgeGroup("mygroup").edges()

for i in range(len(edges)) :
    mystring += (edges[i].edgeId()) + " "
    

 

Link to comment
Share on other sites

33 minutes ago, SciMunk said:

this solution don't really give me a smart string for exemple with "p10-p50 100-512" etc

In 17.5.360 this kind of string doesn't work in an edge group node in 'Base Group' parameter.

The best smart is "p-10-11-12-13 p100-101-102-103" and you can check with a variable if the last computed point was the actual minus 1 to replace the result EdgeId()

 

Edited by fsimerey
Link to comment
Share on other sites

my exemple was just informative, I'm looking at the function that convert a list of point/prim/vertex/edge using python into a string the same way the select on viewport work when setting group, there has to be a function for something like that. I just wanna avoid do my own.

Edited by SciMunk
Link to comment
Share on other sites

10 minutes ago, SciMunk said:

my exemple was just informative, I'm looking at the function that convert a list of point/prim/vertex/edge using python into a string the same way the select on viewport work when setting group, there has to be a function for something like that. I just wanna avoid do my own.

Ok, I understand but it's not that difficult, even I can do it:

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

edges = geo.findEdgeGroup("group4").edges()

mystring= ""
last_pt = ""

for i in range(len(edges)) :
    edgestr = edges[i].edgeId()
    s = edgestr[1:].split("-")
    start_pt = s[0]
    end_pt = s[1]
    if last_pt == start_pt :
        mystring += "-"  + end_pt
    else:
        mystring += " p" + start_pt + "-" + end_pt
    last_pt = end_pt

 

Link to comment
Share on other sites

yes, I can do it too, but that really not the point of it, I want to know about an existing houdini function.

a python version can be slow for million of point, houdini version would be c++ based, that why I'm asking .

Edited by SciMunk
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...