Page MenuHome

Extend Drag and Drop to Python
Open, NormalPublic

Description

Blender Implements the ability to drag files onto the interface and have an operator called when the file is dropped on the interface. Depending on what is under the cursor one of these operators will be called:

  • OBJECT_OT_add_named
  • OBJECT_OT_drop_named_material
  • MESH_OT_drop_named_image
  • VIEW3D_OT_background_image_add
  • OBJECT_OT_group_instance_add

The code for the available dropboxes can be found here:

source/blender/editors/space_view3d/space_view3d.c – view_3d_dropboxes(void) : void

Proposed Implementation:

Allow a python operator to define the functionality that is called when a file is dragged onto the interface. This exposes very intuitive functionality that can be used by Blender Add-on Developers. An example of this functionality can be found in the Fluid Designer project. In order to achieve this functionality in Fluid Designer we just forced a python operator to be called using this code:

PointerRNA ptr;
WM_operator_properties_create(&ptr, "VIEW3D_OT_drag_and_drop");
RNA_string_set(&ptr, "filepath", ima->name);
WM_operator_name_call(C, "VIEW3D_OT_drag_and_drop", WM_OP_INVOKE_REGION_WIN, &ptr);
WM_operator_properties_free(&ptr);

Discussion Topics:

How would the user know if two add-ons are subscribed to the drag and drop operator?
Is there a better way for an operator to subscribe to a drag and drop event? Maybe using the ‘bl_options’ property of an operator.

Details

Type
Design

Event Timeline

Andrew Peel (andyrexic) updated the task description. (Show Details)
Andrew Peel (andyrexic) raised the priority of this task from to Needs Triage by Developer.
Andrew Peel (andyrexic) set Type to Patch.

I cannot speak to the code side, but from a functionality standpoint I think this is really important to increase the power of add ons. This would open a lot more possibilities and improvement for user-friendliness in add ons. Particularly those that deal with scene and/or object management in any way.

What do you think @Campbell Barton (campbellbarton)?

Yeah I still have a lot to learn when it comes to working with Blenders C/C++ Code, but it seems like it could be a simple implementation. Hopefully @Campbell Barton (campbellbarton) can help determine if i am totally out of my mind or if this seems like a possible solution.

Sergey Sharybin (sergey) triaged this task as Normal priority.Apr 11 2014, 8:53 AM

I'm not really sure, seems it's not actually a patch but design discussion? We've got separate project for this actually.. Patch tracker is not the best place for such things.

Assigning to @Campbell Barton (campbellbarton) to have a final decision here.

Yeah i kind of had a feeling that i posted this in the wrong place right after i hit the submit button, but I have implemented this functionality into the Fluid Designer Build so i can submit a diff showing exactly what i changed, but i have a feeling that it wouldn't be accepted since it is mostly a hack. So i guess i will wait to see what @Campbell Barton (campbellbarton) has to say about what direction I should take. Thanks for the info sergey.