How to trigger a Plug In with every save?

How to trigger a Plug In with every save?

Anonymous
Not applicable
987 Views
3 Replies
Message 1 of 4

How to trigger a Plug In with every save?

Anonymous
Not applicable

Hey all! Is there a way to write your plugin such that it launches whenever you save your Revit model?

 

For example, if I write a toy "hello world" plugin, how can I get it to launch whenever I save the model? Is this possible or not? 

 

Generally, can you program a plugin to launch under any given trigger - i.e. when you go to close Revit, when you open Revit, when you add a certain object to a file, etc 

0 Likes
Accepted solutions (1)
988 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor

Yes via subscribing to events such as the Document.DocumentSaving event.

 

How you can interact with the document during some events is sometimes restricted however.

Message 3 of 4

ricaun
Advisor
Advisor
Accepted solution

You could use the DocumentSaved and DocumentSavedAs to check when something is finished to save or DocumentSaving and DocumentSavingAs when the document is about to save (if you want to do something before the save).

 

Check this sample.

 

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace RevitAddin12.Revit
{
    public class AppSave : IExternalApplication
    {
        public Result OnStartup(UIControlledApplication application)
        {
            application.ControlledApplication.DocumentSaved += ControlledApplication_DocumentSaved;
            application.ControlledApplication.DocumentSavedAs += ControlledApplication_DocumentSavedAs;
            return Result.Succeeded;
        }

        private void ControlledApplication_DocumentSaved(object sender, Autodesk.Revit.DB.Events.DocumentSavedEventArgs e)
        {
            TaskDialog.Show("Revit", $"Saved {e.Document.PathName}");
        }
        private void ControlledApplication_DocumentSavedAs(object sender, Autodesk.Revit.DB.Events.DocumentSavedAsEventArgs e)
        {
            TaskDialog.Show("Revit", $"SavedAs {e.Document.PathName}");
        }

        public Result OnShutdown(UIControlledApplication application)
        {
            application.ControlledApplication.DocumentSaved -= ControlledApplication_DocumentSaved;
            application.ControlledApplication.DocumentSavedAs -= ControlledApplication_DocumentSavedAs;
            return Result.Succeeded;
        }
    }
}

I hope this helps.

 

See ya!

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 4 of 4

Anonymous
Not applicable

amazing! thank you! exactly what I was after!

0 Likes