Jump to content

How to receive current geometry selection automatically into other SOP


magneto

Recommended Posts

Thanks this might be it. Basically I am looking to implement a python sop like PolyExtrude where you make a prim selection first and then add this PolyExtrude, and PolyExtrude receives your prim selection to act on it.

Or is this something that I have to query from the cooked geometry that's handed to me inside the SOP?

I couldn't find anything that mentions returning selected points/prims other than globPoints but it only accepts stuff regular Group field accepts on OPs.

I am looking for something like this:

geo = hou.pwd().geometry()

geo.selectedPoints()

geo.selectedPrims()

I see there are functions that returns ALL points and prims but I am not looking for those.

Edited by magneto
Link to comment
Share on other sites

As on that page ..... put this on the onLoaded event in you asset:

kwargs['type'].addSelector("Points to Transform", "points",

prompt="Select the points to transform and press Enter to complete")

This is something that you put on a node type, not an instance of a node...

so the selector is added when the definition is loaded, then it is executed when the user makes a new instance of the node... give it a go ...

Maybe you use this argument to get it to load the selection into a group parm .... ? group_parm_name=someparm

Link to comment
Share on other sites

As on that page ..... put this on the onLoaded event in you asset:

kwargs['type'].addSelector("Points to Transform", "points",

prompt="Select the points to transform and press Enter to complete")

This is something that you put on a node type, not an instance of a node...

so the selector is added when the definition is loaded, then it is executed when the user makes a new instance of the node... give it a go ...

Maybe you use this argument to get it to load the selection into a group parm .... ? group_parm_name=someparm

Thanks I will try this now. But I have a few questions. Do I have to load a library for this?

Also where can I find the onloaded event. I thought I only had a single code file for the whole python SOP. If it's on the type properties dialog, I can find it.

I assume if I had selection before adding the OP, this selector would use that instead?

Lastly after the selection is received, how do you retrieve it inside the python SOP? Or are you saying in the onloaded event I should save it into the group field, then read it from there inside the python sop?

I want to deform these selected points not all points in the geometry.

Link to comment
Share on other sites

Thanks I will try this now. But I have a few questions. Do I have to load a library for this?

should just work without doing anything special

Also where can I find the onloaded event. I thought I only had a single code file for the whole python SOP. If it's on the type properties dialog, I can find it.

On the Scripts tab in type properties, down the bottom-left there is an event handler drop-down, that will let you add more modules.

I assume if I had selection before adding the OP, this selector would use that instead?

Yeah I would think that if the node is created in the viewport that it is automatic .... but i don't know.

Lastly after the selection is received, how do you retrieve it inside the python SOP? Or are you saying in the onloaded event I should save it into the group field, then read it from there inside the python sop?

The class docs seem to suggest it is loaded into the 'group' parm automatically, or any parm you specify with the group_parm_name argument (has to be a string i assume)

Link to comment
Share on other sites

Thanks for your answers. Before automatically hooking up the Group field, I filled it manually, and attempted to get it using this code but globPoints throws "Invalid Pattern" exception:

pattern = hou.ch("group")

if pattern == "":

points = geo.points()

else:

points = geo.globPoints(pattern)

Am I missing something?

Thanks.

Link to comment
Share on other sites

pattern = hou.ch("group")

if pattern == "":

points = geo.points()

else:

points = geo.globPoints(pattern)

Am I missing something?

Thanks.

fist I'm not understanding why you are using hou.ch()? That is a chanel reference to a value

ok.. i found the snippit of code you were going off.. this is a bit confusing to me, cuz I though hou.ch replcaced ch()

http://www.sidefx.com/docs/houdini11.1/hom/hou/ch

so... this is what your snipet says in the docs...

#This code will work from inside a Python SOP, but not from the Python

# shell. It assumes the Python sop has the following parm tuples:

# group: A string containing which points to affect

so hou.ch() is not refing a group inside houdini but a string called group in python.

again not enitrely sure what you mean but maybe this helps?

# Return points 5, 10 to 20, and those in group1.

geo.globPoints("5 group1 10-20")

so if you have a group called group1 globPoints will return a tuple of those points

if you have a string var called group inside python in the format group = "1 2 3 4 5-10"

geo.globPoints("group") will return those points in tuple format.

it would be helpful if you could post a simple file of your problem, just to be sure im not going down a wrong path and wasting both our time.

thanks,

-=3db

Edited by 3dbeing
Link to comment
Share on other sites

Thanks, I actually used evalParam (or whatever it was called) before, but when I saw that snippet under geo.globPoints, I assumed that's the way to go.

Mine is also a python SOP, where I added a string parameter called "group". So from there I thought this line:

pattern = hou.ch("group")

would actually retrieve a string representation of that field/textbox and then when I pass it to globPoints, it would then give me the points that correspond to those values, like in your example.

Also if you use:

print pattern

you can see it actually contains a string value of whatever I typed into my "group" field/texbox. So hou.ch() works.

But passing that string to globPoints doesn't work.

I will attach the python sop, which has no code other than this, so maybe some Houdini guru can see what's wrong.

Edited by magneto
Link to comment
Share on other sites

for example:

>>> n = hou.node('/obj/box_object1/box1')
>>> g = n.geometry()
>>> g.globPoints("0")
(<hou.Point #0 of geometry in /obj/box_object1/box1>,)
>>> g.globPoints("0-1")
(<hou.Point #0 of geometry in /obj/box_object1/box1>, <hou.Point #1 of geometry in /obj/box_object1/box1>)
>>> g.globPoints("p0-1")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/asset/common/software/thirdparty/houdini/11.0.775-build1/arch/linux-any/x86_64/houdini/python2.6libs/hou.py", line 144
03, in globPoints
    return _hou.Geometry_globPoints(*args)
OperationFailed: The attempted operation failed.
Invalid pattern

Link to comment
Share on other sites

Thanks this might be it. Basically I am looking to implement a python sop like PolyExtrude where you make a prim selection first and then add this PolyExtrude, and PolyExtrude receives your prim selection to act on it.

First take a look at the code for some of the shelf tools and then look at the source code in $HFS/houdini/python2.6libs/soptoolutils.py ... Lots of useful stuff there for you to use in your own shelf tool. In particular, examine the soptoolutils.genericSopNodeFilterTool() method to get a better idea of how things hang together. The short of it is that you can just call hou.SceneViewer.selectGeometry() which will either use the current selection or prompt for one if there's no current selection. Then once you have the selection, you can use it to create your node and set into its group parameter.

For a more general overview of how tools work, see this white paper:

http://www.sidefx.co...=966&Itemid=265

Link to comment
Share on other sites

First take a look at the code for some of the shelf tools and then look at the source code in $HFS/houdini/python2.6libs/soptoolutils.py ... Lots of useful stuff there for you to use in your own shelf tool. In particular, examine the soptoolutils.genericSopNodeFilterTool() method to get a better idea of how things hang together. The short of it is that you can just call hou.SceneViewer.selectGeometry() which will either use the current selection or prompt for one if there's no current selection. Then once you have the selection, you can use it to create your node and set into its group parameter.

For a more general overview of how tools work, see this white paper:

http://www.sidefx.co...=966&Itemid=265

Thanks Edward. I didn't think of looking at the shelf tools because I thought python SOPs and python shelf tools are different in terms of getting selection, etc.

But if you recommend so, I will check them out of course.

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