|On this page|
Houdini lets you turn the state into a
drag drop receiver. This enables the state to react when
users drag and drop something onto the scene viewer.
Handling Drag and Drop events
As a result of the
drag event initiated by the user, Houdini will call 3 callbacks sequentially
to handle the event. They are all mandatory and must be implemented for handling the event properly.
In order to access the information related to the
drag drop event, you need to use these APIs:
hou.ui.hasDragSourceData(): to validate the supported type of the event source.
hou.ui.getDragSourceData(): to access the data form the event source.
drag drop event callbacks are listed below in order of execution.
Called by Houdini when an element is dragged into the viewer. The goal of this callback is to
decide whether we are interested of handling the event or not. Returning
This callback is called when the dragged element is dropped onto the view. It lets you build a
list of options representing the different
Houdini uses the option list to populate and display a menu for selecting a drop option. The menu is not displayed however if only one option was added. In this case the lone option is selected by default.
The dictionary passed to this callback contains these items:
A dictionary representing the
An entry in the
An entry in the
Houdini calls this method with the selected
The dictionary passed to this callback contains the following:
The selected option.
Here’s a small code snippet to demonstrate the
drag drop support. Check out the
$HH/viewer_states/examples/state_dragdrop_demo.hip scene for a more detailed example.
import hou import viewerstate.utils as su class State(object): def __init__(self, state_name, scene_viewer): self.state_name = state_name self.scene_viewer = scene_viewer def onEnter(self,kwargs): self.scene_viewer.setPromptMessage( 'Drop a source file in the viewer', hou.promptMessageType.Prompt ) def onDragTest( self, kwargs ): """ Accept text files only """ if not hou.ui.hasDragSourceData('text/plain'): self.scene_viewer.setPromptMessage( 'Invalid drag drop source', hou.promptMessageType.Error ) return False # note: su.dragSourceFilepath returns the sanitized dragged file path su.log(su.dragSourceFilepath()) return True def onDropGetOptions( self, kwargs ): """ Populate a drop option list with 3 items """ kwargs['drop_options']['ids'] = ('option1', 'option2', 'option3') kwargs['drop_options']['labels'] = ('Option 1', 'Option 2', 'Option 3') def onDropAccept( self, kwargs ): """ Process the event with the selected option. """ su.log( kwargs['drop_selection'] ) return True