How to Automatically Dismiss a Revit dialog

For my friend who asked:

Is it possible to disable the pop-up, when you edit a floor: -Would you like walls that go up to his floor’s level to attach to its bottom?- I never want to do this, it’s annoying

Here is how to automatically dismiss that or any other Message Box or Task Dialog

private void Module_Startup(object sender, EventArgs e)
{
    UIApplication uiapp = new UIApplication(this.Application);
    // Subscribe to the DialogBoxShowing event to be notified when Revit is about to show a dialog box or a message box. 
    uiapp.DialogBoxShowing += new EventHandler(dismissFloorQuestion);
}

private void dismissFloorQuestion(object o, DialogBoxShowingEventArgs e)
{
    // DialogBoxShowingEventArgs has two subclasses - TaskDialogShowingEventArgs & MessageBoxShowingEventArgs
    // In this case we are interested in this event if it is TaskDialog being shown. 
    TaskDialogShowingEventArgs t = e as TaskDialogShowingEventArgs;
    if (t != null && t.Message == "The floor/roof overlaps the highlighted wall(s). Would you like to join geometry and cut the overlapping volume out of the wall(s)?")
    {
        // Call OverrideResult to cause the dialog to be dismissed with the specified return value
        // (int) is used to convert the enum TaskDialogResult.No to its integer value which is the data type required by OverrideResult
        e.OverrideResult((int)TaskDialogResult.No);
    }
}

Remember to add this line to the top of the file to avoid compilation errors:
using Autodesk.Revit.UI.Events;

Learn Keyboard Shortcuts with an API app

Would you like to use Revit faster? I learned about KeyRocket from posts at What Revit Wants and better Revit. KeyRocket is great for Windows and Office, but it doesn’t know anything about Revit.

So I used the Revit API to make this app to help remind Revit users of the shortcuts. Any thoughts on this before I put it in the Autodesk App Store?

How to override commands in the Revit UI (when you REALLY don’t want people to import CAD files)

The previous post showed how to delete CAD imports that are already in your Revit model. What if you want to prevent those CAD imports from being added in the first place?

The 2013 API introduced functionality that allows commands in the Revit UI to be replaced with your API code. In this simple case, the Import command will be replaced with an error dialog.

You will need to find the ID for the command that you want to replace. The easiest way to do that is to execute the command through the Revit UI and then open the Revit journal file (in C:\Users\HP002\AppData\Local\Autodesk\Revit\Autodesk Revit Architecture 2013\Journals or something like that). For import, the entry will be

 Jrn.Command "Internal" , "Import vector data from other programs , ID_FILE_IMPORT"

The string in capital letters near the end of the line is the command id. Here’s the code showing how to replace the Import command, and in the video you see that while Link still works as usual, Import does not.

private void Module_Startup(object sender, EventArgs e)
{
    UIApplication uiapp = new UIApplication(this.Application);

    // Get the command id for the import command
    RevitCommandId commandId = RevitCommandId.LookupCommandId("ID_FILE_IMPORT");

    // use try/catch because CreateAddInCommandBinding will throw if there is already a binding for this id
    // for more info see https://boostyourbim.wordpress.com/2013/01/06/using-module_startup-to-run-macro-code-when-revit-starts/
    try
    {
        AddInCommandBinding importBinding = uiapp.CreateAddInCommandBinding(commandId);
        importBinding.Executed += new EventHandler<Autodesk.Revit.UI.Events.ExecutedEventArgs>(importReplacement);
    }
    catch
    {}
}

private void importReplacement(object sender, Autodesk.Revit.UI.Events.ExecutedEventArgs arg)
{
    TaskDialog.Show("Stop!","Do not import!");
}