I can’t take credit for this script, I only suggested a possible solution. Credits go to @Kulkul …
All is good @4bimfercesp. Thank you.
I have added the 2 parentheses as a trial to solve the same error in that line 22. So, nothing changes if 1 parentheses or two exist in the routine. Thank you for your comments.
Hi @Andreas_Dieckmann.
Thank you for that. I did use @KulKul’s script as well, but it does not display the entire file path, including server, as I need to display. Thank you for getting back to me.
Thanks. That one should be marked as the solution…
You could utilize this python code to get the file name, do note that this uses dynamorevit so may not work in dynamo sandbox or other dynamo hosted forms(formit, civil 3d).
import clr
clr.AddReference(‘DynamoServices’)
from Dynamo.Events import *
OUT = ExecutionEvents.ActiveSession.CurrentWorkspacePath
This may work
Great call back.
This API was added by the team shortly after the other method became the required fallback. Hopefully this will help users to find this more stable solution going forward!
This is update for Dynamo and Zerotouch Node :
Python Script :
import clr
clr.AddReference('DynamoServices')
from Dynamo.Events import *
OUT = ExecutionEvents.ActiveSession.CurrentWorkspacePath
Zero Touch Node :
using System.IO;
using Autodesk.DesignScript.Runtime;
using Dynamo.Applications
string fileName = DynamoRevit.RevitDynamoModel.CurrentWorkspace.FileName;
you can use the ExecutionEvents also from c# and it will be more portable than trying to access the DynamoModel directly.
Update for Zerotouch like @Michael_Kirschner2 recommend :
public static string FileFromRelativePath(string relativeFileName)
{
try
{
string fileName = Dynamo.Events.ExecutionEvents.ActiveSession.CurrentWorkspacePath;
if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException(nameof(relativeFileName));
var directory = Path.GetDirectoryName(fileName);
if (directory == null) throw new ArgumentNullException(nameof(relativeFileName));
string filePath = Path.Combine(directory, relativeFileName);
if (!File.Exists(filePath)) throw new FileNotFoundException("File not found");
return filePath;
}
catch (Exception)
{
return string.Empty;
}
}
Require Nuget :
<PackageReference Include="DynamoVisualProgramming.DynamoServices" Version="3.*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>