How can I change category visibility in a view template without changing the overrides?
I’m trying to toggle the visibility of a few categories in all my view templates. I am able to do that with my script (see below) but the process wipes out the category overrides I had previously setup in view templates.
How can I set the overrides input to none/null/don’t change?
@Bren Try using the View.SetCategoryVisibility node from the designtech package.
Please pay close attention to the circled levels & lacing or else it might not work.
#Script by AmolShah
#https://forum.dynamobim.com/t/set-category-visibility-without-changing-overrides/60030/
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 *
toList = lambda x : x if hasattr(x, '__iter__') else [x]
views = UnwrapElement(toList(IN[0]))
categories = toList(IN[1])
booleans = toList(IN[2])
status = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i,view in enumerate(views):
if len(categories) == len(booleans[i]):
for category,boolean in zip(categories,booleans[i]):
try:
view.SetCategoryHidden(ElementId(category.Id), boolean)
stats = "Category Visibility updated for " + view.Name
except:
stats = "Category Visibility couldn't be updated for " + view.Name
status.append(stats)
else:
status.append("Booleans not equal to categories")
TransactionManager.Instance.TransactionTaskDone()
OUT = status