Maybe the approach in the previous post, of completely shutting down the Import command, is too harsh. This example shows how a Dynamic Model Update macro can give a warning after the user imports a CAD file. For some introductory comments on Dynamic Model Update, see https://boostyourbim.wordpress.com/2012/12/17/automatically-run-api-code-when-your-model-changes.
Instead of (or in addition to) the TaskDialog warning used in the code below, you could do other things like write information to a log file (to submit to Human Resources and include in the Revit user’s permanent record!) or require the user to enter a password to complete the operation – if the wrong password is entered then delete the element id returned by data.GetAddedElementIds().
private void Module_Startup(object sender, EventArgs e)
{
ImportInstanceUpdater updater = new ImportInstanceUpdater(this.Application.ActiveAddInId);
try
{
UpdaterRegistry.RegisterUpdater(updater);
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(),
new ElementClassFilter(typeof(ImportInstance)),
Element.GetChangeTypeElementAddition());
}
catch {}
}
public class ImportInstanceUpdater : IUpdater
{
static AddInId m_appId;
static UpdaterId m_updaterId;
// constructor takes the AddInId for the add-in associated with this updater
public ImportInstanceUpdater(AddInId id)
{
m_appId = id;
m_updaterId = new UpdaterId(m_appId, new Guid("FBFBF6A2-4C06-42d4-97C1-D1B4EB593EFF"));
}
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
Autodesk.Revit.ApplicationServices.Application app = doc.Application;
foreach (ElementId addedElemId in data.GetAddedElementIds())
{
ImportInstance ii = doc.GetElement(addedElemId) as ImportInstance;
if (ii.IsLinked == false)
TaskDialog.Show("Hey!", app.Username + " - Maybe should should have linked that CAD instead of importing it.");
}
}
public string GetAdditionalInformation(){return "Check to see if CAD file was imported";}
public ChangePriority GetChangePriority(){return ChangePriority.FloorsRoofsStructuralWalls;}
public UpdaterId GetUpdaterId(){return m_updaterId;}
public string GetUpdaterName(){return "Import Check";}
}
Just a note: Please keep in mind that an updater should not show a warning (in a commercial application, that is.) If the updater does not “agree” with some of the changes made, it should post a failure. For more info refer to the Failure API in Revit SDK.