Weird Issue with element attribute

Don’t know if this is a runtime issue, but all of a sudden one of my scripts is broken.
the cultprit seems to be this method.

    floortypes = DB.FilteredElementCollector(active_doc).OfClass(DB.FloorType.ToElements()
    for ft in floortypes: # type: DB.FloorType
        print(ft.Name) # <-- this is line 81

Gives me this traceback

IronPython Traceback:
Traceback (most recent call last):
 File "...\create_wideslab_script.py", line 422, in <module>
 File "...\create_wideslab_script.py", line 251, in pick_refs_main
 File "...\Create WideSlab.pushbutton\create_wideslab_script.py", line 81, in get_document_wideslab_type
AttributeError: Name

Script Executor Traceback:
System.MissingMemberException: Name
 at CallSite.Target(Closure , CallSite , Object , CodeContext )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

And the weird thing, this runs perfectly fine in the revit python shell. Has been working for me forever.
What’s even weirder. If I print(dir(ft)) I can see the name attr in the list of attriburtes. It’s maddening.
So it has the property… but I can’t read it?

Currently running pyrevit with 279 engine, tried reloading, rebooting, changing engine

floortypes = DB.FilteredElementCollector(active_doc).OfClass(DB.FloorType.ToElements()
                                                                         ^ missing bracket
1 Like

Hold up. Not the solution.
That was just a typo in my example

Is it because you’re using ElementType.Name which allows you to Set the name but not Get it?

Hmm no I don’t think so.
It works in revit python shell though. :thinking:

Try:


print(DB.Element.Name.GetValue(ft))

Odd, an ‘unreadable’ property.
But how come this works in a revit python shell no problem? Actually I do this kind of thing in most of my code.

This seems to happen in Revit 2024 and Revit 2023

IronPython Traceback:
Traceback (most recent call last):
 File "Create WideSlab.pushbutton\create_wideslab_script.py", line 422, in <module>
 File "Create WideSlab.pushbutton\create_wideslab_script.py", line 251, in pick_refs_main
 File "Create WideSlab.pushbutton\create_wideslab_script.py", line 80, in get_document_wideslab_type
AttributeError: unreadable property

Script Executor Traceback:
System.MissingMemberException: unreadable property
 at IronPython.Runtime.Types.ReflectedProperty.CallGetter(CodeContext context, PythonType owner, SiteLocalStorage`1 storage, Object instance)
 at IronPython.Runtime.Types.ReflectedProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.ReflectedProperty.GetValue(CodeContext context, Object instance)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Show a bit more of the code and some sample file for me to try. In PM if you like.
Maybe the specific object you are querying is different from what you expect.
As an example, when you query Views, it returns the project browser and the system browser as well and these two do not have the same parameters as a regular view.

I condensed the script to

from Autodesk.Revit import DB, UI
from Autodesk.Revit.ApplicationServices import Application

uiapp = __revit__ # type: UI.UIApplication
app = uiapp.Application # type: Application

uidoc = uiapp.ActiveUIDocument
doc = uidoc.Document

print("Getting elements")
floortypes = DB.FilteredElementCollector(doc).OfClass(DB.FloorType).ToElements()

print("looping over floortypes")
for ft in floortypes:  # type: DB.FloorType
    print(ft)
    print(DB.ElementType.Name.GetValue(ft))
    print(ft.Name)

Getting this:

Getting elements
looping over floortypes
<Autodesk.Revit.DB.FloorType object at 0x0000000000000A42 [Autodesk.Revit.DB.FloorType]>
IronPython Traceback:
Traceback (most recent call last):
 File "Create WideSlab.pushbutton\script.py", line 18, in <module>
AttributeError: unreadable property

Script Executor Traceback:
System.MissingMemberException: unreadable property
 at IronPython.Runtime.Types.ReflectedProperty.CallGetter(CodeContext context, PythonType owner, SiteLocalStorage`1 storage, Object instance)
 at IronPython.Runtime.Types.ReflectedProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.ReflectedProperty.GetValue(CodeContext context, Object instance)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Tried it in an empty metric R2024 structural file. And again, it works perfectly fine in Revit Python shell (python 3.4.1) apparently. I’m going to see what happens if I downgrade RPS. Will keep you posted

I have found the same problem as you and got round it with

ele.get_Parameter(DB.BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
1 Like

HEY that works! Wow

So weird though. Not sure if I want to call it solved just yet, because as I said, normally the original way of getting things workd.
Can we keep looking at it?

I’m a bit suspicious about the following line in the traceback

at IronPython.Runtime.Types.ReflectedProperty.CallGetter(CodeContext context, PythonType owner, SiteLocalStorage`1 storage, Object instance)

I’m curious if this line is causing the issue.

We’re doing some IT migrations, and the device i’m testing on has no local-admin rights. So… could it be that python is using a temporary folder somewhere that my user account is not allowed to use?

1 Like

not DB.ElementType, you already have it. DB.Element

print(DB.Element.Name.GetValue(ft))

My apologies,
That one works too… I’m confused…

1 Like

Can someone explain to me why:

  1. Those 2 options work (from Jean-Marc and Kevin)
  2. My inittial code works in RPS w/ python 3.4
  3. My initial code doens’t work using pyrevit? And also doesn’t work in RPS w/ python 2.7.7

That last one I just tested.

I am not extremely literate in these matters. I’m not the best person to explain this precisely but I know where to look:

  1. my option is just another way to get the value of an element attribute
    Kevin’s is calling another parameter and not the direct implementation of the Name property for the element type
  2. I happen to know it but never got to dig in. So I will refer to someone more in the know than I am: IronPython to CPython - #7 by c.poupin - Developers - Dynamo
    It is related to a bug in the implementation of .NET properties in Iron python <3.0
  3. 2.77 vs 3.4, like stated in Cyril’s post :point_up:
1 Like

Interesting. Thanks JMC…
Although ApiDocs does say that Name property is only for setting

public override string Name { set; }

I wouldn’t expect it to though, since all I did was try and get the value, never set it.

Regardless I’m going to read up on the link from Jean-Marc and consider this issue solved.
Point goes to Jean-Marc as his answer technically was the first one to work.
Sorry Kevin :frowning:

Weird that I never ran into this issue before, I’ve been working with pyrevit in the last year without this every happening.

Oh, I don’t mind giving it to Kevin. Every effort made to answer thoroughfully is definitely worth a win. :slight_smile:


You are right @KSalmon, but if you look at the hierarchy in the API for the name property:

  • FloorType: set only
  • HostObjAttributes: set only
  • ElementType: set only
  • Element: get AND set

you find that what mostly cause the issue is the inheritance of methods between the Element and ElementType. And I really don’t know what it is done like this by design. Why we cannot directly set the name of an ElementType when you can for the Element through its property. Why the extra step through getValue or through the BuiltInParameter?

2 Likes