Jump to content

python interactive shelf tool, Need help


sadhu

Recommended Posts

Hello,

I am creating a shelftool using python script. Part of this script determines if there is any camera in the scene. If there is no camera then it creates one. If there are multiple cameras; it asks, if user still wants to create a camera or want to select from the existing cameras.

 

The problem I am facing is when user decides to select the camera from existing cameras. When user decides to select the camera from existing cameras, first i want to display a message "Select the camera and press ok" then user should select camera from the network editor and press ok. I am not able to select camera from the network editor as network editor is not the current pane (The pane showing the message  "Select the camera and press ok" is the current pane )

 

This script works well if i select the camera first and then run this script but not when first I run the script and ask user to select camera and press ok. It seems that this is an active window issue . If i manage to set network editor as active window even when displaying the message window this script will work.

 

Please help me, let me know if there is any better way of doing this. I am learning python.

 

Create couple of camera objects and run this python script. This is a part of the script , it assumes that there are multiple cameras in the scene and asks user to select the camera.

 

Thanks a lot

:)

inputcam = hou.ui.displayMessage("There is already a camera in the Scene. Do you want to create a New camera or select from the existing cameras ?", buttons =("New","Select","Cancel"))
if inputcam ==0:
    hou.node("/obj").createNode("cam","MyCAMERA")
if inputcam ==1:
    choice = hou.ui.displayMessage("Select camera and press Enter") 
    #print choice
    if choice == 0:
        selectedcam = len(hou.selectedNodes())
        if selectedcam >1:
            hou.ui.displayMessage("You have selected more than one object, please select object of 'cam' type ")
        if selectedcam == 0:
            hou.ui.displayMessage("You have not selected any camera")
            
        if selectedcam == 1:
            camselected = hou.selectedNodes()     
            hou.ui.displayMessage((camselected[0].name()))





Link to comment
Share on other sites

Rather than interactively try to select a camera node or using hou.selectedNodes() I would personally just pop up a list chooser (hou.ui.selectFromList()) that contained a list of all the available cameras and the user would just select from there.

Link to comment
Share on other sites

I'm guessing the problem is because the displayMessage() dialog is modal, and that prevents the user from selecting anything (anywhere) in the Houdini interface. So an alternative is to get the active scene viewer and do selectObjects() on it. You should be able to set the allowed_types to only "cam".

Link to comment
Share on other sites

Thanks a lot Graham and Edward for your help.

@ Graham - I implemented what you suggested and its working as expected.

@ Edward -  I didnt get much time to try what you suggested. I will try it soon. If needed I will ask for your help. 

 

Thanks again for your time.

:)

Link to comment
Share on other sites

Hello. I am back again.

Continuing the above topic,  I should be able to select the nodes in the network view port when the display message window (hou.ui.displayMessage()) asks you to select the nodes.

I did this using hou.ui.selecFromList() but in some cases I prefer to select the nodes in the network viewport than selecting them from list.

I came across help documents /ref/windows/edittools and tried following script

 

import toolutils
 
sceneview = toolutils.sceneviewer()
prompt = toolutils.selectionPrompt(hou.sopNodeTypeCategory())
selection = sceneview.selectObjects(prompt)
 
it prompts me to select object and press enter but nothing happens when I do that and python shell stops working.  
There is also a tip in the document 
 
" If you try to test the scene_viewer.select methods in the python shell window, it may seem to freeze or not do anything. This is because the prompt only appears when the mouse is over the viewer"
 
I can see the prompt , select the objects and press enter but nothing happens. python shell remains unresponsive no matter where my cursor is.
 
Please  let me know what am I doing wrong.  I want to get the list of names  of objs selected in the network view port.
Link to comment
Share on other sites

little progress.

If i run this from hou.session 

    def test()

        import toolutils
        import hou
        sceneview = toolutils.sceneviewer()
        prompt = toolutils.selectionPrompt(hou.sopNodeTypeCategory())
        selection = sceneview.selectObjects(prompt)
        return selection
 
and use this in python shell
hou.session.test()
It prompts me to select objects and press enter. I  select objs in the network editor , make sure that cursor is in the scene view port and then hit enter.
it is giving me  tuple but in linux shell from which I am opening Houdini.  When I hit escape there then python shell in the houdini becomes active again. Any reason why this is happening ? 
Edited by sadhu
Link to comment
Share on other sites

Hello.

Stuck with another problem. If i run the above mentioned selection method repetitively one after another to select different set of objects , it doesn't work the second time and return the result of the first selection as result of second time selection. 

 

 

        import toolutils
        import hou
       
        sceneview = toolutils.sceneviewer()
        prompt = toolutils.selectionPrompt(hou.sopNodeTypeCategory())
        selection = sceneview.selectObjects(prompt)
        print selection
 
        
        (####  To select different objects for some other operation)
        newsceneview = toolutils.sceneviewer()
        newprompt = toolutils.selectionPrompt(hou.sopNodeTypeCategory())
        newselection = newsceneview.selectObjects(newprompt)
        print newselection
 
 
 in this case , second time it doesn't prompt user to select objects but return the result of the first time selection.  
How to come out of the first time selection process? 
 
Thanks
 :)
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...