suggestion for show objects api method

suggestion for show objects api method

ulski1
Collaborator Collaborator
3,893 Views
25 Replies
Message 1 of 26

suggestion for show objects api method

ulski1
Collaborator
Collaborator

 

hi,

this is mainly a cry out to the Navisworks dev team.

it would be really useful if the Navisworks dev team could add a method to the API which takes a collection of model items and make them visible without affeting already hidden objects not in the collection(parent or grand parent objects are sometimes hidden causing all grandkids to be invisible and we do not want sibling objects to become visible if the grand parent is made visible so a lot of testing is needed and I can not find a way to ask an object "are you truly visible" ). My unqualified guess if that it should not be "crazy expensive" to add a "show method" because some super fast code is already available as "Show" on the context (right click menu) on selection sets and search sets in the "manage sets" dialog. I'm aware of the c# sample code which mimics the "show" code by looping and testing what objects are hidden but I think for the size of models we have it will be impossible to get the same outstanding performance the "native" show code have.

 

br

Ulrik

 

 

2016-09-13_14-25-19.png

 

0 Likes
Accepted solutions (2)
3,894 Views
25 Replies
Replies (25)
Message 2 of 26

xiaodong_liang
Autodesk Support
Autodesk Support
Hi Ulrik,

Sorry I have not understood the scenario nicely. Since you showed a product feature in the snapshot, may I know the product feature works much faster than your API codes? is it possible you could provide some code snippet and another snapshot on what you wanted to hide/make visible? This is just to make sure I understand correctly then I can forward the wish to our engineer team. Thnk you.
0 Likes
Message 3 of 26

ulski1
Collaborator
Collaborator

hi Xiaodong,

the built-in feature is really useful for users, in my opinion the "Show" feature should be added as a button next to the big green hide button in the ribbon home tab -> Visibility panel.(this in addition to my API suggestion). I think it is an oversight that it is not there.

 

The reason that I want a way to start the "show" code from the API is that we have a custom search plugin which searches for and then clip or hide colorize the result and zooms to the result in one operation (like google search for Navisworks).

Our search plugin needs to be able to make objects visible which matches the search result in case the users have previuosly hidden it (which is what "show" does).

 

To replicate the code inside the show button you need to check if each object in the result set are hidden then you need to check if the parent and grand parent objects is hidden. For those of the parent and grand parent objects who are hidden the code then toggle the grand parent and parent object to visible. Problem is that this will affect visiblilty of all objects below - it will make siblings of the object in the search result visible even if they are not in the search result.

 

To program this you need a lot of loops and for huge nwd files around 700mb in size this will cause a long wait for each search.

The lovely thing is that it seems like some clever person in the Navisworks dev team coded  the "show" code so it handle all this complexity super fast and it is a real shame that is can not be called from c#

 

Ulrik

 

0 Likes
Message 4 of 26

Anonymous
Not applicable

Ulrik,

Wouldn't this be faster to show objects? 

dim showMic as New ModelItemCollection
Application.ActiveDocument.CurrentSelection.SelectedItems.CopyTo(showMic)
'Copy selection to speed up if selection is search For each mi as ModelItem in showMic Application.ActiveDocument.Models.SetHidden(mi.AncestorsAndSelf, False) Next

 

0 Likes
Message 5 of 26

ulski1
Collaborator
Collaborator

hi blanicolas,

the code you suggested does not replicate the built in show command. If you unhide ancestorsandself you will make siblings visible which are hidden but not in the selection set. This is what I try to avoid. The code we use today is quite like the code you suggested but people are angry about that it make too much visible.Ulrik
 
0 Likes
Message 6 of 26

xiaodongliang
Contributor
Contributor

Hi ulski,

 

 

I think I got what your scenario is now.  I also did some tests.

 

What I found is: if a parent node is hidden, any sub nodes cannot be visible. So, I am not clear why you got a scenario that you would need to take care of the visibility of the sibling nodes.

 

In another word, assume we have such tree:

 

Parent Node

         Child 1

         Child 2

 

I do not see a scenario that Parent Node is hidden while Child 1 or Child 2 is shown.

 

And, if for some reason, Child 1 is hidden, when we want to make it visible (show), we simple call SetHidden(modelitems, false). It will not affect the status of any other nodes.

 

This is test video shows what I found above.

 

http://autode.sk/2dePFfh

 

Could you check and provide a bit more information on the scenario you are struggling with?

 

0 Likes
Message 7 of 26

Anonymous
Not applicable

Hi Ulrik,

 

Ah yes you're right. Sibling visibility is changed if parent is hidden. The best I can find to replicate this behaviour is this:

