Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drag and Drop from Explorer

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
731 Views, 5 Replies

Drag and Drop from Explorer

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?

5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: Anonymous

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6
jeremytammik
in reply to: Anonymous

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.

 

  1. The drag is initiated somewhere, e.g., in Windows Explorer.

 

  1. The drag is detected by something, presumably your custom non-Revit code X, maybe using the Windows API or .NET functionality to do so.

 

  1. You Revit add-in Y implements the external event handler, which is notified somehow by X about the drag occurrence and associated data.

 

  1. Y raises the external event.

 

  1. The external event handler is equipped with a valid Revit API context, receives the drag data and can do its thing, i.e., call the Revit `DoDragDrop` method accordingly.

 

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 Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 6
Anonymous
in reply to: jeremytammik

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.

Message 5 of 6
matthew_taylor
in reply to: Anonymous

Hi Michael,

Sorry to hear that this is proving difficult.

I've had a couple of ideas that I thought could prove useful.

 

  1. Add a right-click action in Windows Explorer. You could get this to trigger off your own application which could then pass data to Revit's drag-n-drop API.
  2. Similar to 1, but, if you have a proprietary file type with its own file extension, you could associate that file type with your program (which would pass date to Revit's drag-n-drop API). Then a double-click would achieve the same thing.
  3. I haven't looked into it, but you may be able to drag-n-drop (without API help?) to a dockable pane. (This may help: http://forums.autodesk.com/t5/revit-api-forum/external-events-from-dockable-pane/td-p/6448463)

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


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 6 of 6
Anonymous
in reply to: matthew_taylor

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community