Specify View via code block or python

I did some searching around and found this post a while ago, this should help give an understanding of the idea to use.

I’ve also inputted that code into python and played around with it to achieve what you are looking for.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry 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


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



elements = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()

def filter_list(elements, search_str):
	"""Given a list of Views, returns only those which
	contain a given string in their name"""
	passed = []
	for element in elements:
		name = element.Name
		if search_str in name:
			passed.append(element)
	return passed

# The inputs to this node will be stored as a list in the IN variables.
NameSrch = IN[0]

FoundViews = filter_list(elements, NameSrch)
	


# Assign your output to the OUT variable.
OUT = FoundViews

Hope this helps!

3 Likes