Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to trigger a Plug In with every save?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
andrew.blance
538 Views, 3 Replies

How to trigger a Plug In with every save?

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 

Tags (2)
Labels (3)
3 REPLIES 3
Message 2 of 4
RPTHOMAS108
in reply to: andrew.blance

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
in reply to: andrew.blance

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

amazing! thank you! exactly what I was after!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community