Navisworks .NET API Properties

By Xiaodong Liang

 

Most of the basic operations of Navisworks are to manipulate properties which are attached to the ModelItem. .NET API expose two main classes: ProperyCategory and DataProperty. Each has an associated collection class: PropertyCategoryCollection, DataPropertyCollection. The figure below shows the relationship between these classes and the ModelItem.

image

 

image

Not all properties are visible to the end user. The visible are known as GUI properties, displayed in [properties] panel in Navisworks.
   – ModelItem.Properties returns all the properties
   – ModelItem.GetUserFilteredPropertyCategories returns GUI only

Each PropertyCategory or Property has an internal name and a display name. From an API point of view, the former is preferred because this is accessible across localised versions. Some built-in category and property names are defined by the API so you don’t need to remember them. Some of the categories/properties commonly found are exposed as more meaningful names in PropertyCategoryNames and DataPropertyNames respectively. For example:

image

Access property

Access property Iteration is the basic way.

// dump the properties of the selected items    Document oDoc =         Autodesk.Navisworks.Api.Application.ActiveDocument;    foreach (ModelItem oItem in            oDoc.CurrentSelection.SelectedItems)     {        // each PropertyCategory        foreach (PropertyCategory oPC                 in oItem.PropertyCategories)         {             Debug.Write("***Property Category  " +                     "[Display Name]: " +                     oPC.DisplayName +                     "[Internal Name]: " +                     oPC.Name + "****n");                  // each property            foreach (DataProperty oDP in oPC.Properties)             {                           // is a display string                if(oDP.Value.IsDisplayString)                {                    Debug.Write("   [Display Name]: " +                                oDP.DisplayName +                  
               "[Internal Name]: " +                                 oDP.Name +                                "[Value]: " +                                oDP.Value.ToString() +                                        "***n");                                                                    }                // is a date / time                if(oDP.Value.IsDateTime)                {                    Debug.Write("   [Display Name]: " +                                     oDP.DisplayName +                                  "[Internal Name]: " +                                 oDP.Name +                                "[Value]: " +                     oDP.Value.ToDateTime().ToShortTimeString() +                     "***n");                 }                             }        }    }

The most frequent usage is by either display name, internal name, or combined name (display and internal).

void getProperty()    {                Document oDoc =            Autodesk.Navisworks.Api.Application.ActiveDocument;        // get the first item of the selection        ModelItem oSelectedItem =            oDoc.CurrentSelection.            SelectedItems.ElementAt(0);             //get a property category by display name             PropertyCategory oPC_DWGHandle =           oSelectedItem.PropertyCategories.           FindCategoryByDisplayName("Entity Handle");             //get a property by internal name         PropertyCategory oPC_DWGHandle1 =            oSelectedItem.PropertyCategories.            FindCategoryByName(            PropertyCategoryNames.AutoCadEntityHandle);             //get a property by combined name         PropertyCategory oPC_DWGHandle2 =             oSelectedItem.PropertyCategories.             FindCategoryByCombinedName(             new NamedConstant(              PropertyCategoryNames.AutoCadEntityHandle,               "Entity Handle"));               //get a property by display name          //(property caterogy and property)          DataProperty oDP_DWGHandle =              oSelectedItem.PropertyCategories.             FindPropertyByDisplayName             ("Entity Handle", "Value");               //get a property by internal name          DataProperty oDP_DWGHandle1 =             oSelectedItem.PropertyCategories.            FindPropertyByName(            PropertyCategoryNames.AutoCadEntityHandle,             DataPropertyNames.AutoCadEntityHandleValue);              //get a property by combined name         DataProperty oDP_DWGHandle2 =             oSelectedItem.PropertyCategories.            FindPropertyByCombinedName(              new NamedConstant(                 PropertyCategoryNames.AutoCadEntityHandle,                  "Entity Handle" ),              new NamedConstant(                  DataPropertyNames.AutoCadEntityHandleValue,                   "Value"));              //display the value of the property. e.g. use one         // DataProperty got above to access its value        System.Diagnostics.Debug.Write(            oDP_DWGHandle.Value.ToString());      }

Where, NamedConstant's are, for most instances, an identifier for a value combining the internal constant's name and a localized display name equivalent. One thing need to know is there are several "built in" NamedConstants, of which PropertyCategoryNames.Item is one. The Navisworks API knows the correct localized user name for these constants – when such a NamedConstant is constructed, Navisworks ignores the user name argument given and uses the appropriate localized name. This is used to ensure that "built in" properties/categories display in the correct language in localized builds. So, ‘FindCategoryByCombinedName’ will work regardless of the user name supplied for Item. e.g. in the code snippet below, all can return the same category: Item.

PropertyCategory oPC_Item0 =         oSelectedItem.PropertyCategories.        FindCategoryByCombinedName(        new NamedConstant(PropertyCategoryNames.Item,            "Item"));         PropertyCategory oPC_Item1 =         oSelectedItem.PropertyCategories.        FindCategoryByCombinedName(        new NamedConstant(PropertyCategoryNames.Item,             "Item12345"));    PropertyCategory oPC_Item2 =         oSelectedItem.PropertyCategories.        FindCategoryByCombinedName(        new NamedConstant(PropertyCategoryNames.Item,            "no_meaning_string"));

(all the codes in this blog is tested with the sample <Navisworks Installation Path>Samplesgatehousegatehouse_pub.nwd.)


Comments

3 responses to “Navisworks .NET API Properties”

  1. Hi Xiadong,
    This is a very useful post and works well. Can you tell me if it would be possible to display this Property data in a DockPane plugin, each time you select a new item? I can see how to do it with an extra button press after the new select but I am trying to avoid that extra button press.

  2. Hi Xiaodong,
    I want to extract properties from BIM models with Navisworks 2015. I think your post is very useful but the first sentence (Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;) returns null. I am new to Navisworks and could you tell me the reason? Looking forward to hearing from you. Thanks

  3. Thanks for the review and such a great post, I’m really impressed. Keep giving us things like this adndevblog

Leave a Reply to CliveCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading