Find Elements by a list of Element ID

Hi,

I was wondering if you could help me to detect the elements according to a list of element IDs that are imported from an Excel sheet.

Please let me know how I can convert the list of IDs to readable for Select.ByElemendId node.

When you import from excel, most of the time the data comes in as text.
You need to convert the text to numbers.
a String to Number node can do that.

I tested with String.ToNumber, but it doesn’t work.

How old is this file you are reading?
See Element.ID’s can change in Revit, so if you add a workset or something major likewise, ID’s change.
If you are the one creating these excel files in the first place, consider using the Element.UniqueID instead, it’ s much more stable.

You’ll definitely want to confirm your Ids are still good, like Marcel suggested.
The Select.ByElementId node is a little finicky though. It should work for a string or an integer. You can always try to force it with python. This should work regardless of the object type (as I convert it to an integer anyway) as long as it’s a valid Id.

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

doc = DocumentManager.Instance.CurrentDBDocument

dataEnteringNode = IN
ids = IN[0]
out = []

for id in ids:
	element = doc.GetElement(ElementId(int(id)))
	out.append(element)

OUT = out

image

3 Likes

Can I try same procedure with Element Unique ID?

Hello, here an example

import clr
import sys
import System
from System import Int16, Int32, Int64, String
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

def getElementByValue(v):
	# if value is ElementId or Reference object
	if isinstance(v, (ElementId, Reference)):
		return doc.GetElement(v)
	# if value is a integer
	elif isinstance(v, (int, Int16, Int32, Int64)):
		return doc.GetElement(ElementId(v))
	# if value is a String 'integer'
	elif isinstance(v, (str, String)) and str(v).isdigit():
		return doc.GetElement(ElementId(int(v)))
	# if value is a String Unique Id
	elif isinstance(v, (str, String)) and '-' in str(v):
		return doc.GetElement(v)

ids = IN[0]
out = []

for id in ids:
	out.append(getElementByValue(id))

OUT = out
6 Likes

The Designscript equivalent of that Should look something like Element.SelectorByUniqueId (UID, true)

2 Likes