Selection Element Python

I want to enter the name of the Element along with the element ID, but why does it Appear Error as shown in the picture, while if only entering the Id element it works, using the code block to take the familyname also works


    def selectElement(self, sender, event):
        # Ensure correct import and usage of ObjectType
        from Autodesk.Revit.UI.Selection import ObjectType
        selected_id = uidoc.Selection.PickObject(ObjectType.Element, "Select an element")
        selected_element = doc.GetElement(selected_id)
    def run(self, sender, event):
        global OUT
        OUT = [elem for elem in self.listbox.Items]

Is your code part of a larger script? It looks like you are showing two methods that are part of a class but there is no context of how the class is used or initialised

Unhandled exceptions usually occur when trying to modify the model outside of a transaction

Also OUT is already a global variable which is special in the Dynamo Python interpreter - it is possible that this is causing the error by redefining the variable in the run method

1 Like

self.listbox.Items.Add(str(selected_element.Name)) i try code, revitloockup parameter Name ,success