Search - User list
Full Version: Event Trigger for python callback on drag and drop
Root » Technical Discussion » Event Trigger for python callback on drag and drop
caden
Hey all,
Was hoping someone might be able to point me in the right direction. I am trying to implement a drag and drop functionality from Shotgun in the browser into houdini. Currently have a setup for Nuke but Houdini is proving to be more difficult. Any help would be greatly appreciated!

thanks!
tpetrick
Houdini has a script hook for external drag/drop, but currently only file path data is supported.

To use the script hook add a Python script named externaldragdrop.py to the Houdini script path, for example ~/houdini16.5/scripts/externaldragdrop.py. The script should define a function called dropAccept which takes a single parameter. Every time a drop event occurs on the main Houdini application it will call the dropAccept function with a list of file path(s) that were dropped onto Houdini. The function can return True to block the drop event from continuing on to Houdini, or False to indicate that Houdini should handle the drop event itself.

An example drop handler script that ignores .hip file drops and creates Font SOPs with the contents of the incoming files:

import hou
import os

def dropAccept(file_list):
    if len(file_list) == 1 and os.path.splitext(file_list[0])[1] == ".hip":
        return False

    for filename in file_list:
        with open(filename) as f:
            contents = f.read()

        obj = hou.node("/obj")
        geo = obj.createNode("geo", "geo1", False, False)
        font = geo.createNode("font")
        font.parm("text").set(contents[:20])

    return True

If the data in the drag/drop event contains arbitary text or binary data instead of file paths the script hook won't be invoked. This is something that would need to be fixed on our end - I can look into fixing that if necessary.
NFX
The ability to drag in arbitrary text or even binary data and handle it would be amazing. Just to verify, would this work with python panels? So far I haven't been able to figure out a good way drag and drop data from a custom panel into a parameter field. Seems like an important feature to have to support common studio tasks like wanting to drag an asset from a python asset manager into the viewport or network view. Perhaps there is already a way to do this that I have missed?
caden
Thank you tpetrick! I apologize for the delayed response but such are the riggers of production.

I haven't had the chance to try and implement this but I agree with NFX. This all came about because we would like to more tightly integrate the shotgun web ui into our artist pipeline. To really provide a robust solution I definitely believe we will need to be able to accept arbitrary text/data i.e json data stored in shotgun.

Please let me know what you think and would love to be kept in the loop if this issue progresses.
Doudini
externaldragdrop.py works really fine but does anyone know how we can pass stuff from a pypanel so it can be used in externaldragdrop.py script?

Edit:
I solved it with setting correct mimeData for example with option
setUrls([QtCore.QUrl.fromLocalFile(item)])
lightreacher
Doudini
setUrls
Can you share your working test script. How can I enable trigger on shotgun url drop?
mattebb
Just bumping this, it would be extremely helpful if we could access the full data of drop events inside houdini (eg. including web urls), not just files.

I'd also like to get Shotgun drag/drop working here too.
danielsweeney
@Doudini

any chance you could elaborate on how you got the drag and drop to work with python panels?

Been trying to find some information about this but cant seem to find anything?

cheers

Daniel
anvdev
tpetrick
Houdini has a script hook for external drag/drop, but currently only file path data is supported.

If the data in the drag/drop event contains arbitary text or binary data instead of file paths the script hook won't be invoked. This is something that would need to be fixed on our end - I can look into fixing that if necessary.

Is there any news?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB