Python Help - Untagged rebar

I have been using a script since 2018 that notifies me of any untagged rebars but when I have gone to use it in Revit 2022 I get an error message:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.

Traceback (most recent call last):

File “”, line 26, in

TypeError: expected object, got NoneType

This is the code:

import clr

clr.AddReference('RevitAPI')

from Autodesk.Revit.DB import *

from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitNodes')

import Revit

clr.ImportExtensions(Revit.GeometryConversion)

clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')

import RevitServices

from RevitServices.Persistence import DocumentManager

from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit

tag = UnwrapElement(IN[0])

OUT = []

for t in tag:
    id = t.TaggedLocalElementId
    element = doc.GetElement(id)
    if element.GetType().ToString() == "Autodesk.Revit.DB.Dimension":
        uId = set([r.ElementId for r in element.References])
        for ui in uId:
            OUT.append(doc.GetElement(ui).ToDSType(True))
    else:
        OUT.append(element.ToDSType(True))

Is the reporting error to do with “Autodesk.Revit.DB.Dimension” since this script was created in 2018.

I have no knowledge of Python and any help would be much appreciated.

1 Like

@kieran.atherton ,

i did test your code just cleaned up and set the right template…

import clr
import sys
import System

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

tag = UnwrapElement(IN[0])

output = []

for t in tag:
	id = t.TaggedLocalElementId
	element = doc.GetElement(id)
	if element.GetType().ToString() == "Autodesk.Revit.DB.Dimension":
		uId = set([r.ElementId for r in element.References])

	for ui in uId:
		output.append(doc.GetElement(ui).ToDSType(True))

	else:
		output.append(element.ToDSType(True))
		
OUT = output

Thanks for your help Draxl, however, it still doesn’t seem to be reporting the missing rebar tags, this is the error:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 38, in
NameError: name ‘uId’ is not defined

this is line 38: for ui in uId:

@kieran.atherton ,

i think there are still some syntext errors

check out this topic

the inputs are elements I think. This is the script I am using
RebarCheckUntaggedBars-MultiplePartition.dyn.dyn (23.5 KB)

Ive no experience with python so Im not sure what the correct inputs should be

The error in this script is occurring at line 34, and is stating that a NoneType object was encountered where an object was expected.

Without additional context, it is difficult to pinpoint the exact cause of the error. However, one possibility is that the UnwrapElement function used to retrieve the tag parameter may be returning a NoneType object, which is causing an error when attempting to access the TaggedLocalElementId property on the next line.

To troubleshoot this issue, you may want to try printing out the tag object before the loop to ensure that it is a valid object, and checking to make sure that the UnwrapElement function is returning the expected type of object. You may also want to double-check that the input passed into the script is of the correct type and format.

Additionally, it may be helpful to check if any other variables or functions used within the loop are returning NoneType objects, which could be causing the error on line 34.

This is what Chat gpt gives me, Do I have to edit 1 of the lines so that it only reads none object?

Very quick glance I’d suggest this bit needs an extra indent

1 Like

I think ive got it to work:

RebarCheckUntaggedBars-MultiplePartition2022.dyn (23.6 KB)