Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Searching? (Match against an objects 'name'?)

1 REPLY 1
Reply
Message 1 of 2
stuart.r.porter
577 Views, 1 Reply

Searching? (Match against an objects 'name'?)

Hi all,

So... I'm not even entirely sure how to describe what I'm trying to do... But here goes.

In the model I have, there's lots of objects and I need to find certain objects. Currently, I search and match against one of their property fields values. Like so:

 

                Search s = new Search();
                s.Selection.SelectAll();

                SearchCondition condition = SearchCondition.HasPropertyByDisplayName("DMRS", "Value").DisplayStringContains(identifier);
                s.SearchConditions.Add(condition);

                ModelItemCollection collection = s.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);

                if (collection.Count > 0)
                {
                    bool match = false;
                    ModelItem foundItem;

                    foreach (ModelItem item in collection)
                    {
                        /* Trying to find where SP381 is stored.
                        if (((item.DisplayName != null)&&(item.DisplayName.Contains("SP381"))) || ((item.Model.FileName != null)&&(item.Model.FileName.Contains("SP381"))))
                        {
                            MessageBox.Show("Found SP381 item @" + item.DisplayName + ":" + item.Model.FileName);
                        }*/
                        if(!match)
                        {
                            //PropertyCategory category = item.PropertyCategories.FindCategoryByDisplayName("DMRS");
                            foreach (PropertyCategory category in item.PropertyCategories)
                            {
                                if (category != null)
                                {
                                    foreach (DataProperty property in category.Properties)
                                    {
                                        /* Trying to find where SP381 is stored.
                                        if ((property.Value.ToString().Contains("SP381"))||(property.DisplayName.ToString().Contains("SP381")))
                                        {
                                            MessageBox.Show("Found SP381 property @" + category.DisplayName + ":" + property.DisplayName);
                                        }*/
                                        if (property.Value.ToString() == "DisplayString:" + identifier)
                                        {
                                            foundItem = item;
                                            match = true;

 

(With all the appropriate close brackets)

However, we now need to switch to a slightly more dynamic system and the DMRS value isn't a reliable way of finding the objects I'm looking for. When I use the built-in Navisworks search, I can locate the object I'm after by typing in it's name, SP381. However, I've tried searching through all of the properties and can't find this on the object.

So, how do I match agains the objects "name"? Navisworks seems to do it fine, but it's not a property and doesn't seem to be the item name. Anyone know where this data might be getting stored so I can match against it?

Hope that makes sense.

Cheers for reading this! 😃
-Stuart 

 

1 REPLY 1
Message 2 of 2

It is not clear to me with your scenario. I am curious why the codes of search does not return what you are after. Those lines looks fine to me, though you did not provide how the variable identifier is defined. It may be more helpful if you could upload a small sample model file and direct which object you are looking for.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report