Retrieving element ID from a list with null values

Hi all, trying out Dynamo to solve some issues again.

As the title states, I’m having difficulty extracting only the element ID from a list with null values and element IDs.
I’ve tried the element ID code block but it doesn’t produce the results I want because of null values.

In the list, I want to retain the position of the null value in the list but still extract the element IDs from the list. Is there a way? I’ve been googling but I can’t seem to find a way. Does anyone have a link or guide where i can refer to? It’ll really help me to understand what codes i should use.

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
Import RevitAPI
clr.AddReference(‘RevitAPI’)
import Autodesk
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

elements = []
for i in IN[0]:
elements.append(UnwrapElement(i))

elementIds, idString, guid = [], [], []
for i in elements:
elementIds.append(i.Id)
idString.append(i.Id.ToString())
guid.append(i.UniqueId)

#Assign your output to the OUT variable
OUT = elementIds, idString, guid

Thanks alot!

Can you post the whole graph? :slight_smile:

Hi @inferno9177,

Do you mean somethig like this:

import clr

#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

elements = UnwrapElement(IN[0])
output = []

for i in elements:
	if i != None:
		output.append(i.Id)
		
	else:
		output.append('nullWasHere.')
	
OUT = output

When posting code, use the little </> icon to get it formatted properly:
image

2 Likes

Hi, CVestesen!

Thanks but Martin has solved my issue for me!

Hi Martin,

You have what I really need!

Thank you!

Yeah, I’m sure he have ;-). Remember to set his post as the solution.

1 Like

No probs :slight_smile: