How to read custom properties from navisworks file.

How to read custom properties from navisworks file.

Anonymous
Not applicable
7,360 Views
41 Replies
Message 1 of 42

How to read custom properties from navisworks file.

Anonymous
Not applicable

Hi.

 

User is adding additional properties (custom properties) using Navisworks Data Tools. When i am reading the properties from navisworks file using the API's, the API is returning all the properties under "Item", "Material", "Timeliner", "Entity Handle", "Autoplant Component", "Autocad" tabs. But this navisworks file has one more property node called "XYZ"(example, this is user defined name) and this property node has multiple properties user has entered. But the API is not reading these properties. So, the question is how to read Custom or user defined properties from navisworks file?

 

Here is the piece of code to read the properties i have in my project. 

GetValue(oModelItem, null)).GetEnumerator();

while (ePropertyCatIterator.MoveNext())
{
object oPropCatIter = ePropertyCatIterator.Current;
string sCategory = Convert.ToString(oPropCatIter.GetType().GetProperty("DisplayName").GetValue(oPropCatIter, null));


IEnumerator<Object> ePropertyIterator = ((IEnumerable<Object>)oPropCatIter.GetType().GetProperty("Properties").
GetValue(oPropCatIter, null)).GetEnumerator();

      while (ePropertyIterator.MoveNext())
      {
                  object oPropIter = ePropertyIterator.Current;
                  string sValue = Convert.ToString(oPropIter.GetType().GetProperty("Value").GetValue(oPropIter, null));
                   string sName = Convert.ToString(oPropIter.GetType().GetProperty("DisplayName").GetValue(oPropIter,        null));

     }

}

Regards

Sampath

7,361 Views
41 Replies
Replies (41)
Message 2 of 42

Anonymous
Not applicable

Is there a way to read the properties using API's which are added by Data Tools. Though these additional properties which are added by data tools in navisworks file, is shown in navisworks software, when i try to fetch them using the API call as below, i dont get the property categroy which is being added by data tools.. 

 

IEnumerator<Object> ePropertyCatIterator =((IEnumerable<Object>)oModelItem.GetType().GetProperty("PropertyCategories").
GetValue(oModelItem, null)).GetEnumerator();

 

@xiaodong_liang Any help is much appreciated. 

0 Likes
Message 3 of 42

Anonymous
Not applicable

@xiaodong_liang  Please let me know if you have any idea on this topic.. 

0 Likes
Message 4 of 42

ulski1
Collaborator
Collaborator

hi,

the user data that can be added to objects by end users or by code is in a category called LcOaPropOverrideCat

 

br

Ulrik

 

0 Likes
Message 5 of 42

Anonymous
Not applicable

@ulski1 @xiaodong_liang 

But how to read those properties is the question. All the other properties are being read by my above piece of code except the category that user added using data tools. Why is the API not returning those properties?

 

Regards

Sampath

0 Likes
Message 6 of 42

ulski1
Collaborator
Collaborator

These properties need to be handled differently

what I use is a scan of categories via the search object. Look at this thread:

List all of the Categories in the Model - Autodesk Community - Navisworks

 

 

 

0 Likes
Message 7 of 42

Anonymous
Not applicable

@ulski1

 

I have tried with following piece of code, but still those properties were not getting.

 

var miPath = ComApiBridge.ToInwOaPath(item);
var PropertiesCategories = (InwGUIPropertyNode2)state.GetGUIPropertyNode(miPath, true);
int index = 0, i = 0;
foreach (InwGUIAttribute2 propertyCategory in PropertiesCategories.GUIAttributes())
{
if (propertyCategory.UserDefined)
{

}

}

 

What do we called those properties which are added through Data tool? Are they UserDefined properties? 

Above piece of code is correct to get the new category user added through Data Tool?

Can you share any sample code if you dont mind.?

Do we need to specify the name of the category user added through Data Tools to read it or the API will retrun all the categories?

0 Likes
Message 8 of 42

ulski1
Collaborator
Collaborator

did you try it the way it was show in this article:

 

Navisworks .NET API Properties - AEC DevBlog (typepad.com)

0 Likes
Message 9 of 42

Anonymous
Not applicable

Yes i tried the same way.

 

foreach (PropertyCategory oPc in modelItem.PropertyCategories)
{
string DisplayName = oPc.DisplayName;
string Name = oPc.Name;
foreach (DataProperty oDp in oPc.Properties)
{
if (oDp.Value.IsDisplayString)
{
DisplayName = oDp.DisplayName;
string Value = oDp.Name;
string hh = oDp.Value.ToString();
}
if (oDp.Value.IsDouble)
{

}
}
}

 

With the above piece of code i am getting all the categories like "Item", "Material", "Autocad", "Geomerty" "Entity Handle" etc. But the category which user added through data tools is not getting. 

0 Likes
Message 10 of 42

Anonymous
Not applicable

Repeating my work flow one more time for more clarity. Please see the attached image. You can observe a new category called "Safety Properties" added through data tools by below procedure.

 

