I'm trying to bind the drag/drop of a family into the project and disable it.
My code is based on the Revit 2014 SDK Sample DisableCommand
My code has the .CanHaveBinding test and I have a dialog that displays success or failure. When I run the command it shows success, but I'm still able to drag drop families. Any ideas?
RevitCommandId commandId2 = RevitCommandId.LookupCommandId("ID_PROCESS_DROP"); if (!commandId2.CanHaveBinding) { TaskDialog.Show("Error", "Drag/Drop cannot be overridden."); } else { TaskDialog.Show("Success", "Drag/Drop can be overridden."); } try { AddInCommandBinding dropBinding = uiapp.CreateAddInCommandBinding(commandId2); dropBinding.Executed += new EventHandler<Autodesk.Revit.UI.Events.ExecutedEventArgs>(dragDropDisable); } catch (Exception ex) { Console.WriteLine("Error: {0}",ex.ToString()); } private void dragDropDisable( object sender, Autodesk.Revit.UI.Events.ExecutedEventArgs args) { TaskDialog.Show("Disabled", "Never Drag/Drop families into your project!"); }
Hi,
We don't believe the generic drag'n'drop can be tracked with this command binding... but, more important, what is exactaly that you want to achieve with that? We may be able to find a better alternative...
Thanks!
So what about track the 'FamilyLoadingIntoDocument' event? Inside it, just call e.Cancel()
public Result OnStartup(UIControlledApplication a)
{
a.ControlledApplication.FamilyLoadingIntoDocument += ControlledApplication_FamilyLoadingIntoDocument;
}
Looks like that's new to the 2015 api? is that right? If so, that won't work for this in particular as I need the code to work for 2014 as well.
If this is about preventing families to be loaded into a document, perhaps the Dynamic Updater framework can be used, which has been around since 2014 (and maybe even earlier.) And updater can be set to be notified about new elements created (types, in this case) and can post a failure that would prevent the current action (regardless of what it actually is) from being committed. Naturally, this approach may be less obvious to the end user than disabling a particular command, but the final effect would be the same – loading in new types is disabled.
The idea is to prevent only that method of loading families. When Families are dragged and dropped into the project, they don't trigger type catalogs and it goes against our company best practices.
I had thought about Dynamic Updater, but I wasn't sure how to identify when that particular event happened.