salik Posted November 28, 2016 Share Posted November 28, 2016 Hi all, I have written a function that grabs the selection from within the viewport. While it works if I select one or more objects in the viewport, but it does not seems to be working if nothing is selected. I have placed a 'check' to prompt an error should there be no selections, but it does not seems to be working and instead, if there are no selections, as I execute my code, it will prompt me to select some geometries. def selection(): scene_viewer = toolutils.sceneViewer() selected_objects = list(scene_viewer.selectObjects( prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory()), allow_multisel = True, allowed_types = ("geo") ) ) # if nothing was selected. if len(selected_objects) == 0: raise hou.Error("Nothing was selected.") return selected_objects Is it suppose to be like this or am I writing it wrongly somewhere... Quote Link to comment Share on other sites More sharing options...
f1480187 Posted November 28, 2016 Share Posted November 28, 2016 allowed_types=("geo",) Here. Missing comma. Quote Link to comment Share on other sites More sharing options...
salik Posted November 28, 2016 Author Share Posted November 28, 2016 (edited) 1 hour ago, f1480187 said: allowed_types=("geo",) Here. Missing comma. It does not seems to make any difference.. Added that comma in and I am getting the same result where it prompts me to 'select objects. press enter to accept selections'.. Update: Happened to hit Enter by chance and the error will be raised (selection is still empty) Are there any ways in which I can bypass the prompt that is asking me to select objects.. Edited November 28, 2016 by salik Quote Link to comment Share on other sites More sharing options...
f1480187 Posted November 28, 2016 Share Posted November 28, 2016 If something already selected, return it immediately. If nothing is selected, ask for selection and wait for Enter. If nothing was selected, raise hou.Error. That's how this code works for me. I believe 1 and 2 is how selectObjects tool intended to work. Do you want to to skip the second step? There is hou.selectedNodes() function returning a list of nodes currently selected. It's a bit different thing, but it may work for your case, at least by checking for the type of it's contents. Maybe there is better built-in ways, but I didn't find it inside toolutils and objecttoolutils modules. 1 Quote Link to comment Share on other sites More sharing options...
salik Posted November 28, 2016 Author Share Posted November 28, 2016 24 minutes ago, f1480187 said: If something already selected, return it immediately. If nothing is selected, ask for selection and wait for Enter. If nothing was selected, raise hou.Error. That's how this code works for me. I believe 1 and 2 is how selectObjects tool intended to work. Do you want to to skip the second step? There is hou.selectedNodes() function returning a list of nodes currently selected. It's a bit different thing, but it may work for your case, at least by checking for the type of it's contents. Maybe there is better built-in ways, but I didn't find it inside toolutils and objecttoolutils modules. Ahhh, ok.. Yes I am planning to skip Step 2 if possible. As I am more of a Maya User and just beginning to code for Houdini, I am thinking more in-line with Maya instead.. In that case, I can try out hou.selectedNodes() and see how it goes.. I have a question though, about the missing comma.. Does it really matters? I asked, cause it seems to work whether or not there is a comma.. Quote Link to comment Share on other sites More sharing options...
f1480187 Posted November 28, 2016 Share Posted November 28, 2016 (edited) Comma denotes tuple in Python. Without comma it is just a "something inside parentheses". If you implement such a function, you will use type checks and handle strings and tuples in a different manner. The function expecting a tuple. It seems, it does not handle single strings and fails silently. I cannot select anything (step 2 is not working). So, it matters both in general and in the case of the tool. Edited November 28, 2016 by f1480187 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.