Python error with Assembly names

Hi,

I’ve trying to get a list of Assembly names from the active document by using this code:

#Get all Assembly types within the document
allassem = FilteredElementCollector(doc).OfClass(AssemblyType)

#Convert list to elements
allassemt = allassem.ToElements()

nameslist = []

#Extract the list of names
for f in allassemt:
	nameslist.append(f.Name)

OUT = [nameslist]

I get the error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. _
Traceback (most recent call last):
_ File “”, line 48, in

AttributeError: Name

Looking at the API documents, the AssemblyType class has a property called ‘Name’ and when I use DIR() it lists the Name property.

Am I missing something?

Thanks.

If you look at the attribute Name in the Revit API, you’ll see that you can only ‘set’ it and not ‘get’ it. Which is a bit odd, usually you can do both.
image

mmm, that’s very strange… I wonder how I can get a list of Assembly names - I was hoping to get then names and then rename elements to match…

Thanks for your response.

It’s still possible to get the names, but you’ll have to do it through the parameters, like this:

#Get all Assembly types within the document
allassem = FilteredElementCollector(doc).OfClass(AssemblyType)

#Convert list to elements
allassemt = allassem.ToElements()

nameslist = []

#Extract the list of names
for f in allassemt:
	param = f.GetParameters("Type Name")
	nameslist.append(param[0].AsString())

OUT = nameslist

Or just use a GetParameter node :slight_smile:

2 Likes

Ah yes, that’s a good idea - thanks.