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
Solved! Go to Solution.
Solved by ricaun. Go to Solution.
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.
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!