Not all property categories returned from API

Not all property categories returned from API

Anonymous
Not applicable
5,716 Views
13 Replies
Message 1 of 14

Not all property categories returned from API

Anonymous
Not applicable

I have a model that contains a property tab value of "Element" with several properties. When I cycle through the property categories and properties, I would expect to see the category and related properties, but I don't.

 

I have gotten to the point where I am walking every category and property to try and see the properties.

 

My code to iterate over the categories and properties is as follows:

 

Snippet

            foreach (var navisCat in NavisModelItem.PropertyCategories)
            {
                foreach (var navisProp in navisCat.Properties)
                {
                    // create local property
                }
            }

I retrieve categories such as Geometry, Item, Material, and Revit Material. I am not seeing other categories that appear in the model such as Element, Level, Revit Type, Element ID, etc.

 

Is there a different method to retrieve the other categories and properties? I have run through debug mode and do not see the categories in the collection for the model item.

 

Thanks for any help you may be able to provide. 

0 Likes
Accepted solutions (1)
5,717 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Hi!
I think your code is right, propertyCategories should show all categories that your element has. For example, GetUserFilteredPropertyCategories returns only GUI properties.
I use the same method as you and get all element properties. On the other hand not all elements has such categories as Revit Type or Element ID.
0 Likes
Message 3 of 14

Anonymous
Not applicable

Yeah, I've had success with the above code with other models. The current model I am using has the Element, Element ID, etc. properties that I can view in NavisWorks Manage 2016. They show in the property panel. However, they are not returned in the above code. I thought that the above code would return anything that appears in the panel (plus others since I'm not limiting to user filtered). I have actually tried both methods, but neither returns the additional categories.

 

Thanks for your response.

 

The struggle continues...

0 Likes
Message 4 of 14

Aaron.Lu
Autodesk
Autodesk
Dear, would it possible to provide a rvt file (can be uploaded here after zip it) and indicate what element can't work using the above code?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 5 of 14

Anonymous
Not applicable

I have uploaded the Navisworks file in question. I have also provided a screenshot of a model item selection and the properties panel.

 

In the screenshot, you can see that the proprety panel has tabs for: Item, Element, Level, Phase Created, Revit Type, TimeLiner, and Element ID.

 

When running through the code in the original post, I only retrieve properties for the following categories: Geometry, Item, Material, and Revit Material.

 

That means that I am not retrieving: Element, Level, Phase Created, Revit Type, TimeLiner, and Element ID.

 

Thanks,

Jon

0 Likes
Message 6 of 14

Aaron.Lu
Autodesk
Autodesk

Dear,

 

I can see the category using AppInfo, that means it is no problem to get those categories you want, please see below image:

 

Element Tab.png

 

 

PropertyCategory[2] returns the "Element" category, and 

[0] is Project,

[1] is Element ID,

[3] is Level

[4] is Phase Created,

[5] is Revit Type,

[6] is TimeLiner

 

Did you try to use AppInfo to see the same result?

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 7 of 14

Anonymous
Not applicable

I do see the properties when using AppInfo. However, when the model is loaded using the API into an active document in our project, those properties are not available. I have even broken into the selection method, looked at the selected ModelItem directly (not just through the code snippet sent) and it is not showing the categories. That is why this is confusing...

 

In the selected item event, I have printed the categories out in the debug window. This is the result:

"Autodesk.Navisworks.Api.ModelItem", HashCode=1137220496, ReadOnly

Category: LcOaNode(Item)

Category: LcOaExMaterial(Material)

Category: LcRevitMaterialProperties(Revit Material)

Category: LcOpGeometryProperty(Geometry)

 

Is there something in the load that would prevent the other categories from being part of the loaded model?

 

0 Likes
Message 8 of 14

Aaron.Lu
Autodesk
Autodesk

Not sure how you load the model, I'm using AppendFile, which works well, please see below code:

 

