I have dug into the documentation and examples and found a lot of information on working with drag and drop of content into Revit. However they all deal with dragging from another application. I would like implement a custom handler for drag and drop from the file explorer. Where do I put the call to my custom handler?
Dear Michael,
Thank you for your query, a follow-up to your previous one last week on the same topic, "launch-adding-when-file-is-dropped-in-revit":
http://forums.autodesk.com/t5/revit-api-forum/launch-addin-when-file-is-dropped-in-revit/m-p/6802123
In it, Matt pointed out some discussions and the UIAPI SDK sample:
http://www.revitapidocs.com/2017/f4561775-33b7-8643-b792-5cc234f7240f.htm
http://thebuildingcoder.typepad.com/blog/2012/04/drag-and-drop-api.html
I cannot say much more than he did then, really, except to confirm that his answer back then covers your new question as well.
I have another blog post to add to his list, historical:
http://thebuildingcoder.typepad.com/blog/2012/01/drag-and-drop-to-revit.html
In it, Tim Hoffeller implemented drag and drop for Revit 2012 before introduction of the official support for customised drag and drop behaviour described in the posts pointed out by Matt.
The official Drag and Drop API was introduced in Revit 2013 and with it, the UIAPI SDK sample.
UIAPI implements drag and drop support by presenting a modeless form from which you can drag an image item from the left panel to the Revit view to place a component, or drag a family file name item from the right panel to the Revit view to load a family file into the current project and place an instance in the model.
However, all aspects of this behaviour are completely customisable.
Any kind of file type can be supported, any type of drag source, any kind of drop behaviour.
You choose, you implement.
In other words, drag and drop from the Windows explorer is also fully supported.
Best regards,
Jeremy
Dear Michael,
I pondered this issue a bit further and can imagine exactly what issue you are facing now.
The Revit API provides the `DoDragDrop` method.
That enables you to implement custom drag and drop behaviour.
As said, any kind of file type or other data can be supported, any type of drag source, any kind of drop behaviour.
However, there is a non-trivial stumbling block to master first:
`DoDragDrop` is a Revit API method. Revit API methods can only be invoked from a valid Revit API context. Windows Explorer and all other external applications do not provide such a context. A valid Revit API context is only provided by Revit itself, within the scope of a Revit event. The most typical event is the external command `Execute` method. If you are trying to interact programmatically with an external application and perform some kind of action in the Revit API based on external circumstances, you can make use of an external event to gain access to a valid Revit API context.
I think this would be the proper way to implement what you are after.
Capisci?
For more information on implementing external events, please refer to The Building Coder topic group on Idling and External Events for Modeless Access and Driving Revit from Outside:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28
I hope this helps.
As you can see, I find this question interesting and will be glad to continue this conversation.
Best regards,
Jeremy
Jeremy,
Thanks for this information. I think it give me a better understand of how this will work. I will read through you blog and report back.
Hi Michael,
Sorry to hear that this is proving difficult.
I've had a couple of ideas that I thought could prove useful.
For 1,2 - Obviously you may run more than one version of Revit, or more than one instance of the same version of Revit, so that would need working around also.
What file type are you trying to drag-n-drop? Knowing that may sprout additional ideas.
Cheers,
-Matt
I am trying to add support for PDF files. I currently have a menu bar item to load a file, but drag and drop is more convenient. A right click feature could work, and I have done that previously for other tools so that wouldn't be difficult to implement.