A schedule’s category is ScheduleGraphics but a legend’s category is Viewport the same as a regular view.
How can I differentiate between a legend and a view on a sheet when I’m selecting in the Revit window?
Eg, how do I prevent the user from selecting a regular view when all I want them to select is the legend view?
I’m asking how to allow the selection of ONLY a legend view.
The legend on a sheet is the same category as any other view. I’d like to specifically allow the user ONLY to select the legend.
This is working for me. It will return the viewports on the sheet which contain a legend. You can ask a viewport for its view from there which has a node in later versions, or the ViewId property of the viewport itself if you prefer. As Jacob mentioned, legends occur as viewports on sheets, the legend itself is the single view in the browser.
# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au
# Boilerplate text
import clr
import System
from System.Collections.Generic import List
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import Selection
from Autodesk.Revit.UI.Selection import ISelectionFilter
# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
# Force list function
def uwlist(input):
result = input if isinstance(input, list) else [input]
return UnwrapElement(result)
# Preparing input from dynamo to revit
runMe = IN[0]
elements = []
# Make selection filter class
class selectionfilter(ISelectionFilter):
def AllowElement(self, element):
try:
vp_view = doc.GetElement(element.ViewId)
if vp_view.ViewType == ViewType.Legend:
return True
else:
return False
except:
return False
if runMe:
# Create selection filter
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, selectionfilter())
# Lists for appending/adding
elementIds = List[ElementId]()
# Try to get elements for selection
for s in sel:
try:
id = s.ElementId
el = doc.GetElement(id)
elements.append(el)
elementIds.Add(id)
except:
pass
# Select the elements
selection = uidoc.Selection.SetElementIds(elementIds)
# Preparing output to Dynamo
OUT = elements
Slight variants on processing the outcomes:
Just get the viewports and append to elements list:
if runMe:
# Create selection filter
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, selectionfilter())
# Lists for appending/adding
elementIds = List[ElementId]()
# Try to get elements for selection
for s in sel:
try:
id = s.ElementId
el = doc.GetElement(id)
elements.append(el)
except:
pass
Get the legend of the viewport itself, append as elements:
if runMe:
# Create selection filter
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, selectionfilter())
# Lists for appending/adding
elementIds = List[ElementId]()
# Try to get elements for selection
for s in sel:
try:
id = s.ElementId
el = doc.GetElement(id)
lv = doc.GetElement(el.ViewId)
elements.append(lv)
except:
pass
Someone is going to have to put some nodes together to pass these via zero touch nodes if we are going to make this scale. Not a fun task and it’s going to take a b it but I’m guessing it’ll go faster than waiting on Python to resolve it.