Private Sub UnhideSel()
        Dim curSel As New ModelItemCollection
        Application.ActiveDocument.CurrentSelection.SelectedItems.CopyTo(curSel)

        Dim ancestorsAndSelfMic As New ModelItemCollection
        Dim descendantsMic As New ModelItemCollection

        Dim mi As ModelItem = Nothing
        For Each mi In curSel
            ancestorsAndSelfMic.AddRange(mi.AncestorsAndSelf)
            descendantsMic.AddRange(mi.Descendants)
        Next

        'Loop through ancestors backwards to go down the tree
        For i = ancestorsAndSelfMic.Count - 1 To 0 Step -1
            mi = ancestorsAndSelfMic.Item(i)
            If mi.IsHidden Then
                Application.ActiveDocument.Models.SetHidden(mi.Children, True)
            End If
        Next

        Application.ActiveDocument.Models.SetHidden(ancestorsAndSelfMic, False)
        Application.ActiveDocument.Models.SetHidden(descendantsMic, False)
    End Sub

But that's perhaps too slow in your testing?

0 Likes
Message 8 of 26

ulski1
Collaborator
Collaborator
hi Xiaodong, Please see my screencast http://autode.sk/2df4H4W here I demonstrate what the show command is capable of using the Eircom park sample model. Ulrik
0 Likes
Message 9 of 26

ulski1
Collaborator
Collaborator
hi Nic.White, the whole point of my post is that the performance of the built show command works almost instant even on giantic models, but to replicate it via looping in .net will cause end users to wait minutes for every search and that is just not acceptable
0 Likes
Message 10 of 26

xiaodong_liang
Autodesk Support
Autodesk Support

Hi Ulrik,

 

It is strange I failed to attach image. anyway, in your video, firstly, you hided the parent  Pith_Sl, so self and decedent nodes are all hidden. Then you created a selection set for the second level node Pith_Gr, and call Show of the selection set. So Pith_Gr and its child (the geometry node) and Pith_Sl are also visible now.

 

This workflow looks same if you simply call SetHidden on the selection set as I showed in the last message. i.e. it seems you do not need to care about the sibling nodes of Pith_Gr, just call SetHidden. is it fine to you to show something of the problem when you call API? 

0 Likes
Message 11 of 26

ulski1
Collaborator
Collaborator

hi Xiaodong,

the autodesk builtin to the show command have built in counter measures which hides the siblings which are not supposed to be visible. Also simply toggling hide = false on the selected items like in the video you sent will not make the selected object visible if the parent is hidden. The smart thing about the code inside the show command is that it will ALWAYS maked the selected object visible (even if parents are hidden) AND at the same time it makes sure that siblings stay hidden (if the partent was initial hidden). 

 

Ulrik

0 Likes
Message 12 of 26

xiaodong_liang
Autodesk Support
Autodesk Support

Hi Ulrik,

 

the key issue that is not clear to me is: no matter my test or your test, I do not see a scenario that parent can be hidden yet the children are visible. e,g, as said yesterday, the video shows:

 

firstly, you hided the parent Pith_Sl, so self and decedent nodes are all hidden. Then you created a selection set for the second level node Pith_Gr, and call Show of the selection set. So Pith_Gr and its child (the geometry node) and Pith_Sl are also visible now

 

Sorry for my ignorance, could you show me a scenario that parent is hidden while the child is visible? 

 

assume such scenario  exists, I do not find a better way than iterate each model item and manage their visibility, but at least, you could just iterate the path of a specific node of first level, instead of all nodes of a model. Then it would not cause much time. 

 

anyway, I will need to get  such scenario (parent can be hidden yet the children are visible) and compare API and UI abilities. Thanks.

0 Likes
Message 13 of 26

ulski1
Collaborator
Collaborator

you misunderstand how the "show command" works. I will explain in a different way. The end user hides the entire grass (grand parent object) one toggle only on grand parent. Then later the end user search for one of the markings on the grass and he only want to see this one making not the sibling markings on the grass. the only hiding rules sits one the grand parent. What the show command does is that it unhided the grand parent object so every thing becomes visible but in the same transaction it also toggle hiding on all the siblings which the uses was not interested in. 

like this:

1 unhide grand parent

2 hide all sibling objects expect the childern the user searched for or selected

0 Likes
Message 14 of 26

ulski1
Collaborator
Collaborator

one more comment to get you to understand why performance is an issue. imagine the user is in a 800mb nwd file. now the user does a search which will return 100000 child objects. now you need to make the the parents and grand parent of 100000 objects visible and set hiding og the 900000 sibling objects which was originatly hidden due to the initally hidden parent or grand parent objects. this works nicely with the fast show command and if you can show be c# code with the same performace I can use this but I don't think you can get the same performce using looping in c#

0 Likes
Message 15 of 26

xiaodongliang
Contributor
Contributor

Hi ulski,

 

Please bear with me discussing further:

 

Assume we have the hierarchy:

 

Grand Parent

         Parent 1

                  Child 1-1

                  Child 1-2

         Parent 2

                  Child 2-1

                  Child 2-2

 

What I have not got is the scenario that Parent 1 = visible while Grand Parent = hidden, no matter your test or mine. So I thought I can simply run the code below to toggle Parent 1 with show/hide. It looks to me it does not need to check the status of Parent 2 or Grand Parent.

 

Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

