Get whether graph is executing in Dynamo Workspace or Dynamo Player

Hello,
is it possible to identify in Dynamo (e.g. by a Python script) whether the current graph is executed in the Dynamo Player or directly in the Dynamo Workspace? Or if the Dynamo Player is open/active during the execution?

I already looked in the API Docs for Revit and Dynamo for something like this, but unfortunately found nothing. Maybe I missed it because the function name is not obvious enough. Idk

Does anyone know a way to get this information in Dynamo?

I would like to add this function to my graphs, as I have an analytic node built in to each graph. However, I only want analytic data to be collected when it is used by a user through the Dynamo Player and not when changes and bugfixing are done in the workspace by our Dynamo Graph authors. I know there are workarounds like freezing nodes and bool switches, but that is error prone and you have to think about it every time.

Thanks.

It adds a little bit of a bottleneck (maybe .25 of a second or so), but you could check if a process called dynamoplayer.exe is open using the subprocess library which comes with Dynamo:

import subprocess
cmd = 'WMIC PROCESS get Caption,Commandline,Processid'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)

playerFound = False

for p in [line for line in proc.stdout]:
	if "dynamoplayer.exe" in p:
		playerFound = True
		break

OUT = playerFound

3 Likes

That’s an interesting take on the problem, which I didn’t think about. Thank you for that.

Sadly I found some issues whilst testing.

With this method it detects every “dynamoplayer” that is currently open. Even if it’s not from the Revit instance from which the graph is running. Not a very big deal, but if you are using multiple different Revit Versions at the same time, it can happen, that you work in one in the workspace but have the player open in the other.
Could be solved with more advanced filtering and stuff, but obviously not optimal.

Also one could have Dynamo workspace and player opened at the same time, even in one Revit instance, and it would detect the player and log the analytic data, even if it’s not meant to.

So actually it would be better if the Dynamo workspace could be detected instead of the player. But apparently it’s not possible with this method, is it? At least I couldn’t find any process the represents the dynamo workspace.

Would be awesome if someone knew a way to detect if the Dynamo workspace is open/active in the Revit instance the graph is run in.

Don’t get me wrong. Your suggestion is a workable solution I will use if I don’t find something better, but it’s not optimal in my opinion.

Btw. found something funny. Somehow Dynamo Player for Revit 2023 is listed as “GenerativeDesign”.
grafik

I believe there is something under the events class for this, but it may only be in newer builds.

I am curious - what is the intended use?

Hi Jacob,

you are talking about one of those?

Which one of them exactly? I have already tested a bit but got nothing useful.

I am using Revit 2023.1.1 with Dynamo 2.16.
Is this new enough?

As I wrote in my initial post, I want to use this function for data analysis of Dynamo graph usage in our company.
I already have a function (Custom Node) built into all of our graphs that collects data for usage analysis and statistics every time a graph is run.
All “ordinary” users use Dynamo Player only.
However, certain staff members are also involved with graph creation, maintenance and support. And troubleshooting of course. However, those executions should not be included in the statistics and analysis. Since this work usually takes place in the Dynamo workspace, the function I am looking for could be used to automatically suppress/skip the analysis part in such a case.

using ModelState property (DynamoRevit API)

check run

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms
from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon
clr.AddReference('DynamoRevitDS')
import Dynamo 
# access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()

def CheckRun():
	if any(modeStr in dynamoRevit.ModelState.ToString() for modeStr in ['StartedUIless', 'NotStarted']):
		MessageBox.Show("Script run on Player", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
		return "Script run on Player"
	else:
		MessageBox.Show("Script run on Dynamo", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
		return "Script run on Dynamo"
		
OUT = CheckRun()

ressource

3 Likes

I love this solution for when the scope is only Revit usage, but we really ought to have a ecosystem wide means of identifying this, ideally as a property of the exeuction session (accessible directly by Dynamo.Events.ExecutionEvents.ActiveSession).

Who wants to figure out which of my instances are from FormIt, Alias, or just Sandbox?

1 Like

@jacob.small I have a node in Clockwork called Application.Version which returns the name and version of the Dynamo host process. It reports Revit and Sandbox correctly, so it should work with other host apps as well. Dynamo Player is a special case, though, so it‘s nice to see there‘s a solution for that as well now.

3 Likes

Perfect! That’s exactly what I was looking for.
Thank you very much.

1 Like

I’m not sure if it’s possible to get the DymamoModel from active Session
I have not yet found a universal solution to access the dynamomodel (without a dynamo addin extension)

Ideally it would be to have a static method to access the DynamoModel

Note:
there may be a track to explore with the ViewStartupParams events from Python

1 Like

Good to know!

The headless stuff is more the issue I’m stuck with now though - even running a few graphs via CLI of late (bulk updating graph libraries)… the more the ecosystem expands the harder it is to tell what’s coming from where.