Execute Dynamo Script from Revit API

Very nice John, you are the man! I just tried this out and seems to work exactly as I need. I’m even able to save/store my Dynamo Scripts in “Manual” mode which is preferred for what we are doing. Before we had to save the scripts as “Automatic” which was a pain.

Here is my updated VB.NET code which is working perfectly now! I’d give you a hug but will stick to an elbow bump :smile: GREAT SUCCESS!!!

 Public Function ExecuteDynamo(uiapp As UIApplication, path As String) As Result

    Try

        If File.Exists(path) = False Then Return Result.Failed

        Dim jd As IDictionary(Of String, String) = New Dictionary(Of String, String) From {
        {Dynamo.Applications.JournalKeys.ShowUiKey, False.ToString()},
        {Dynamo.Applications.JournalKeys.AutomationModeKey, True.ToString()},
        {Dynamo.Applications.JournalKeys.DynPathKey, ""},
        {Dynamo.Applications.JournalKeys.DynPathExecuteKey, True.ToString()},
        {Dynamo.Applications.JournalKeys.ForceManualRunKey, False.ToString()},
        {Dynamo.Applications.JournalKeys.ModelShutDownKey, True.ToString()},
        {Dynamo.Applications.JournalKeys.ModelNodesInfo, False.ToString()}}

        Dim drcd As DynamoRevitCommandData = New DynamoRevitCommandData()
        drcd.Application = uiapp
        drcd.JournalData = jd

        Dim dr As DynamoRevit = New DynamoRevit()
        dr.ExecuteCommand(drcd)

        DynamoRevit.RevitDynamoModel.OpenFileFromPath(path, True)
        DynamoRevit.RevitDynamoModel.ForceRun()

        Return Result.Succeeded

    Catch ex As Exception

        Return Result.Failed

    End Try

End Function
4 Likes