Is there a way to specify what Revit Selection Set to use for a script?

I’m looking to specify a Dynamo script to use the elements from a pre-determined Revit Selection. Does anyone have any suggestions?

What types of elements and how do you know they’ll always be the same elements (ie: same element numbers)?

I have manually designates 6 Revit Selection sets that all contain only MEP Fabrication Pipework elements.

I’m just looking to call back to one of the 6 sets. After I actually have them specified the script should work.

See below:


filters.dyn (6.5 KB)

import clr
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

view = UnwrapElement(IN[0])
name = IN[1]

selection_sets = FilteredElementCollector(doc).OfClass(SelectionFilterElement)

user_selection = []

for s in selection_sets:
	if s.Name == name:
		ids = s.GetElementIds()
		user_selection = [doc.GetElement(e) for e in ids]
OUT = user_selection

The above script retrieves all selection sets in a document and matches a single selection set by name, returning the elements contained within.


Perfect! That is exactly what I was looking for, thank you!!

1 Like

can i do same thing on “Rule-based Filters”
ex: return all Elements at “Interior filter”

The strategy is a bit different, but I think it is possible. I will give it a shot tomorrow and reply to your original thread.

1 Like

Thank you very much