Jump to content

Return selected sop in Python


zglynn

Recommended Posts

Hey everyone,

I'm trying to return a sop that the user selects. I can do it just fine with:

hou.selectedNodes()

Only problem is I want to tell the using with some kind of prompt to select the sop that he or she wants and press ok. But when I try to use the:

hou.ui.displayMessage()

It locks out houdini's ui and you can't select anything while the dialog prompt is up. With some digging I figured out how to return a node at object level with:

import toolutils
import hou
scene_viewer = toolutils.sceneViewer()
selection = scene_viewer.selectObjects(prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory()))
print selection

And this works great, but when I try do to the same thing for a sop node...

import toolutils
import hou
scene_viewer = toolutils.sceneViewer()
selection = scene_viewer.selectGeometry(prompt = toolutils.selectionPrompt(hou.sopNodeTypeCategory()))
print selection

It returns nothing. It just prints blank space.

I would really appreciate any help.

Thanks,

Zach

Edited by zglynn
Link to comment
Share on other sites


import toolutils
import soptoolutils

activepane = toolutils.activePane(kwargs)
if activepane.type() != hou.paneTabType.SceneViewer:
    raise hou.Error("This tool cannot run in the current pane")

scene_viewer = toolutils.sceneViewer()
nodetypename = "delete"

# Obtain a geometry selection
geo_types = (hou.geometryType.Primitives, )
selection = scene_viewer.selectGeometry(
                "Select the primitives to extract and press Enter to complete",
                geometry_types = geo_types,
                allow_obj_sel = False)

print "This is what you selected: ",selection
selectionList = str(selection).split(' ')
selectionList=selectionList[:-1] # remove lase element which is '' when selectin all primitives in the SOP it returns only ' ' --- PROBLEM - if you want to change the order of all the primitives select one by one excepth the last element
print selectionList


for sop in selection.nodes():
    sop_path = sop.path()

print sop_path

### Last line
scene_viewer.enterCurrentNodeState()

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