How do I hide All "Elements" in a 3D View except the items in my collection?

How do I hide All "Elements" in a 3D View except the items in my collection?

0001des
Enthusiast Enthusiast
8,104 Views
8 Replies
Message 1 of 9

How do I hide All "Elements" in a 3D View except the items in my collection?

0001des
Enthusiast
Enthusiast

I know how to use the View.HideElements to hide a list of Elements in a 3D View.  

How can I do the opposite?  I have a collection of ElementID's and I only want them to be visible in the 3D View.  Everything else hidden.  

 

I'm used to hiding by categories, but my list transcends category types.  These could be all sorts of things in the Revit model, so I have to filter by elementID.

0 Likes
8,105 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

You could use a filtered element collector to gather all the elements from the view and hide all of them except the ones you want. The filtered element collector constructor takes an optional view argument.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

BIM.Frankliang
Collaborator
Collaborator

Hi Friend,

 

     You could hide elements like this:

var visibleElementIds = GetVisibleElementIds(); //your codes for getting visible elements
var ids =  new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).ToElementIds();
// filter constructed depends on your work logic
var hideIds = new List<ElementId>(); foreach(var id in ids ) { if(!visibleElementIds.Contains(id)) { hideIds.Add(id); } } using (var tran = new Transaction(doc, "Test")) { tran.Start(); var view = commandData.Application.ActiveUIDocument.ActiveView as View3D; if(view != null) { view.HideElements(hideIds); } tran.Commit(); }

 

Wish it is helpful for you 🙂

 

Best Regards,

Frank Liang

名片2.png

 

 

0 Likes
Message 4 of 9

0001des
Enthusiast
Enthusiast

I think it's going to be easier to just use the filter to hide everything in the view, then "show" the handful of offending elements. 

 

How do I "show" in a 3Dview using the API's?  I find all sorts of "hide" methods, but nothing for showing?

0 Likes
Message 5 of 9

0001des
Enthusiast
Enthusiast

I've been able to use the filter to collect all the FamilyInstances, then make a simple loop to hide anything that isn't in my "error Collection."   

 

However, when I finish running my subroutine, it hides everything in the 3D View.  I need the offending objects to be visible.  I suspect this is because the offending elements in my model might be a sub-element in these familyInstances.  

 

Is there a way to extract all the element ID's using the filter, without restricting it to typeof(familyInstances)?  I tried to use typeof(Element) and it gave me an error.  

 

 

0 Likes
Message 6 of 9

BIM.Frankliang
Collaborator
Collaborator

Hi Friend,

 

      The first question,  View.UnhideElements() function could be used to show Elements.

      The second question, you could not use typeof(Element) since lots of class objects inherit from Element, including ElementType.  WhereElementsIsNotElementType() could be used to get instance, not types 🙂

 

Wish it is helpful

 

Best Regards,

FrankLiang

名片2.png

 

 

0 Likes
Message 7 of 9

0001des
Enthusiast
Enthusiast

Seriously?  "Unhide."  

 

giphy

 

 

 

Most people would just use the commonplace word "show" when referring to the opposite of "hide."   Whatev's.  Back to the code... Thanks for your suggestion, I'll give it a shot and see if unhide works.

0 Likes
Message 8 of 9

vilo176
Participant
Participant

Old question, but as I was up there ...

Inside a valid transaction you can do (elements being the items you want to show alone) :

view.IsolateElementsTemporary(elements.Select(e => e.Id).ToList());
view.ConvertTemporaryHideIsolateToPermanent();

 

0 Likes
Message 9 of 9

e.deroosJYJVV
Community Visitor
Community Visitor

What I do is: hide everything before you make your selection.

 

First Hide your entire project, select everything, and Hide in View.

Then use; Reveal Hidden Elements

Make your selection, and Unhide these in View.

 

Now you can Export these to an IFC