Save selection set by element?

Hello, is this Clockwork node broken in 1.2 ?

Thank you

Hi @Giovanni_Succi,

Can you open the Custom node and copy the contents to the master graph, plug it in and see what warnings you are getting? The warnings are hidden while wrapped in the custom node and it’s impossible to see what’s wrong with your current image.

Cheers,
Dan

Hi Giovanni

I found got a simalr result in one of my scripts. The reason for the null is in my case that the model include filters with name including special signes like æøå (Danish letters) After a bit of renaming to the filters the node “SelectionSet.BeElements” works well.

Hi,
I’ve got same problem. Has Anyone found a solution?

I can’t replicate this error. Can you please upload the graph you are using and also a sample revit file that you are getting errors with so we can have some more context.

Yes of course. Here it is:

Hi,
I stuck in this place without idea why You can use this node without any problem. Thanks in advance for any suggestion.

Hi @PiotrS,

Apologies for the delay, I didn’t get a chance to look at this over the weekend.

I tested your script and model, in 2020 it works fine. However, in 2018 it does not. I traced this back from the error to one line of code which was…

if str(filter.Name) == name:

That I replaced with…

if filter.Name == name:

Here is the full code which you can copy into the node…

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from System.Collections.Generic 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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

import traceback

doc = DocumentManager.Instance.CurrentDBDocument
name = IN[1]

# create itemset
items = UnwrapElement(IN[0])
ids = list()
for item in items:
	ids.append(item.Id)
itemset = List[ElementId](ids)

try:
	# collect all existing filters from the model 
	names = list()
	collector = FilteredElementCollector(doc)
	filters = collector.OfClass(FilterElement).ToElements();
	
	selset = False
	TransactionManager.Instance.EnsureInTransaction(doc)
	# if a filter of that name already exists, delete its content
	for filter in filters:
		if filter.Name == name:
			filter.Clear()
			selset = filter
	# create a new selection set if it doesn't already exist
	if selset == False:
		selset = SelectionFilterElement.Create(doc,name)

	selset.AddSet(itemset)
	OUT = selset.ToDSType(False)
	
	TransactionManager.Instance.TransactionTaskDone()
except Exception, ex:	
	OUT = traceback.format_exc()

I’m not sure why this is an issue, I will dig into it more.

Cheers,
Dan

6 Likes

Ok, had a quick look at the why. It turns out that the Filter.Name is in Unicode. For some reason, when converting this to string in Revit 2018, the encoding fails with this error. However, in 2020 this is not an issue. The python I supplied above seems to work in both cases, regardless or the language I am using. If it fails, let me know.

Cheers,
Dan

2 Likes

Hi Daniel,
It works :wink: Thank You very much! I attached my script which is connected with “rythm” node. Useful when You need to get all elements with the same value of choosen parameter.


Selection set_v.2.1.dyn (19.5 KB)

2 Likes

Nice one @PiotrS! Glad you have it all up and running nicely now!

Hello again,
Could You tell me, is it possible to get the selection set (and all elements within it) by its name?

Hi,
I’m still trying to find a solution. I’ve tried 3 different nodes, but without success.
Maybe someone knows how to do it with CodeBlock?

Ok, if someone needs a solution, here it is:


Inputs: Value and Filther Method:
image

how do you select the selection set after creating it?

You can retrieve them like this :

1 Like

@Alban_de_Chasteigner I had this python code that does same but it does not work now trying on Revit 2021
image

but well I got 2 more options without python, one seems new in Dynamo selection of element by ID:

Amazing, thank you