Intercept Material Drag-and-Drop

I’ve been working on scripts to import and export objects of a game. Due to the requests of my tester, the scope of the job has increased to handling materials within Blender. These materials can have from one to seven texture slots, with UV layers associated with the slots. There can be up to four unique UV layers divided amongst the up to seven textures. I’ve written code that will change the texture slots and UV layers of a material based upon the game shader selected. My tester then tried to move/copy a material from one mesh to another via the drag and drop within Blender. This is where this post comes in…

When performing the d&d of the material, the texture slots will move fine. If the d&d is done within the outliner, the moved material is added to the receiving mesh. A delete of the existing material then cleans things up-- there is only one material allowed per mesh. If the d&d is performed from the outliner to the 3D view, the moved material replaces the existing material and no clean-up is needed. In any event, the UV layers of the receiving mesh remain the same-- if there is only one in the mesh’s current material, then there is only one after the move-- even if there are, say, seven used in the moved material. In no case are the textures of the moved material assigned to the UV textures of the receiving mesh.

The current method of distributing a material throughout a scene is to change the material of the receiving mesh to that of the source material so the UV layers match, then manually assigning the UV textures after the d&d. It works, but is cumbersome. I can see myself attempting to write a material copying/replacing routine, but I don’t think I can make it as elegant as the d&d on my own. Is there a way to intercept the d&d code call?

For informational purposes, the materials are linked to the data of the mesh object, not the mesh object itself. Also, I’m using the latest Blender version available. Currently 2.69 RC2, but will move to 2.69 when it is released.

Is there a way to intercept the d&d code call?

No, it’s entirely handled in C-code. First step would be to redesign the DnD system internally and expose it to python (e.g. via app handlers).

Yup, one of my many TODOs that I’ll probably never get around to finishing…

No redesign needed though, just needs a way to register new ones from the python side like with operators and some code to add/remove them from the DnD stack. Might need some cleanup in the ‘dropzone’ code in places too, I already cleaned up the outliner code in anticipation of doing this but never got around to starting the python side of things.