Hide items?

Hide items?

Anonymous
Not applicable
4,156 Views
7 Replies
Message 1 of 8

Hide items?

Anonymous
Not applicable

Hi all,

 

Coding a plugin under C#. Have code in place to nicely find and select an object, but now I want to hide all the objects in the model that aren't the one I'm looking at.

 

Is there a way to do this? Essentially I want to trigger the hideUnselected option in the menubar, but can't find a way to do so.

 

Any tips on how to make the camera jump to a selected item would also be great.

 

Cheers,

-Stuart

0 Likes
Accepted solutions (2)
4,157 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Approach 1 : Get a copy of the CurrentSelection, which holds the item you selected. Invert it, so it contains the entire model except the actually selected item.

InwOpState10 myState = Autodesk.Navisworks.Api.ComApi.ComApiBridge.State;
mySelection = (InwOpSelection2)moState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOpSelection, null, null);
mySelection.SelectAll();
mySelection.SubtractContents(moState.CurrentSelection);
myState.set_SelectionHidden(moSelection, true);

 

 

Approach 2 :Create a InwOpSelection object, use the SelectAll method and then remove the selected item.

InwOpState10 myState = Autodesk.Navisworks.Api.ComApi.ComApiBridge;moSelection = (InwOpSelection2)
mySelection = (InwOpSelection) myState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOpSelection, null, null);
moSelection.SelectAll();
moSelection.SubtractContents(moState.CurrentSelection);
moState.set_SelectionHidden(moSelection, true);

 And zoom the camera:

moState.ZoomInCurViewOnSel();
// or zoom on Selection containing the selected item
moState.ZoomInCurViewOnSel(mySelectedItemSelection);

 Hope this works in plugins as well, I have written only one plugin to see if it works. And it was a long time ago, so I am not sure what API is available in plugins.

 

Message 3 of 8

Anonymous
Not applicable

Unfortunately it doesn't look like I have access to InwOpState10 when developing a plugin. Will continue to play around with it in case I'm missing something....

0 Likes
Message 4 of 8

Anonymous
Not applicable

Add reference to other assemblies like Autodesk.Navisworks.Interop.CompApi, Autodesk.Navisworks.Api etc.

 

Also the examples in C:\Program Files\Autodesk\Navisworks Simulate 2011\api\net\examples\PlugIns may be of a great help. But I think you are aware of these.

 

Good luck.

Message 5 of 8

Anonymous
Not applicable

Hi,

 

Odd. Swear I tried to add those earlier and no dice... But added them just now and it's recognising the InwOpSelection classes.

 

It's not happy with moState and moSelection though. How should I create these?

 

 

Cheers.

0 Likes
Message 6 of 8

Anonymous
Not applicable
Accepted solution

It is not happy with those moState and moSelection because I have mistyped them. They should be myState and mySelection. And I have made another mistake. But I have just created a small plugin and tested it so I can confirm the functionality of following code. I have Simulate 2011 x86.

    // Get a hold of the state object (it is a singleton)
InwOpState10 myState = Autodesk.Navisworks.Api.ComApi.ComApiBridge.State;
    // Create a copy of current selection
InwOpSelection2 myCurrentSelection = myState.CurrentSelection.Copy() as InwOpSelection2;
    // Create a new empty selection
InwOpSelection2 myRestOfModel = myState.ObjectFactory(nwEObjectType.eObjectType_nwOpSelection, null, null) as InwOpSelection2;
    // Get the new selection to contain the entire model
myRestOfModel.SelectAll();
    // Subtract the current selection, so it contains the unselected part of model
myRestOfModel.SubtractContents(myCurrentSelection);
    // Make the unselected part of model invisible
myState.set_SelectionHidden(myRestOfModel, true);
    // Zoom on the currently selected part of model
myState.ZoomInCurViewOnCurSel();

 I included a sample Visual Studio Project. In the zip you will also find a Plugin01.dll which you may copy to a a Plugins\Plugin01 subdirectory of the Simulate 2011 directory, which in my case means

C:\Program Files\Autodesk\Navisworks Simulate 2011\Plugins\Plugin01

Run the program and the plugin to make the unselected part of the model invisible and zoom on the selected part.

 

Enjoy.

 

 

 

 

Message 7 of 8

Anonymous
Not applicable
Accepted solution

Hi Dude

 

I did this 2 weeks ago,  i hope help you....

 

 

//Create hidden collection
            ModelItemCollection hidden = new ModelItemCollection();
            //create a store for the visible items
            ModelItemCollection visible = new ModelItemCollection();

            //Add all the items that are visible to the visible collection
            foreach (ModelItem item in Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems)
            {
                if (item.AncestorsAndSelf != null)
                    visible.AddRange(item.AncestorsAndSelf);
                if (item.Descendants != null)
                    visible.AddRange(item.Descendants);
            }
            //mark as invisible all the siblings of the visible items as well as the visible items
            foreach (ModelItem toShow in visible)
            {
                if (toShow.Parent != null)
                {
                    hidden.AddRange(toShow.Parent.Children);
                }
            }
            //remove the visible items from the collection
            foreach (ModelItem toShow in visible)
            {
                hidden.Remove(toShow);
            }
            //hide the remaining items
            Autodesk.Navisworks.Api.Application.ActiveDocument.Models.SetHidden(hidden, true);

 

 

hide the unselected items.

 

Regards,

 

Sergio  Franco.

Message 8 of 8

Anonymous
Not applicable

Sergio, Warran, you are both amazing. Thank you very, very much.

0 Likes