Skip to content

Instantly share code, notes, and snippets.

@johnpierson
Last active May 6, 2024 12:42
Show Gist options
  • Save johnpierson/3c819c901f836745b1524d7f2261c68e to your computer and use it in GitHub Desktop.
Save johnpierson/3c819c901f836745b1524d7f2261c68e to your computer and use it in GitHub Desktop.
This is an example of an application level add-in that would prompt a user to save if they need to when launching dynamo.
#This code is proudly provided under the BSD-3-Clause, https://opensource.org/licenses/BSD-3-Clause
using System;
using Autodesk.Internal.Windows;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
namespace PromptForSaveOnDynamoLaunch
{
class App : IExternalApplication
{
//the current document
private Document _currentDoc;
public Result OnStartup(UIControlledApplication a)
{
//using AdWindows, we are able to see when someone clicks a ribbon button
//here we subscribe to that event
Autodesk.Windows.ComponentManager.ItemExecuted += CommandExecuted;
return Result.Succeeded;
}
private void CommandExecuted(object sender, RibbonItemExecutedEventArgs e)
{
bool wasDynamo = e.Item.AutomationName.StartsWith("Dynamo", StringComparison.OrdinalIgnoreCase);
if (wasDynamo)
{
TaskDialog.Show("Hi", "You launched Dynamo. PLZ SAVE. KTHXBYE.");
}
}
public Result OnShutdown(UIControlledApplication a)
{
//unsubscribe from the event
Autodesk.Windows.ComponentManager.ItemExecuted -= CommandExecuted;
return Result.Succeeded;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment