Jump to content
SciMunk

Convert a group into string using Python

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 ?

Share this post


Link to post
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()) + " "
    

 

Share this post


Link to post
Share on other sites

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

Edited by SciMunk

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Ok in that case ask for convert a group in string but not 'Convert a group into string using Python'

Share this post


Link to post
Share on other sites

well, technically speaking, it still using python, but using a houdini existing function ...

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

×