Execute add-in automatically

Execute add-in automatically

joaofmoco
Advocate Advocate
391 Views
1 Reply
Message 1 of 2

Execute add-in automatically

joaofmoco
Advocate
Advocate

Hello everyone,

I have an add-in that is producing an error.
The Add-In in question is trying to execute a .dyn file when executed.
Here is the code in "Command.cs":

#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Dynamo.Applications;
using System;
using System.Collections.Generic;
using System.Diagnostics;

#endregion

namespace DynamoAddin
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class RunDynamo : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application and documnet objects and start transaction
            UIApplication uiapp = commandData.Application;
            Document doc = uiapp.ActiveUIDocument.Document;

            string Journal_Dynamo_Path = @"C:\Users\JoãoMoço\Documents\Dynamo\structure.dyn";
            DynamoRevit dynamoRevit = new DynamoRevit();

            DynamoRevitCommandData dynamoRevitCommandData = new DynamoRevitCommandData();
            dynamoRevitCommandData.Application = commandData.Application;
            IDictionary<string, string> journalData = new Dictionary<string, string>
            {
                { Dynamo.Applications.JournalKeys.ShowUiKey, false.ToString() }, // don't show DynamoUI at runtime
                { Dynamo.Applications.JournalKeys.AutomationModeKey, true.ToString() }, //run journal automatically
                { Dynamo.Applications.JournalKeys.DynPathKey, Journal_Dynamo_Path }, //run node at this file path
                { Dynamo.Applications.JournalKeys.DynPathExecuteKey, true.ToString() }, // The journal file can specify if the Dynamo workspace opened from DynPathKey will be executed or not. If we are in automation mode the workspace will be executed regardless of this key.
                { Dynamo.Applications.JournalKeys.ForceManualRunKey, false.ToString() }, // don't run in manual mode
                { Dynamo.Applications.JournalKeys.ModelShutDownKey, true.ToString() },
                { Dynamo.Applications.JournalKeys.ModelNodesInfo, false.ToString() }

            };

            dynamoRevitCommandData.JournalData = journalData;
            Result externalCommandResult = dynamoRevit.ExecuteCommand(dynamoRevitCommandData);
            return externalCommandResult;

        }
    }
}

 

I have followed the solution here:
Run a.dyn from a Revit add-in? - Dynamo (dynamobim.com)
However, the .dyn script doesn't run when I execute the add-in and I get this error message:

Screenshot 2022-10-11 102525.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I have tried to implement the solutions on the thread. Why is this happening?
The files are attached bellow.
Any help is appreciated.

0 Likes
Accepted solutions (1)
392 Views
1 Reply
Reply (1)
Message 2 of 2

joaofmoco
Advocate
Advocate
Accepted solution

I have figured out the solution. I had put the wrong class name and it wasn't running because of that.
It's fixed.

0 Likes