public override int Execute(params string[] parameters)
{
    var file = @"D:\SHA95DLF12\ADN\11037542 -navis-no element id\BRIC-NWD1.nwd";
    StringBuilder sb = new StringBuilder();
    var doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
    if (doc != null)
    {
        doc.AppendFile(file);
        Search search = new Search();
        search.Selection.SelectAll();
        search.SearchConditions.Add(SearchCondition.HasPropertyByName("LcRevitId", "LcOaNat64AttributeValue").EqualValue(VariantData.FromDisplayString("331809")));
        var items = search.FindAll(doc, false);
        doc.CurrentSelection.CopyFrom(items);
               
        var selected = doc.CurrentSelection.SelectedItems[0];
        foreach (var propCategory in selected.PropertyCategories)
        {
            sb.AppendLine(propCategory.CombinedName.ToString());
            foreach (var propData in propCategory.Properties)
            {
                sb.AppendLine("\t" + propData.CombinedName + ":" + propData.Value);
            }
        }
        MessageBox.Show(sb.ToString());
    }

    return 0;
}

the output is:

 

LcOaNode(项目)
  LcOaSceneBaseUserName(名称):DisplayString:LW Concrete on Metal Deck
  LcOaSceneBaseClassUserName(类型):DisplayString:Floors: LW Concrete on Metal Deck
  LcOaSceneBaseClassName(内部类型):DisplayString:LcRevitComposite
  LcOaNodeIcon(图标):NamedConstant:LcOaNodeIcon:5(复合对象)
  LcOaNodeHidden(隐藏):Boolean:False
  LcOaNodeRequired(必须):Boolean:False
  LcOaNodeMaterial(材质):DisplayString:
  LcOaNodeSourceFile(源文件):DisplayString:BRIC.rvt
  LcOaNodeLayer(层):DisplayString:Level 3
LcRevitId(Element ID)
  LcOaNat64AttributeValue(值):DisplayString:331809
