Tiago Cerqueira
Tiago Cerqueira

Reputation: 37

Control Events- Revit API

I would like to control events of Load Families and Create Type with revit api. Someone can give me a direction ? I don't understand very well the documentation that I read.

Upvotes: 3

Views: 909

Answers (1)

konrad
konrad

Reputation: 3706

First you need to subscribe to an event by creating an event listener in the IExternalApplication OnStartup method.

public class AppCommand : IExternalApplication
{
    public Result OnStartup(UIControlledApplication application)
    {
        application.ControlledApplication.FamilyLoadedIntoDocument += OnFamilyLoaded;

        return Result.Succeeded;
    }
}

Next you need a handler for that event:

private void OnFamilyLoaded(object sender, FamilyLoadedIntoDocumentEventArgs args)
{
    // do work here
}

When finished you need to unregister the event handler:

public Result OnShutdown(UIControlledApplication application)
{
     application.FamilyLoadedIntoDocument -= OnFamilyLoaded;

     return Result.Succeeded;
}

The other events available that you can subscribe to are these:

http://www.revitapidocs.com/2018/b69e9d33-3c49-e895-3267-7daabab85fdf.htm

Cheers!

Upvotes: 1

Related Questions