How To Check Dynamo Is Open Or Closed!

Hi everyone, I have a question to investigate right now, do we have a way to check if the dynamo is open with revit, I use Process.GetProcesses () but can’t find any progress Anyway, if someone has solution, please help me, thanks!

var processss = from proc in System.Diagnostics.Process.GetProcesses() orderby proc.ProcessName ascending select proc;
foreach (var item in processss)
{
Console.WriteLine(item.ProcessName);
}


Screenshot_2

Not sure this is entirely the forum you need, this sounds more like a stack exchange question. However, there are probably several ways to go about something like this (I’m no expert in System.Diagnostics so maybe someone else will chime in), but here are a couple of suggestions that I can think of…

I couldn’t get much info out of the CefSharp subprocess, but by enumerating the modules of the Revit.exe process you can check if there any filenames that contain the name “Dynamo”, Revit will load these in only when the user launches Dynamo. This will only tell you if Dynamo has been opened, not that it is open… once the modules are loaded, they remain loaded until Revit is shut down even if you close Dynamo.

Another crude method is to check the latest dynamo log file, if it does not say Goodbye, then it is open.

Or, you could just create a ViewExtension. I have no idea what it is you are trying to do, but you could use it communicate to another process when Dynamo is open or has been closed via IPC and trigger some external code.

Cheers,
Dan

1 Like

Have you thought about accessing the Journal files and reading information from that?

I have not tried/looked to see what is indicated re:Dynamo but definitely worth a look at.

Also watch out if reading information from memory because i think revit still holds dynamo(and dynamo packages) there even if closed. This is why you have to close revit fully to uninstall a dynamo package if dynamo has been opened.

1 Like

Yeah, the revit journal will most likely also have this, they are very large though and don’t reflect multiple instances or revit in one file, so you would need to check a few before getting a definitive answer. Also, logs/journals are never a good way to go for sound development IMO. Sort of like trying to pass the year at school with someone elses class notes. Still, its possible…

The only foolproof method I can think of is via ViewExtension in dynamo. This is what I use when retrieving usage information ( say, open, close, time elapsed and other session data).

1 Like

View Extensions could be a way but do remember that these do not load if you are using Dynamo player or similar solution for running dynamo(eg Relay for revit - Relay for Revit - Adding .dyns to Ribbon).

1 Like

There may be a way to use the revit api “UIApplication” or “ExternalEvent” classes to watch out for Dynamo to appear in event and similar for when it is closed?

Though this will mean you will have to build a revit addin instead of something in dynamo.

Fair point and a good one! :blush: But, we are asking whether dynamo is open. Lets wait and see what @chuongmep needs this for, I think context will be important here.

You could use the Dynamo APIs and maybe evaluate the RevitDynamoModelState enum:

        public Result Execute(ExternalCommandData externalCmd, ref string message, ElementSet elements)
    {
        var modelState = DynamoRevit.ModelState;

        TaskDialog td = new TaskDialog("Test")
        {
            Title = "Dynamo status",
            MainInstruction = modelState.ToString(),
            AllowCancellation = false,
            CommonButtons = TaskDialogCommonButtons.Ok
        };

        td.Show();

        return Result.Succeeded;
    }

Before Dynamo is opened:

While Dynamo is open:

After Dynamo is closed:

7 Likes

Nice, @Thomas_Mahon. Very simple too!

1 Like

That’s what I need, thanks so much !