Navisworks API : Adding Property to Existing Category

Welcome to the seventh tutorial of Navisworks® API series, this post is to cover how to add custom property to the existing category via  Navisworks® COM (Component Object Model) API. This tutorial is a continuation of the third tutorial of our Navisworks API series, Navisworks API : COM Interface and Adding Custom Property.

Adding New Property to Existing Category

So, first things first, setting up Navisworks® Add-Ins project in the visual studio, you can follow Creating Navisworks Add-Ins tutorial to set up the project. In the previous tutorial we’ve already discussed about the equivalent between Navisworks® .Net API objects and COM API objects. So, I strongly recommend you to go through with the previous tutorial first.

Whenever you are ready, in the Execute method, create a list of variables : doc to store the current document, cdoc for COM State object (the document object), items for the current selected ModelItems. Next variable is InwOaPath (Path object in COM) which is a ModelItem (.Net API), ComApiBridge has ToInwOaPath method to convert a ModelItem to Path(COM object). InwGUIProertyNode2 (COM object) is equivalent to .Net ModelItem’s PropertyCategoryCollection object and from this object we can collect all the related PropertyCategories data. (figure 1.0)

figure 1.0 – Execute Method

Next step is to loop through each of the PropertyCategory to check has user created? and is the category’s name is “Premier League” ( “Premier League” Category was created in the previous tutorial). (figure 1.1)

InwGUIPropertyNode2 (PropertyCategoryCollection) object allow to create PropertyCategory by using it’s SetUserDefined method. The first argument of this method is whether create or overwrite ( “0” is to create new PropertyCategory, “1” is to overwrite existing PropertyCategory). Second and third arguments are for the DisplayName and InternalName. The last one is for PropertyCategory data, here we have called our custom method, AddNewPropertyToExtgCategory, and provided as an argument. (figure 1.1)

figure 1.1 – Creating PropertyCategory

In AddNewPropertyToExtgCategory method, the only argument propertyCategory is to retrieve all the existing PropertyData and the return value is InwOaPropertyVec which is user created PropertyCategory. We have two variables, cdoc for COM State and category for a new PropertyCategory object. (figure 1.2)

So far, the only way to add new PropertyData to existing PropertyCategory is – create a new PropertyCategory with the same name, retrieve all the existing PropertyData and add new PropertyData.

figure 1.2 – AddNewPropertyToExtgCategory method

Loop through each Property from the argument (propertyCategory) and create new Property with the existing PropertyData (such as.. InternalName, DisplayName, Value) and add to our newly created PropertyCategory. (figure 1.3)

After retrieving all the existing PropertyData, we create a new Property for our PropertyData. So, as you can see in figure 1.3, property’s Name is “2021 Champions” and Value is “Who Knows!!”. Finally add to the PropertyCategory and return user created PropertyCategory. (figure 1.3)

figure 1.3 – AddNewPropertyToExtgCategory method

Well, that’s all for this tutorial, I hope not too confuse you and download the complete source code from here, Cheers!

Advertisement

2 thoughts on “Navisworks API : Adding Property to Existing Category

  1. Hi Min,

    Just wanted to say thank you for your effort and posts you made.
    It really helped me a lot with learning how to exploit functionality from APIs.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.