A name is given to the new DataTools Link. This name will become the name of the properties tab in
Navisworks that includes all of the properties identified in the “Fields” area.
2. Using an ODBC Driver connection, a link is made between the Excel file and the Navisworks file. Upon
selecting the file in Setup. The mapping of the two files is automatically generated.
3. An SQL String needs to be written in order to link the information in the Excel file to the applicable
graphics in the Navisworks file. This is executed by mapping the specific equipment name, known as
“Item Name” in Navisworks, to the “Item Name” column in Excel. The SQL String reads as follows:

 

"Select * From [S.I. Exports$] where "Item Name" = %Prop ("Item", "Name")

 

4.User needs to input the Field Name they wish to see under the new developed “Safety Properties” tab.
For this example, the “Name” of the piece of equipment and the added “Environment Decibel Level”
property will be mapped to the graphics. Only properties that have values will be transferred to individual
graphics. Fig. 14 presents the added safety properties in the newly developed “Safety Properties” tab for
the electrical panel upon the execution of the DataTools process.

 

Finally the new category and the properties were added to the navisworks file. 

 

But when reading categories, "Safety Properties" is not coming for me but the other properties like "Item", "Autocad" etc are coming.Datatools.png

0 Likes
Message 11 of 42

ulski1
Collaborator
Collaborator

one way of reading values from user added properties is to get the property via FindPropertyByDisplayName

like so:

using Nw = Autodesk.Navisworks.Api;
//MI is your Nw.ModelItem object containing the property
using (Nw.DataProperty MyDataProperty = MI.PropertyCategories.FindPropertyByDisplayName(MyCategory, MyProp))
                    {
                        if (MyDataProperty != null)
                        {
                            mystr =MyDataProperty.Value.ToString().Replace(MyDataProperty.Value.DataType.ToString() + ":", "");                  
                        }
                    }
0 Likes
Message 12 of 42

sampath.jeedigam
Enthusiast
Enthusiast

No luck. I tried this but still unable to read that category.

 

DataProperty cat = modelItem.PropertyCategories.FindPropertyByDisplayName("Safety Properties","Name");

 

Its surprising that no where i am finding the information about this and no one is responding too. 😞

 

Regards

Sampath.

0 Likes
Message 13 of 42

ulski1
Collaborator
Collaborator

this code is in production and working here - so you are doing something wrong. I suggest at you hold down shift as you open the options editor, then open Interface->Developer and enable "show property internal names". Then please confirm that you see "Mycategoryname" (LcOaPropOverrideCat) on the objects in question

 

0 Likes
Message 14 of 42

sampath.jeedigam
Enthusiast
Enthusiast

Thank you for your quick response.

 

After following the below suggested workflow, i see the internal name of the user added category as "LcOdpDBDatabaseReadLink"

 

Regards
Sampath.

0 Likes
Message 15 of 42

ulski1
Collaborator
Collaborator

this means the data comes in via a link to a database (or other odbc source). The code suggestions you have been given is for the user data LcOaPropOverrideCat type attribute data so that is perhaps why things are not working

0 Likes
Message 16 of 42

sampath.jeedigam
Enthusiast
Enthusiast

Yes, that is the reason i have mentioned the procedure how we added the properties to NWD File in one of my previous post (Using an ODBC Driver connection). 

 

So, is there an API to get those properties? Actually all the critical properties lies in that category. 

 

Regards

Sampath.

0 Likes
Message 17 of 42

sampath.jeedigam
Enthusiast
Enthusiast

Hi 

 

Do we really have an API in navisworks to read those properties?

0 Likes
Message 18 of 42

sampath.jeedigam
Enthusiast
Enthusiast

@ulski1 @xiaodong_liang  Any help ??

0 Likes
Message 19 of 42

ulski1
Collaborator
Collaborator

hi,

Now I have done the following to help you:

build coderun and appinfo tools from the API to test.

created a navisworks model linked to a datalink

written code in coderun that could read the data - more or less the same code I showed above.

 

here is the code:

using System;
using System.Linq;

namespace CScript
{
    public class CScript
    {
        static public void Main()
        {
            string MyCategory = "MainEquipment";
            string MyProp = "LOCATION_CODE";
            string retval = "Test:";
            try
            {
                if (!Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.IsEmpty)
                {
                    using (Autodesk.Navisworks.Api.ModelItem MI = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems.First)
                    {
                        if (MI != null)
                        {
                            Autodesk.Navisworks.Api.ModelItemEnumerableCollection MeAndMyAncestors = MI.AncestorsAndSelf;
                            foreach (Autodesk.Navisworks.Api.ModelItem SMI in MeAndMyAncestors)
                            {
                                using (Autodesk.Navisworks.Api.DataProperty MyDataProperty = SMI.PropertyCategories.FindPropertyByDisplayName(MyCategory, MyProp))
                                {
                                    if (MyDataProperty != null)
                                    {
                                        retval += MyDataProperty.Value.ToString().Replace(MyDataProperty.Value.DataType.ToString() + ":", "");
                                        retval += System.Environment.NewLine;
                                    }
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(retval);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Sorry, an error occurred: " + ex.Message);
            }
        }
    }
}
0 Likes
Message 20 of 42

sampath.jeedigam
Enthusiast
Enthusiast

Same problem. With the above code i can able to read the "Item", "Material", "Autocad", etc categories but not the one use added category using data tools. FindPropertyByDisplayName() is always returning null when i entered the category name which user added using data tools. 

 

Thank you. 

Sampath.

0 Likes