PAPIWARBUX
PAPIWARBUX

Reputation: 9

What's wrong with my Class Library? 'Fatal Execution Engine Error'

I am trying to make an Plug In for Navisworks manage that will rename a batch of selected clashes with a prefix or suffix. I am running this on Visual Studio.

using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Clash;

namespace ClashTestNameModifier
{
    class Program
    {
        static void Main(string[] args)
        {
            // Open the Navisworks document
            string modelPath = @"C:\path\to\your\model.nwd";
            Autodesk.Navisworks.Api.Application app = new Autodesk.Navisworks.Api.Application();
            Autodesk.Navisworks.Api.Document doc = app.OpenFile(modelPath);

            // Get the selected clash tests
            Autodesk.Navisworks.Api.Clash.TestsData clashTestsData = doc.GetClash().TestsData;
            SavedItemCollection selectedTests = clashTestsData.Tests.Value.GetSelectedItems();

            if (selectedTests.Count == 0)
            {
                System.Console.WriteLine("No clash tests selected.");
                return;
            }

            // Modify the clash test names
            string prefix = "New Prefix ";
            string suffix = " - Suffix";

            foreach (SavedItem testItem in selectedTests)
            {
                ClashTest test = clashTestsData.TestsDataArray[testItem.Index];
                test.DisplayName = prefix + test.DisplayName + suffix;
            }

            // Save the modified document
            doc.SaveFile(modelPath);

            // Close the document
            doc.Close();

            // Dispose of the application
            app.Dispose();

            System.Console.WriteLine("Clash test names modified successfully!");
        }
    }
}

When I run the program I get the following errors.

enter image description here

IMAGE 2

Upvotes: 0

Views: 266

Answers (1)

Pedram Elmi
Pedram Elmi

Reputation: 389

To create a plugin for Navisworks, you need to start by creating a class library project in the .dll format. The simplest type of plugin is AddinPlugin, which can be found in the Autodesk.Navisworks.Api.Plugins namespace. For more information on creating Navisworks plugins, you can refer to the link provided below.

https://apidocs.co/apps/navisworks/2018/87317537-2911-4c08-b492-6496c82b3ed6.htm

I have tried to edit your code so that it works, but one issue is that the Navisworks Clash API does not currently support the retrieval of selected tests from the UI. The documentation states that the UI part of the Clash API is still underdeveloped.

using Autodesk.Navisworks.Api.Clash;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;

namespace ClashTestNameModifier
{
    [Plugin("ClashTestNameModifier.PAPI", "PAPI", DisplayName = "ClashTest Name Modifier")]
    [AddInPlugin(AddInLocation.AddIn)]
    public class ClashTestNameModifierAddinPlugin : AddInPlugin
    {
        public override int Execute(params string[] parameters)
        {
            // Open the Navisworks document
            string modelPath = @"C:\path\to\your\model.nwd";
            Autodesk.Navisworks.Api.Document doc = Autodesk.Navisworks.Api.Application.MainDocument;
            doc.OpenFile(modelPath);

            // Get all clash tests
            Autodesk.Navisworks.Api.Clash.DocumentClashTests clashTestsData = doc.GetClash().TestsData;

            // Clash API does not support the selected tests yet.
            // But, assume that selected tests are found with a method
            SavedItemCollection selectedTests = FindSelectedTests(clashTestsData);

            // Modify the clash test names
            string prefix = "New Prefix ";
            string suffix = " - Suffix";

            foreach(SavedItem testItem in selectedTests)
            {
                var test = testItem as ClashTest;
                clashTestsData.TestsEditDisplayName(testItem, prefix + test.DisplayName + suffix);
            }

            // Save the modified document
            doc.SaveFile(modelPath);

            return 0;
        }
    }
}

In order to run this on a console application, you may need to reference and use the Autodesk.Navisworks.Automation assembly. With Automation, it's also possible to invoke a plug-in and receive a reply in the form of a status code. For additional information, please visit the following link:

https://apidocs.co/apps/navisworks/2018/87317537-2911-4c08-b492-6496c82b3ed7.htm

Upvotes: 0

Related Questions