[Sidefx-houdini-list] HOM changing geometry selection

Tom Nixon ignivomous at gmail.com
Fri Jul 28 14:14:54 EDT 2017


Cool Andy, pretty close to what I've done. Thanks for the nudge in the
right direction, guys!

On Thu, Jul 27, 2017 at 3:56 PM, Andy Nicholas <andy at andynicholas.com>
wrote:

> Hi Tom,
> Glad you’ve got it working now.
>
> I was having a play with this as it’s a useful thing to have anyway, and
> I’ve simplified the soputils.selectGroupParm() function to become the
> selectGeometry() function below. There’s a small test function at the
> bottom to demo it. To get it to work, do the following:
>
> 1) Start a new scene
> 2) Open the Python Source Editor, paste all the code in below and click
> Accept.
> 3) In /obj create a Geometry node called “geo1”
> 4) Inside “geo1” create a sphere called “sphere1”
> 5) Make sure you set the sphere Primitive Type to “Polygon” with a
> frequency of 10.
> 6) Open a python shell and type “hou.session.test()” and hit enter. You
> should enter an interactive selection prompt to pick points. Once you’ve
> done so, it’ll print out the result in the Python shell.
>
> As you can see, you can pass it an initial selection and you can tell it
> to pick Points, Primitives, or Edges.
>
> Cheers,
> Andy
>
>
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>
>
> import soputils
> import toolutils
> import itertools
>
> def selectGeometry(selectionnode, initsel, initseltype =
> hou.geometryType.Points, ordered=False):
>
>     selectionnodeparent = selectionnode.parent()
>
>     # Find a scene viewer
>     pane = toolutils.sceneViewer()
>     if pane is None:
>         showError("Can't find Scene Viewer to select group.")
>         return
>
>     # Remember old selection settings, and set new values as needed.
>     state = {}
>     soputils.stashViewportState(pane, selectionnode, state)
>     pane.setPickingCurrentNode(False)
>     pane.setPwd(selectionnodeparent)
>     selectionnode.setDisplayFlag(True)
>     hou.ui.waitUntil(lambda: True)
>
>     pane.setPickGeometryType(initseltype)
>
>     selstr=""
>
>     try:
>         sel = pane.selectGeometry(
>                     prompt ='Select ' + str(initseltype).split(".")[1].lower()
> + \
>                             '. Press Enter when done.',
>                     use_existing_selection=False,
>                     initial_selection=initsel,
>                     initial_selection_type=initseltype,
>                     ordered=ordered,
>                     geometry_types=(initseltype,),
>                     allow_obj_sel=False,
>                     allow_other_sops=False)
>
>         # Make sure we got a selection from exactly one node.
>         if sel is not None:
>             selstrs = sel.selectionStrings()
>             if len(selstrs) > 0:
>                 # try to get the selection associated with selectionnode
>                 for selnode, nodeselstr in itertools.izip(sel.nodes(),
> selstrs):
>                     if selnode == selectionnode:
>                         selstr = nodeselstr
>                         break
>                 else:
>                     # if we can't find selectionnnode just use the first
>                     # selection string
>                     selstr = selstrs[0]
>             else:
>                 selstr = ""
>
>     except:
>         pass
>
>     # Restore the old viewport and node states stored above.
>     soputils.restoreViewportState(pane, selectionnode, state)
>     return selstr
>
>
> def test():
>     selection_node = hou.node('/obj/geo1/sphere1')
>     initsel = "0-20";
>
>     selstr = selectGeometry(selection_node, initsel,
> hou.geometryType.Points, False)
>     print selstr
>
>
>
>
>
>
> > On 27 Jul 2017, at 23:18, Tom Nixon <ignivomous at gmail.com> wrote:
> >
> > Looks like you were both right. Andy pointed me to the code that got me
> > sorted out regarding the selectGeometry function. I had to explicitly
> > set use_existing_selection=False
> >
> > Thanks!
> >
> > On Thu, Jul 27, 2017 at 10:57 AM, Tom Nixon <ignivomous at gmail.com>
> wrote:
> >
> >> Hi Chris,
> >>
> >> Thanks for the suggestion. I'm afraid toolutils.sceneViewer().
> selectGeometry()
> >> doesn't seem to have a way to skip the prompt, and I haven't found a
> way to
> >> give it an arbitrary initial selection.
> >>
> >> Cheers
> >>
> >> On Thu, Jul 27, 2017 at 7:14 AM, Chris Rydalch <crydalch at gmail.com>
> wrote:
> >>
> >>> Not sure if this is helpful, but toolutils has a way to prompt for
> >>> geometry
> >>> selection in the viewport:
> >>>
> >>>>>> import toolutils
> >>>>>> toolutils.sceneViewer().selectGeometry()
> >>>
> >>> The selectGeometry() method has some arguments for what type of
> geometry
> >>> to
> >>> select.
> >>>
> >>> On Thu, Jul 27, 2017 at 3:44 AM, Andy Nicholas <andy at andynicholas.com>
> >>> wrote:
> >>>
> >>>> Hi Tom,
> >>>> I’ve got half an answer for you. If you create a string parm on some
> >>> node
> >>>> and fill it with point IDs, you can use the following python code to
> >>> load
> >>>> it as a selection in the current viewer, edit it, and set it back to
> the
> >>>> original parameter. It basically works a bit like the “re-pick” button
> >>> for
> >>>> group parameters.
> >>>>
> >>>> # Set these up to point at your node and string parameter name
> >>>> this_node = hou.node('/obj/geo1/subnet1')
> >>>> parm_name = "point_group_str"
> >>>>
> >>>> kwargs={}
> >>>> kwargs["node"] = this_node
> >>>> kwargs["parmtuple"] = n.parmTuple(parm_name)         # The name of the
> >>>> parameter to read/write
> >>>> kwargs["geometrytype"] = hou.geometryType.Points    # The geometry
> type
> >>> of
> >>>> the ids in the parameter
> >>>> kwargs["inputindex"] = 0
> >>> #
> >>>> The input index of the node
> >>>> soputils.selectGroupParm(kwargs)
> >>>>
> >>>> So the code you need is all in the soputils.selectGroupParm()
> function.
> >>>> That’s why I’m saying this reply is only half an answer, as you’ll
> need
> >>> to
> >>>> copy that function and reduce it down to the fundamental functionality
> >>> that
> >>>> you need. The important call is to “selectGeometry()" at line 300.
> It’s
> >>>> undocumented and I’ve not had time to figure out the exact parameter
> >>> values
> >>>> you need to pass it to get what you’re after, but I’m fairly sure you
> >>>> should be able to get what you need.
> >>>>
> >>>> Hope that helps,
> >>>> Andy
> >>>>
> >>>>
> >>>>> On 27 Jul 2017, at 00:20, Tom Nixon <ignivomous at gmail.com> wrote:
> >>>>>
> >>>>> Thanks Andy,
> >>>>>
> >>>>> I would like to be able to provide a list of points/prims or their
> >>>> numbers
> >>>>> and have that change the selection in the viewport (feature request
> >>> made
> >>>>> for a tool I have).
> >>>>>
> >>>>> Seems the tools stop short of that ability - unless I'm missing
> >>> something
> >>>>> staring me in the face!
> >>>>>
> >>>>> Cheers
> >>>>>
> >>>>> On Wed, Jul 26, 2017 at 11:24 AM, Andy Nicholas <
> >>> andy at andynicholas.com>
> >>>>> wrote:
> >>>>>
> >>>>>> Check out the second paragraph on this page. I think it explains
> what
> >>>>>> you’re after:
> >>>>>>
> >>>>>> www.sidefx.com/docs/houdini/hom/hou/Selection
> >>>>>>
> >>>>>> Note that you have the constructor functions for hou.Selection where
> >>> you
> >>>>>> can create your own selection object and specify the points,
> >>> primitives,
> >>>>>> etc.
> >>>>>>
> >>>>>> Cheers,
> >>>>>> Andy
> >>>>>>
> >>>>>>
> >>>>>>> On 26 Jul 2017, at 18:49, Tom Nixon <ignivomous at gmail.com> wrote:
> >>>>>>>
> >>>>>>> Sorry, by change, I mean to set explicitly (not grow or shrink an
> >>>>>> existing
> >>>>>>> selection).
> >>>>>>>
> >>>>>>> On Wed, Jul 26, 2017 at 10:42 AM, Tom Nixon <ignivomous at gmail.com>
> >>>>>> wrote:
> >>>>>>>
> >>>>>>>> Hey all,
> >>>>>>>>
> >>>>>>>> I'm just hoping there is now some way to change the geometry
> >>> selection
> >>>>>>>> through HOM. I've come up short in the past, but maybe someone out
> >>>> there
> >>>>>>>> has come across a way to do it?
> >>>>>>>>
> >>>>>>>> Thanks,
> >>>>>>>> Tom
> >>>>>>>>
> >>>>>>> _______________________________________________
> >>>>>>> Sidefx-houdini-list mailing list
> >>>>>>> Sidefx-houdini-list at sidefx.com
> >>>>>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>>>
> >>>>>> _______________________________________________
> >>>>>> Sidefx-houdini-list mailing list
> >>>>>> Sidefx-houdini-list at sidefx.com
> >>>>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>>>
> >>>>> _______________________________________________
> >>>>> Sidefx-houdini-list mailing list
> >>>>> Sidefx-houdini-list at sidefx.com
> >>>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>
> >>>> _______________________________________________
> >>>> Sidefx-houdini-list mailing list
> >>>> Sidefx-houdini-list at sidefx.com
> >>>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>>
> >>> _______________________________________________
> >>> Sidefx-houdini-list mailing list
> >>> Sidefx-houdini-list at sidefx.com
> >>> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
> >>>
> >>
> >>
> > _______________________________________________
> > Sidefx-houdini-list mailing list
> > Sidefx-houdini-list at sidefx.com
> > https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>
> _______________________________________________
> Sidefx-houdini-list mailing list
> Sidefx-houdini-list at sidefx.com
> https://lists.sidefx.com:443/mailman/listinfo/sidefx-houdini-list
>



More information about the Sidefx-houdini-list mailing list