LcRevitData(Element)
  LcRevitPropertyElementName(Name):DisplayString:LW Concrete on Metal Deck
  LcRevitPropertyElementType(Type):DisplayString:LW Concrete on Metal Deck
  LcRevitPropertyElementCategory(Category):DisplayString:Floors
  LcRevitPropertyElementId(Id):Int32:331809
  revit_Structural Usage(Structural Usage):Int32:3
  revit_Area(Area):DisplayString:211.82 ft ²
  revit_Height Offset From Level(Height Offset From Level):DoubleLength:-0.0833333333333333
  revit_Volume(Volume):DisplayString:88.26 ft ³  revit_Level(Level):NamedConstant:LcRevitElement(Level "Level 3", #255702)  revit_Phase Created(Phase Created):NamedConstant:LcRevitElement(Phase "New Construction", #118390)
  revit_Related to Mass(Related to Mass):Int32:0
  revit_Room Bounding(Room Bounding):Int32:1
  revit_Thickness(Thickness):DoubleLength:0.416666666666667
  revit_Workset(Workset):Int32:522
  revit_Slope(Slope):Double:0
  revit_Edited by(Edited by):DisplayString:RyanWilliams
  revit_Perimeter(Perimeter):DoubleLength:62.0026041666663
  revit_Structural(Structural):Int32:0
LcRevitData(Level)
  LcRevitPropertyElementName(Name):DisplayString:Level 3
  LcRevitPropertyElementType(Type):DisplayString:1/4" Head
  LcRevitPropertyElementCategory(Category):DisplayString:Levels
  LcRevitPropertyElementId(Id):Int32:255702
  revit_Edited by(Edited by):DisplayString:RyanWilliams
  revit_Workset(Workset):Int32:103
  revit_Elevation(Elevation):DoubleLength:136
LcRevitData(Phase Created)
  LcRevitPropertyElementName(Name):DisplayString:New Construction
  LcRevitPropertyElementId(Id):Int32:118390
  revit_Workset(Workset):Int32:13
LcRevitData(Revit Type)
  LcRevitPropertyElementName(Name):DisplayString:LW Concrete on Metal Deck
  LcRevitPropertyElementId(Id):Int32:180521
  revit_Assembly Code(Assembly Code):DisplayString:B1010
  revit_Default Thickness(Default Thickness):DoubleLength:0.416666666666667
  revit_Workset(Workset):Int32:17
  revit_Cost(Cost):Double:0
  revit_Assembly Description(Assembly Description):DisplayString:Floor Construction
  revit_Coarse Scale Fill Color(Coarse Scale Fill Color):Int32:0
LcOdpTimeLinerProperty(TimeLiner)
  LcOdpTimeLinerProperty_TasksContainedCount(包含的任务):Int32:1
  LcOdpTimeLinerProperty_TasksAttachedCount(附着的任务):Int32:1
  LcOdpTimeLinerProperty_ContainedOverlap(包含重复):Boolean:False
  LcOdpTimeLinerProperty_SelectedOverlap(附着的重复):Boolean:False
  LcOdpTimeLinerProperty_ContainedTask1(包含在任务中:1):DisplayString:Install new entry canopies
  LcOdpTimeLinerProperty_ContainedTask_Start1(包含在任务起点 (实际):1):DateTime:2010/12/27 0:00:00
  LcOdpTimeLinerProperty_ContainedTask_End1(包含在任务终点 (实际):1):DateTime:2011/1/14 23:59:00
  LcOdpTimeLinerProperty_SelectedTask1(附着到任务:1):DisplayString:Install new entry canopies
  LcOdpTimeLinerProperty_SelectedTask_Start1(附着到任务起点 (实际):1):DateTime:2010/12/27 0:00:00
  LcOdpTimeLinerProperty_SelectedTask_End1(附着到任务终点 (实际):1):DateTime:2011/1/14 23:59:00

Appologize I did not have English version installed. But you got the idea 🙂

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 9 of 14

Anonymous
Not applicable

We are using the NavisworksViewControl to load the document using the TryOpenFile method. Once the document is opened, we iterate through the model items and pull the properties. The categories I have mentioned are not contained within the model. Is there a difference when loading through the View Control?

 

0 Likes
Message 10 of 14

Aaron.Lu
Autodesk
Autodesk

Dear, it still works for me, except there is no timeliner properties,

please see below screenshot, I embeded the ViewControl in a windows form:

 

DocumentControl.png

 

Related source code:

private void button1_Click(object sender, EventArgs e)
{
    var file = @"D:\SHA95DLF12\ADN\11037542 -navis-no element id\BRIC-NWD1.nwd";
    this.navisDocumentControl.Document.TryOpenFile(file);
    StringBuilder sb = new StringBuilder();
    var doc = this.navisDocumentControl.Document;
    if (doc != null)
    {
        doc.AppendFile(file);
        var search = new Search();
        search.Selection.SelectAll();
        search.SearchConditions.Add(SearchCondition.HasPropertyByName("LcRevitId", "LcOaNat64AttributeValue").EqualValue(VariantData.FromDisplayString("331809")));
        var items = search.FindAll(doc, false);
        doc.CurrentSelection.CopyFrom(items);

        var selected = doc.CurrentSelection.SelectedItems[0];
        foreach (var propCategory in selected.PropertyCategories)
        {
            sb.AppendLine(propCategory.CombinedName.ToString());
            foreach (var propData in propCategory.Properties)
            {
                sb.AppendLine("\t" + propData.CombinedName + ":" + propData.Value);
            }
        }
        MessageBox.Show(sb.ToString());
    }
}


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 11 of 14

Anonymous
Not applicable

Ok, I think we finally have made some progress, at least from reproducing the issue.

 

Please see the attached project and screen shots. The project is hard coded to load the model from the C:\ drive.

 

When you click the process button, 2 things will happen.

 

1) The document (from the DocumentControl) will be searched for the Element ID property, just as you have done in your examples. You will see, in both the screen shots and the running project, the "Category - Property" list contains all the aforementioned categories and properties.

 

