Set Category Visibility Without Changing Overrides?

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?

Dynamo: set category visibility.dyn (26.6 KB)
Revit: test.rvt (800 KB)

@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.

3 Likes

That does work. Unfortunately my firm has a standard to not use any third party nodes (causes too many breaks).

Does anyone know how to collect the overrides from a view template so I can feed them right back in?

@Bren Collecting overrides doesn’t sound like a good option!
Why not do it the python way?

Only because I don’t know the python way. Would you mind sharing?

@Bren Here you go.

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])
boolean = IN[2]

status = []

TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
	for category in categories:
		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)
TransactionManager.Instance.TransactionTaskDone()

OUT = status

Works like a charm! Thank you so much. :slight_smile:

Dynamo: set category visibility.dyn (21.0 KB)

1 Like

Okay, now to make life for complicated…

Can I use levels and lacing to feed in variable booleans?

Dynamo: set category visibility v2.dyn (21.1 KB)
Revit: test2.rvt (624 KB)

@Bren Levels & Listing won’t help you because of the way I wrote the logic.
I’ve updated the logic for you. See if that works for you now.

#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
2 Likes

Amazing. Thank you again!