20.08.2015 Views

TECHNICAL PAPER Building Tools for Houdini 9

TECHNICAL PAPER Building Tools for Houdini 9 - Digital Cinema Arts

TECHNICAL PAPER Building Tools for Houdini 9 - Digital Cinema Arts

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

0003 active_pane = toolutils.activePane(kwargs)0004 if active_pane is not None and \0005 active_pane.type() == hou.paneTabType.ContextViewer:0006 active_pane = active_pane.sceneViewer()0007 if active_pane is None or \0008 active_pane.type() != hou.paneTabType.SceneViewer:0009 raise hou.Error(“The tool was not invoked in the \0010 scene viewer.”)Line 3 uses toolutils.activePane(kwargs) to return whether or not a viewer pane is currently openwhen the tool was pressed.Lines 4 to 6 check to see if a viewer is actually open and available then finds out what context theviewer pane is in. This is what does the actual work. After this it is common to match the viewporttype with a known context to do a specific type of action. The Delete tool is a very good example ofexecuting different actions depending on what context the viewport is in.Lines 7 to 10 throw an error if there was no scene viewer detected making interactive placement ofthe tool impossible.Detecting Selections to use with your asset is a common tool task. Following from the python code abovein the Delete tool, the following lines take the current view type and pull out exactly what is the current nodetype that you have selected.0011 # we determine what selection type we should consider 0011 # (ie, OBJ, SOP,DOP,POP) based on the viewer network 0013 # path and the child type0015 scene_viewer = active_pane0016 child_type = scene_viewer.pwd().childTypeCategory()Line 16 uses the function childTypeCategory() to return the type of the current selection in the givenviewport given the path to that node: scene_viewer.pwd().The variable child_type now contains the type of the current selected node.The Delete tool then takes that type and compares it to an Object type, a SOP type, a DOP type and then aPOP type. For the Object context type match, the following line is used:0018 if child_type == hou.objNodeTypeCategory():....If child_type is of a type object, then that block of code. The function objNodeTypeCategory() simply returns astring representing an object type. Similar tests are done <strong>for</strong> the other possible types.Prompting the user <strong>for</strong> input is provided as a default when using any of the filter tool functions. The mostcommon filter tool is genericObjNodeFilterTool with the function interface:def genericObjNodeFilterTool(scriptargs, nodetypename,nodename, prompt = None):Using this function as is and not overriding the optional prompt field will result in the default prompt “Selectone or more objects, then press Enter to continue. Middle mouse to select. Left mouse to select and drag.”To create your own custom prompts you simply need to add an optional argument to one of the filter tools likethis:objecttoolutils.genericObjNodeFilterTool(kwargs,‘$HDA_NAME’, ‘$HDA_NAME’,‘Select the object to work on and Enter to complete’)To grab the viewport position and write to a custom parameter, you need to add an additionalparameter to the genericObjNodeGeneratorTool function. By default, the position is returned to the added objectsown tx, ty and tz channels. When working with assets with hidden default subnet parameters, the targetparameter t[xyz] is hidden and so will the resultant values. This is not recommended. Use the option in the<strong>Building</strong> <strong>Tools</strong> <strong>for</strong> <strong>Houdini</strong> 9 | 17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!