2) The document (from the DocumentControl) will walk through all the ModelItems within the Model. You will see, in both the screen shots and the running project, the "Category - Property" list does NOT contain several categories, per my original post issue.

 

In our main project, when we click a model item to select it, the ModelItem returned as part of the selection does not contain the properties either, so we really need to be able to have the properties loaded with the document control and not only returned as part of a search.

 

Please let me know what we can do to alleviate this problem.

 

Thanks,

Jon

 

P.S.

The project I tried to upload exceeded the 5MB limit, so I have pasted the code for the code-behing below. The window was built based on the http://adndevblog.typepad.com/aec/2013/03/use-navisworks-api-with-wpf-create-a-net-control-applicati... example, so you should be able to easily re-create the project.

 

 

using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace NavisTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        DocumentControl _docControl = new DocumentControl();
        HashSet<string> _properties = new HashSet<string>();
        HashSet<string> _searchProperties = new HashSet<string>();

        public MainWindow()
        {
            ApplicationControl.Initialize();

            InitializeComponent();

            viewControl.DocumentControl = _docControl;

            string file = @"C:\BRIC-NWD1.nwd";
            _docControl.Document.TryOpenFile(file);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // search the model, all properties are there
            TestSearch(_docControl.Document);

            // walk the model, missing properties
            ProcessModel(_docControl.Document);
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            // terminate the control application
            // ApplicationControl.Terminate();
        }

        private void ProcessModel(Document doc)
        {
            if (doc.Models.Count > 0)
            {
                Model theModel = doc.Models[0];

                foreach (ModelItem item in theModel.RootItem.Children)
                {
                    ProcessModelItems(item);
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Results from Walking the Model:");
                foreach (string catProp in _properties.OrderBy(s => s))
                {
                    sb.AppendLine(catProp);
                }
                MessageBox.Show(sb.ToString());
            }
        }

        private void ProcessModelItems(ModelItem item)
        {
            if (item.Children.Count() > 0)
            {
                foreach (ModelItem child in item.Children)
                {
                    ProcessModelItems(child);
                }
            }

            if (item.HasGeometry)
            {
                ProcessCategories(item);
            }
        }

        private void ProcessCategories(ModelItem item)
        {
            foreach (PropertyCategory propCat in item.GetUserFilteredPropertyCategories())
            {
                foreach (DataProperty propData in propCat.Properties)
                {
                    _properties.Add(string.Format("{0} - {1}", propCat.DisplayName, propData.DisplayName));
                }
            }
        }

        private void TestSearch(Document doc)
        {
            var search = new Search();
            search.Selection.SelectAll();
            search.SearchConditions.Add(SearchCondition.HasPropertyByName("LcRevitId", "LcOaNat64AttributeValue").EqualValue(VariantData.FromDisplayString("331809")));
            var items = search.FindAll(doc, false);
            doc.CurrentSelection.CopyFrom(items);
            var selected = doc.CurrentSelection.SelectedItems[0];

            foreach (var propCat in selected.PropertyCategories)
            {
                foreach (DataProperty propData in propCat.Properties)
                {
                    _searchProperties.Add(string.Format("{0} - {1}", propCat.DisplayName, propData.DisplayName));
                }
            }
       
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Results from Search:");
            foreach (string catProp in _searchProperties.OrderBy(s => s))
            {
                sb.AppendLine(catProp);
            }
            MessageBox.Show(sb.ToString());
        }
    }
}

 

0 Likes
Message 12 of 14

Aaron.Lu
Autodesk
Autodesk
Accepted solution
The problem should be this line:
if (item.HasGeometry)
in function ProcessModelItems(ModelItem item)

if you comment it, all the categories will be caught.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 13 of 14

Anonymous
Not applicable

Thanks, that's our problem.

 

This is the first model we came across where the selectable items in the model do not have geometry. We were hoping to be able to limit the number of model items we had to process based on being selectable. Guess we are going to have to process them all...

 

I appreciate your patience working through this.

0 Likes
Message 14 of 14

Aaron.Lu
Autodesk
Autodesk
you are welcome 🙂


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes