magneto Posted November 22, 2011 Share Posted November 22, 2011 I am trying to make a DA using the existing SOPs but I need the existing SOPs such as Point SOP, etc to automatically receive the current selection into their group field without me copy pasting those values. Is this possible? Thanks. Quote Link to comment Share on other sites More sharing options...
3dbeing Posted November 22, 2011 Share Posted November 22, 2011 I'm not sure I completely understand what you are asking but mabye this helps? http://www.sidefx.com/docs/houdini11.0/hom/hou/Selector "Describes how Houdini should prompt the user to choose geometry in the viewport when creating a new SOP node instance." Quote Link to comment Share on other sites More sharing options...
magneto Posted November 22, 2011 Author Share Posted November 22, 2011 (edited) 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 November 22, 2011 by magneto Quote Link to comment Share on other sites More sharing options...
sam.h Posted November 22, 2011 Share Posted November 22, 2011 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 Quote Link to comment Share on other sites More sharing options...
magneto Posted November 22, 2011 Author Share Posted November 22, 2011 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. Quote Link to comment Share on other sites More sharing options...
sam.h Posted November 22, 2011 Share Posted November 22, 2011 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) Quote Link to comment Share on other sites More sharing options...
magneto Posted November 22, 2011 Author Share Posted November 22, 2011 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. Quote Link to comment Share on other sites More sharing options...
magneto Posted November 22, 2011 Author Share Posted November 22, 2011 Also the pattern is valid because I created a sphere, selected half of the points and deleted it using Dissolve and copied the value from its Group field and then deleted the Dissolve SOP. I just used it to get some point sequence. Quote Link to comment Share on other sites More sharing options...
3dbeing Posted November 22, 2011 Share Posted November 22, 2011 (edited) 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 November 22, 2011 by 3dbeing Quote Link to comment Share on other sites More sharing options...
magneto Posted November 23, 2011 Author Share Posted November 23, 2011 (edited) 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 November 23, 2011 by magneto Quote Link to comment Share on other sites More sharing options...
magneto Posted November 23, 2011 Author Share Posted November 23, 2011 Here is an image that shows all the code in my python SOP: Not sure what's causing this issue, as I have a PolygonMesh sphere connected to my SOP. Quote Link to comment Share on other sites More sharing options...
sam.h Posted November 23, 2011 Share Posted November 23, 2011 (edited) I don't think "p" is valid for globPoints. try without the p Edited November 23, 2011 by sam.h Quote Link to comment Share on other sites More sharing options...
graham Posted November 23, 2011 Share Posted November 23, 2011 The problem is that your pattern isn't valid. 0-4 is valid, but p2 isn't. Quote Link to comment Share on other sites More sharing options...
sam.h Posted November 23, 2011 Share Posted November 23, 2011 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 Quote Link to comment Share on other sites More sharing options...
magneto Posted November 23, 2011 Author Share Posted November 23, 2011 Thanks guys. That's what selecting points and adding a Dissolve SOP gave me. I copied it from its Group field, thinking it would be the same. Quote Link to comment Share on other sites More sharing options...
edward Posted November 23, 2011 Share Posted November 23, 2011 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 Quote Link to comment Share on other sites More sharing options...
magneto Posted November 23, 2011 Author Share Posted November 23, 2011 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. Quote Link to comment Share on other sites More sharing options...
3dbeing Posted November 23, 2011 Share Posted November 23, 2011 Great info, thanks Edward! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.