How to extract Revit ID from schedule xls?

@Jean-Marc

when i commit with else i get this

@jpitts @Jean-Marc

i used a bit chatGPT and it implement some test units like try and conditions… at least i got error

# 🎯 set Parameter based excel
def set_parameters(elements, parameters=PARAMETERS, data_dict = DATA_DICT):
    not_found = {}
    for element in elements:
        element_id = str(element.Id)
        if element and element_id in data_dict.keys():
            not_found[element_id] = []
            element_entry = data_dict[element_id]
            for i, parameter in enumerate(parameters[1:]):
                param = element.LookupParameter(parameter)
                try:
                    if param:
                        param.Set(str(element_entry[i]))
                except Exception as e:
                    not_found[element.Id].append(parameter)
    return not_found


all_elements = DB.FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType().ToElements()

# 🔓 🔒 🔑 Set Parameter
with revit.Transaction("set Parameter based on excel"):
    try:
        not_found = set_parameters(all_elements)
        print("Parameters not found for elements: {}".format(not_found))
    except Exception as e:
        print("Transaction failed: {}".format(e))

bear with me, I know pretty much how to fix this, but I think you are getting there wrong.

  • try not to use chatgpt too much

  • try not to use dynamo in parallel too much.

  • what is the precise end goal of the script (finding parameter that are not found, or parameter values for specfic parameters of specific elements?)

  • ask yourself in plain english (or german :slight_smile: ) what you are trying to achieve and write it in pseudo code - including the try catch of errors you are trying to achieve

  • Look through a dictionary made of element ids as keys

  • from these keys get the corresponding elements in the revit model

  • return the ones that are not found

  • process the one you found and assign parameter values accordingly

1 Like

My goal, answering, is to get you there, by giving you hints, not give you necessarily the answer as I think you need to walk there yourself to progress.

@Jean-Marc

i got it actually it is also a acceleration of transaction time


# 🎯 set Parameter based excel
def set_parameters(elements, parameters=PARAMETERS, data_dict = DATA_DICT):
    not_found = {}
    for element in elements:
        element_id = int(element.Id.IntegerValue)
        if element_id in data_dict:
            element_entry = data_dict.get(element_id)
            for i, parameter in enumerate(parameters[1:]):
                try:
                    element.LookupParameter(parameter).Set(element_entry[i])
                except Exception:
                    not_found.setdefault(element_id, []).append(parameter)
    return not_found

i modified the transaction it got a list of Ids which are not filled!

it think next step will be getting what did not work, and why… it is actually a big step.

Thanks for the hints.

KR

Andreas