Setting Revision Visibility with Python - RevisionVisibility Enumeration Members

Amy,

This is good stuff. You were really close. Here’s how to make this work:

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

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

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

revisions = UnwrapElement(IN[0])

# enumeration class can be parsed by it's member's name
vis = System.Enum.Parse(Autodesk.Revit.DB.RevisionVisibility, IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)

if isinstance(revisions, list):
	# we have a list here let's iterate over it in a loop
	for r in revisions:
		r.Visibility = vis

TransactionManager.Instance.TransactionTaskDone()

OUT = [v.Visibility for v in revisions]

Now a few things that explain what’s going on. First and foremost the Select Revision Visibility node outputs a string representation of the RevisionVisibility class from Revit API. You can see that on my image where I put Object.Type and it says System.String. Why does that matter? It does, because what we have here is a string, and not an actual enum object.

Now, that we are talking about enums. To briefly explain what they are. Think of them as immutable lists. That means they hold some items in an ordered collection, but you cannot neither remove nor add more to that list. They are pretty good for things that you know you only have certain amount of, and you never want to add/remove any but you need a really fast access to it. Since they are ordered, you can access items in an enum via it’s index etc. Here’s some more on Enums. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/enum

Now, knowing we are dealing with an enum and we had it’s string representation we can use System.Enum.Parse() to convert from string to Enum. You see that in my code.

Once we sorted that out, the rest was like you had it.

Cheers!

6 Likes