Family Element Visibility Settings Python

I don’t have Revit 2019 or Dynamo 2.1 so I made my own in 2018 with Dynamo 2.0.2.

So this is the very basic (slightly janky) version that will work.

import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import * 
doc = DocumentManager.Instance.CurrentDBDocument

def tolist(obj):
	if isinstance(obj, list):
		return obj
	else:
		return [obj]


elems = tolist(UnwrapElement(IN[0]))
bools = tolist(IN[1])

out = []

for elem, b in zip(elems, bools):
	TransactionManager.Instance.EnsureInTransaction(doc)
	try:
		fev = FamilyElementVisibility(FamilyElementVisibilityType.Model)
		fev.IsShownInFine = b
		elem.SetVisibility(fev)
	except:
		fev = FamilyElementVisibility(FamilyElementVisibilityType.ViewSpecific)
		fev.IsShownInFine = b
		elem.SetVisibility(fev)
	TransactionManager.Instance.TransactionTaskDone()
	out.append(True)

OUT = out

There are two types of FamilyElementVisibility classes, one for 3d/multiple view and one for view specific elements but I couldn’t use the property .ViewSpecific to figure out which it should be, it would always just return false even when it is supposed to be true. So I just made it into a try/except statement.

I used your code as a base so there are other limitations on it from that. For example, it is assuming you are entering two equal sized inputs of elements and booleans. If you want to do multiple elements with only a single false boolean, then the script has to be changed.

familyelementvisibility

3 Likes