1

I want to hide certain elements in the view. I managed to hid (with view..HideCategoryTemporary) all the elements I wanted except the marked one in the picture attached. 3D_House_before_hide

Element snoop This element is a building section of category OST_Viewers. Manually hiding the element category via the view works, but fetching all OST_Viewers in the code and hiding them does not work.

The following code contain the building section elements in addition to the grids,

FilteredElementCollector viewers_sections = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Viewers);
FilteredElementCollector grids = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Grids);

FilteredElementCollector elements_to_be_hidden = new FilteredElementCollector(doc, v_id);
elements_to_be_hidden.UnionWith(viewers_sections).UnionWith(grids)

foreach (Element e in elements_to_be_hidden)
{
     cur_view.HideCategoryTemporary(e.Category.Id);
}

I've checked that viewers_sections contains the mentioned building sections however it is not hidden from the view. After hide

How do I hide these building sections?

Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
Razyo
  • 39
  • 6

2 Answers2

1

Please use View#SetCategoryHidden instead to turn off the visibility of the category, the result of the View#HideCategoryTemporary will be reset after closing the file. Here is the working example:

var gridCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Grids);
var sectionsCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Sections);

using(var trans = new Transaction(this.Document))
{
    trans.Start("Hide Grids & Secions");
    this.ActiveView.SetCategoryHidden(gridCate.Id, true);
    this.ActiveView.SetCategoryHidden(sectionsCate.Id, true);
    trans.Commit();
}
Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • Thank you for your answer however this also does not work. The problem is not that the HideCategory is temporary, its working well on all the other elements I want to hide. Its only not working on the building section. Hiding their category (I tried within view, within the whole document) via this code does not work. While it works on the OST_grids and others, it does not work on the OST_Viewers category in this model. – Razyo Jul 06 '20 at 07:55
  • Section's caegory in visivility setting is called `OST_Sections`, it doesn't use `OST_Viewer`. While only hiding section by elelments, you can use `OST_Viewer`. – Eason Kang Jul 06 '20 at 08:59
1
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import *

document = DocumentManager.Instance.CurrentDBDocument
uiDocument = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

view = uiDocument.ActiveGraphicalView

instance = UnwrapElement(IN[0])

def HideElements(view, instance) :

    ids = List[ElementId]()
    
    if not instance.IsHidden(view) and instance.CanBeHidden(view) :
        ids.Add(instance.Id)
        
    TransactionManager.Instance.EnsureInTransaction(document)
    
    view.HideElements(ids)
    
    TransactionManager.Instance.TransactionTaskDone()
    
    return None

HideElements(view, instance)

The above one is the python code for revit dynamo.. Similarly for C# you can use View view = uidoc.ActiveGraphicalView; to get view and inside the transaction use view.HideElements("Your Element ID List"); to hide the element in the Active View

Rocker-APK
  • 51
  • 6