HOM question: Querying current selected point.

   4349   1   0
User Avatar
Member
52 posts
Joined: 6月 2009
Offline
Hello everyone,

What is the HOM command to query the currently selected point.?

Thanks in advance.
User Avatar
Member
1922 posts
Joined: 11月 2006
Offline
To query the selected point(s) you'll have to perform a geometry selection in your viewport. If you have things already selected then you'll just get the information right away but if not you'll have to select something. Having to perform a selection might not be ideal but there is no other way to access the information since it is highly dependent upon the viewer.

Something like this allows you to get/prompt for the information and the filter the result to get a tuple of hou.Point objects that are selected.

import toolutils
viewer = toolutils.sceneViewer()
# Try to select some points. If we hit Esc while selecting we need to catch
# the exception and return an empty tuple.
try:
selection = viewer.selectGeometry(“Select point(s) to query.”, geometry_typeshou.geometryType.Points,), allow_obj_sel=False)

except hou.OperationInterrupted:
return ()
# Get the selected point numbers. If we selected every point or none at
# all this will be an empty string.
pt_nums = selection.mergedSelectionString()

# If we selected anything then there will be a reference to the node whose
# geometry we selected.
if len(selection.nodes()) > 0:
# Get the geometry.
geo = selection.nodes().geometry()
# Since we have a valid node and the selection string is empty we know
# we selected all points in the geometry so we just return the list of
# all points.
if len(pt_nums) == 0:
return geo.points()
# We selected only some points so we glob for them
else:
return geo.globPoints(pt_nums)
# No points were selected so return an empty tuple.
else:
return ()
Graham Thompson, Technical Artist @ Rockstar Games
  • Quick Links