//assume Parent 1 has been created as the first selection set

SelectionSet oSet = oDoc.SelectionSets.Value[0] as SelectionSet;

oDoc.Models.SetHidden(oSet.ExplicitModelItems, false);

 

In my test video last time, what I SetHidden are the model items which I have selected explicitly. These days, I found if it is a Selection Set and has been toggled with show/hide manually, SetHidden does not work. e.g. with the code above, the first selection set cannot be visible with the code.

 

So I cannot verify if SetHidden on selection set directly could be a solution for you L Is this why you had to find way to toggle by code but hit the performance issue?

 

Again, since I did not get a scenario that Parent 1 = visible while Grand Parent = hidden, I still think SetHidden on the selection set should be enough. I will check with engineer team on the behavior of SetHidden does not work, but in the same time, I’d appreciate if you could further help me understand why you need to check the status of Parent 2 or Grand Parent. I will also ask our engineers to take a look in case they know better than me.

0 Likes
Message 16 of 26

ulski1
Collaborator
Collaborator
Hi Xiaodong, The thing you fail to understand is that our end users of do a seiries of searches and the hide everything they are not interested in - but them later they find out that they lack a few objects but these obects is one or 2 objects among 10000 hidden siblings - if you use your code to toggle the hiding rule on the partent all 10000 siblings will become visible and that is not what the want - the want to make the parent visible and then hide the 10000 siblings so they are left with the 2 child objects they are interested in. The only way to do this is by using the show command. Call me on lync/skype and we can have a talk about it. I do not think I can explain it so you understand it 😞
Message 17 of 26

Anonymous
Not applicable

If I may interject, as this would be a useful function indeed. Perhaps this image will help:

 

 Show.jpg

0 Likes
Message 18 of 26

ulski1
Collaborator
Collaborator
nice illustration - that was what I tryed to show in the video
0 Likes
Message 19 of 26

xiaodong_liang
Autodesk Support
Autodesk Support

Thank you Nic.White!

 

Hi ulski,

 

I also  gave a couple of tests further and finally got what I confused.

 

looking at my test video in message 6 again, I found the reason why that code looks working well was just because the ancestor has been visible before I ran that code. This also explains why it did not work when I tested with SelectionSet. I thought it is a different behavior of SelectionSet or explicitly selected items, but actually if the ancestor(s) are hidden, the SetHidden does not work for the sub items that I wanted to show. i.e. no response when SetHidden. 

 

So, I have to find out the ancestor(s) and also descendants of the item(s) to make sure they are going to be visible. Then, I hit the problem you reported in this post. i.e. 

#1,  IF the ancestor(s) is hidden, after SetHidden on a SelectionSet (or explicitly selected items) in the hierarchy, all sibling items in the same hierarchy will be also affected. 

#2, BUT, if ancestor(s) is visible already (no matter how it is set to be visible), after SetHidden on a SelectionSet (or explicitly selected items) in the hierarchy, the status of all sibling items in the same hierarchy will NOT be affected.

 

The video below tells more.

http://autode.sk/2dR1I68

 

the code in the video I used is:

 

  Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument; 
          SelectionSet oSet = oDoc.SelectionSets.Value[0] as SelectionSet;

          ModelItemCollection ancestors_self_descendants = new ModelItemCollection();
          foreach(ModelItem item in oSet.ExplicitModelItems)
          {
              ancestors_self_descendants.AddRange(item.AncestorsAndSelf);
              ancestors_self_descendants.AddRange(item.Descendants);
          }


           MessageBox.Show(ancestors_self_descendants.Count.ToString());
 
          oDoc.Models.SetHidden(ancestors_self_descendants, false);

 

although for #1, restore the status of sibling one by one could be an approach, however as you have experienced, it will hit performance issue. While compared with #2, it is a bit strange behavior to me.

 

I will check with our engineer team on the behavior and the possible solution. Sorry for my slow understanding.

 

Message 20 of 26

ulski1
Collaborator
Collaborator
Xiaodong, It pleases me that you picked up on that the "show command" makes objects visiblie without affecting the visibility of objects not in the selection set. It is a bit sad that the "show" command is not more known by Navisworks users but the fact that it is hidden on the "manage sets" right click menu of course explains this. Again, in my opinion the "show" command should have been next to the big green hide button in the ribbon menu and (as this whole thread is about) a way to start the "show" command from the API. If you want to replicate the show command in C# you should ask devs for the c++ code used by the show command - that way so you can learn how it loops. I think the reason why code like this causes a lot of looping, is that in the API you can not ask an object "are you already visible" if that was possible you could speed up things by skipping objects already visible. In previous years when I tried to explain the need for a "isvisible" feature to Autodesk the persons I interacted with did not understand that hidden true/false is not the same as "isvisible" due to parents or grand parents overriding the hidden attribute of lower level objects. In Navisworks there has to be internal code that holds a list of visible objects - how could you else know what objects to draw in the view? br Ulrik