Get Script's own name

How can I get the script’s own name via python?

Here is one way to do it. (This will only work in Dynamo for Revit, not Dynamo Sandbox)

and here is the Python script:

8 Likes

Interesting… using Dynamo API in dynamo itself?
But I’m not able to replicate the same results? I’m using v 1.3.

I tried different way(shown below) as well but still don’t get the script’s name… I’m still getiing “Home” as name of the script.

In Dynamo 1.3 use FileName

import clr
# Adding the DynamoRevitDS.dll module to work with the Dynamo API
clr.AddReference('DynamoRevitDS')
import Dynamo 

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

#output the current workspace's name
OUT = currentWorkspace.FileName

Filename function is returning the whole location of the file not just the name.

if it is not possible to extract just the name, this is perfect solution!
I will convert the output into string and slice the text as needed.

Thanks!

OOTB nodes are available for this.

1 Like

Found a way to do in python node itself!

import clr
clr.AddReference('DynamoRevitDS')
import Dynamo 
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import os
DynamoRevit=Dynamo.Applications.DynamoRevit()
scriptname=DynamoRevit.RevitDynamoModel.CurrentWorkspace.FileName

name=os.path.basename(scriptname)
filename,extention=os.path.splitext(name)
OUT=filename

image

4 Likes

Very Nice!

Over on the DynamoPython GitHub repo @Brendan_Cassidy added the ability for this to work on Dynamo 1.3.x or 2.0.x.

In Dynamo 2.0.x they added a method to just get the name without splitting or anything like that.

4 Likes

Glad it helps to have one node type for both versions :blush:

2 Likes

Hi @Brendan_Cassidy , @john_pierson : How can we access Dynamo API from DesignScript ? So that we could do the same operation in code block instead of adding a Python node.

Unfortunately, I do not think so.

Can I nest this python node in a custom node and access “Home” workspace instead of a workspace in which this python node is?
I know its very complicated but just wondering if it is possible.

I think you can use DynamoRevit.RevitDynamoModel.Workspaces and iterate through that for the one that is not equal to the custom node name.

please, FilePath.FileName node at which package?

If you add the python code from the github page information given above this will mean it will automatically remove the “.dyn” information at the end.

This will mitigate the requirements for the “FilePath.FileName” node.

Though it was indicated earlier in the post that it was a Out Of The Box Node(OOTB Node)