Get graph filename?

Hi all,

I am wondering if there is a way to programmatically get the active Dynamo graph’s filename? I did some research but came up empty:

  • Example by Mark Thorley (But I cannot find any reference to Dynamo.Applications.DynamoRevit.RevitDynamoModel; ) link

  • Tried accessing it through the viewmodel - no luck either

  • Searched through the Dynamo repo for examples with keywords like ‘workspace’ and ‘filename’

  • On this forum here

I think what I have to do is to get the current Dynamo graphs’ workspace but I don’t know how to do it. I could then get the filename with through Dynamo.Graph.Workspaces.WorkspaceModel

Thanks for the help!

This should help you get the FileName of the currently opened Dynamo Graph, though note it only works for Dynamo when it is hosted within Revit.

2 Likes

Thanks Brendan, I’ve seen this before:

# access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

Thing is, as you mention, it will only work with Dynamo for Revit and I’m using Core :upside_down_face:

Could there be a similar (simple) solution for Core as well?

Thanks again for your help!

@john_pierson did you ever do this for Core too dude? :smiley: Or was it just D4R?

Hi @Michael684

Is this what you want?

8 Likes

This is awesome @Kulkul ! :raised_hands:

3 Likes

@Kulkul that’s great! Thank you so much!!

For those wondering, here is the same solution in C#:

string graphPath = Dynamo.Events.ExecutionEvents.ActiveSession.CurrentWorkspacePath;
string graphName = graphPath.Substring(graphPath.LastIndexOf('\\') + 1, graphPath.Length - graphPath.LastIndexOf('\\') - 1);
1 Like

You’re Welcome!

1 Like

I have added @Kulkul version onto the link below and added a way to just get the file name with and without the file type.

2 Likes

Hello @Kulkul,

thanks for this amazing solution. I tried to use your code in a user-defined-node but it does not get the path. Is it possible to make it run inside a node?

Thank you very much!

Could you share user defined node?

1 Like

Thank you very much for your help @Kulkul.

I tried some stuff and saw that I have to user Passthrough after node to another Python node. Now it works.
Awesome work!