Dynamo Python - List or single element?

Hi guys,

I’m learning Python in Dynamo and my first task is to get the UniqueId from selected elements in Revit. Quiet easy task, but I’ve found some inconvenience, see the attached images. If I want to have one input, which can select one or more elements, I have to prepare a condition, which will iterate over a list or just, return the UniqueId from one element. That is my goal but I’ve made somewhere a mistake probably, if the algorithm want to iterate over a list of elements and get the UniqueId from them it returns me a warning that list[object] has no attribute UniqueId. I think this is very common task when using Python and somebody will immediately see this mistake. Can you please help me? I’ll appreciate any small advice.


When you unwrap element you have a net collection (List) not a Python list
check before if input are a list and after unwrap it.
Or check if input have __iter__ attribute

1 Like
  if isinstance(IN[0],list):
    	elements = UnwrapElement(IN[0])
  else:
    	elements = [UnwrapElement(IN[0])]
1 Like

Many thanks c.popin and especially myrwen you save my day. Now it is clearer to me.
Finale algorithm:
image