By Joe Ye
We need to copy some original central files to a new location and opened them in an automatic way to read some information.
When opening those files, the warning dialog: 'This File has been copied or moved from....' shows for each rvt file.
To make my command opening some rvt files one by one without interactively clicking the “Close” button, how can we suppress this dialog?
Solution
You can use the DialogBoxShowing event to dismiss this dialog automatically. In Revit when dialog shows, this event can be triggered. This event handlers can decide how to handle the dialog. For instance let it show, dismiss it, or mimic clicking specified buttons in the dialog.The arguments passed in to the event handler contains the target dialog information, for example, DialogId. This can be used to identify dialog.
Here is the full code for this command. For simplicity, I register the DialogBoxShowing event in the external command. You can register it in the Application.OnStartup() method. And dismiss the "Copies Central Model" dialog by mimic clicking the "Close" button.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
[TransactionAttribute(TransactionMode.Manual)]
public class RevitCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc);
trans.Start("testComamnd");
app.DialogBoxShowing +=new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(app_DialogBoxShowing);
trans.Commit();
return Result.Succeeded ;
}
public void app_DialogBoxShowing(Object sender, DialogBoxShowingEventArgs args)
{
if (args is TaskDialogShowingEventArgs)
{
TaskDialogShowingEventArgs argsTask = args as TaskDialogShowingEventArgs;
if (argsTask.DialogId == "TaskDialog_Copied_Central_Model")
{
args.OverrideResult((int)TaskDialogResult.Close);
}
}
}
}