How to check Dynamo or Dynamo player is already running (C#)?

Hi, I’m developing an addin with Revit API(C#).
The program is developed to run .dyn file without Dynamo or Dynamo Player.
It runs well, but I want to block to run my addin when Dynamo or Dynamo player is already running. The reason is to prevent a conflict.
How can I know Dynamo or Dynamo player is already running? Thank you!

Hi Daeil,
It might be worth reviewing How to get help on the Dynamo forums
Further this question seems more appropriate here Revit API Forum - Autodesk Community
Perhaps start here LoadedApplications Property

for Dynamo we can check the state (DynamoModelState Enum)

Example of code

      public void CheckDynamoIsOpen()

      {
         UIDocument uidoc = this.ActiveUIDocument;  
         Document doc = this.ActiveUIDocument.Document;
         UIApplication uiApp = this;
         //get all loaded assemblies
         var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

         //find the Dynamo Revit one
         var dynamoRevitApplication = loadedAssemblies
            .FirstOrDefault(a => a.FullName.Contains("DynamoRevitDS"));
         // create dynamoRevit instance
         object dInst = dynamoRevitApplication.CreateInstance("Dynamo.Applications.DynamoRevit");
         Dynamo.Models.DynamoModel rdm = (Dynamo.Models.DynamoModel)dInst.GetType().GetProperty("RevitDynamoModel").GetValue(dInst, null);
         DynamoModel.DynamoModelState state = (DynamoModel.DynamoModelState)dInst.GetType().GetProperty("ModelState").GetValue(dInst, null);
         // OR
         state = (DynamoModel.DynamoModelState)rdm.GetType().GetProperty("State").GetValue(rdm, null);
         if (state == DynamoModel.DynamoModelState.StartedUI)
         {
            TaskDialog.Show("Dynamo", "Dynamo is Open");
         }
         else
         {
            TaskDialog.Show("Dynamo", "Dynamo is Close");;
         }

      }

for DynamoPlayer , I didn’t find it, otherwise, I will start with a query on the running processes by searching for “GenerativeDesign”

1 Like

Thank you! It is perfect for me.
But unfortunately, DynamoModelState is not supported in Dynamo for Revit 2022. Is there other way in Dynamo for Revit 2022?

Not sure when the external service gets added to Revit, but you could check this method and the parent class: GetServices Method

1 Like

You could get the current revit process, then go through that for each module and see if there is a Dynamo dll running.

Though in revit 2025 it auto loads some dynamo dll’s so you may have to check if say a package dll/some other dll that is not auto loaded is loaded instead or even try what Jacob has indicated.

The below is from some code i did that was checking all processes to see if it could update all packages when dynamo is not loaded, because it cannot update packages if dynamo was loaded in any instance. You can utilise GetCurrentProcess instead to get the current instance of revits process

2 Likes

This could work

bool IsDynamoOpen = 
    Process
    .GetCurrentProcess()
    .Modules
    .Cast<ProcessModule>()
    .Any(mod => mod.ModuleName.ToLower().Contains("dynamo"));