NoneType object has no attribute AsString

Hi everyone, I am trying to get element from Item number of that equipment. In my case, “Item Number” is a shared parameter of instance type. I am facing the below shown error while executing the code.

The parameter value can be seen in Element.Parameter which is of storage type “string” but still it is unable to fetch the element and rather getting some NoneType object.

Interestingly, the same code is working perfectly in Revit sample project with the same parameters. I could not figure out the reason of it failing in my live project.

This is not a data storage error, the error means that for one or more elements has no “Item Number” parameter

1 Like

I made schedule of specialty equipment in Revit, deleted the items having no values and some whose Item Number was greyed out and run the script. Still the error persists.

Can we somehow bypass those items by making changes in below code ?

import sys

import clr

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

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

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

elements = IN[0]
Item_Number = IN[1]
#parameter = IN[1]

outList = []


for i in UnwrapElement(elements):
	if i.LookupParameter("Item Number").AsString() == IN[1]:
		outList.append(i)


OUT = outList

@shujath36 append the LookupParameter("Item Number") to the output list, check what is the value of the greyed out ones, filter them out according to the value you got, basically, you should end up with clean elements ready to be filtered out according to the “IN[1]” value:

3 Likes

Thanks for that valuable input. Now I don’t have to bother about those equipment which does not have parameter added in it or having null values.

1 Like

Another method you can put in there is a try/except clause
image

This makes it so it tries to do it, then if it doesn’t exist skips to the next element.

1 Like