Simple Traversal through a Model using Navisworks .NET API

By Saikat Bhattacharya

How can we traverse through all the components in a Navisworks file using the .NET API?

To traverse through all the components in the model, you can use the following simple approach to iterate through each model item.

using System;

using System.Collections.Generic;

using System.Text;

//Add two new namespaces

using Autodesk.Navisworks.Api;

using Autodesk.Navisworks.Api.Plugins;

namespace BasicPlugIn

{

   [PluginAttribute("BasicPlugIn.ABasicPlugin",                  

                    "ADSK",                                      

                    ToolTip = "BasicPlugIn.ABasicPlugin tool tip",

                    DisplayName = "Sample Plugin")]         

 

   public class ABasicPlugin : AddInPlugin

   {

      public override int Execute(params string[] parameters)

      { 

        foreach (ModelItem item in

          Autodesk.Navisworks.Api.Application

          .ActiveDocument.Models.RootItemDescendantsAndSelf)

        {

          System.Diagnostics.Trace.WriteLine(

            "Display Name: " + item.DisplayName +

            "; Class Display Name: " + item.ClassDisplayName +

            "\n");

        }

        return 0;

      }

   }

}

Just as a warning – this approach can be little slow and if you are traversing to access a specific item, please use the Search APIs.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading