Sunday, April 15, 2018

Houville :: Get selections from Scene Views

This is one of those obvious needs that ends up being a frustrating "how do you even..?"

In Houdini 16.5 and up it's pretty simple:
import toolutils
sv = toolutils.sceneView()
str(hou.SceneViewer.currentGeometrySelection(sv))


However in 16.0 it's a bit more fiddly as currentGeometrySelection doesnt exist. hicon:/SVGIcons.index?book.svg
import toolutils
selection = toolutils.sceneViewer().selectGeometry() ## this annoyingly unselects your selection
print selection
## lets also get this in the clipboard so we can past it in a node.
Here's a good reference: https://www.sidefx.com/forum/topic/30353/
As is this in the docs: http://www.sidefx.com/docs/houdini/hom/tool_script.html