Doc-changed.py hook GetAddedElementId, capturing floor

Hello, I am playing around on getting the events of changed elements. I successfully captured the Ids, Category, Families of wall, doors and windows, but on floor, instead of getting the floor itself as one entitiy, i am getting the individual line on sketch mode. Does anyone have a solid advise on how to do this? Here’s the output in question:


Here’s my code:

def add_element_log(custom_path):
    """ added element log """
    if doc.IsFamilyDocument:
        sys.exit()

    else:
        # ✅ main code
        add_filepath = custom_path
        username = os.environ['USERNAME']
        computer_name = os.environ['COMPUTERNAME']
        cur_time = datetime.now()
        date = str(cur_time.strftime("%d-%m-%y"))
        time = str(cur_time.strftime("%H:%M:%S"))
        model = EXEC_PARAMS.event_args.GetDocument().Title
        added_element_ids = EXEC_PARAMS.event_args.GetAddedElementIds()  # ICollection of element ids
        coll_elements = [doc.GetElement(el) for el in added_element_ids]
        trans_name = list(EXEC_PARAMS.event_args.GetTransactionNames())

        with open(add_filepath, 'a') as f:
            writer = csv.writer(f)
            if not os.path.isfile(add_filepath) or os.stat(add_filepath).st_size == 0:
                headings = [
                    'Model',
                    'Element',
                    'Element Type',
                    'Family',
                    'Category',
                    'Element Id',
                    'Added by',
                    'Computer Number',
                    'Date',
                    'Time',
                    'Transaction Name'
                ]
                writer.writerow(headings)

            try:
                for el in coll_elements:
                    if el:
                        el_id = el.GetTypeId()
                        el_type = doc.GetElement(el_id)
                        el_type = el_type.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME)
                        el_cat = el.get_Parameter(BuiltInParameter.ELEM_CATEGORY_PARAM)
                        el_fam = el.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM)

                        for trans in trans_name:
                            row_data = [
                                model,
                                el.Name,
                                el_type.AsValueString() if el_type else '',
                                el_fam.AsValueString() if el_fam else '',
                                el_cat.AsValueString() if el_cat else '',
                                el.Id,
                                username,
                                computer_name,
                                date,
                                time,
                                trans
                            ]
                            writer.writerow(row_data)
            except:
                pass

thanks in advance!

Hi,
I am guessing you are using the doc-changed hook
I woudl either use a different event or just exclude the capture of the sketch line with something like:

el_cat != "Dimensions: Automatic Sketch Dimensions" or with the transaction type.

Yes I’m using the the doc-changed.py, alright will try that and see if it’ll capture the floor creation, thanks!

for trans in trans_name:
    if trans == 'Finish sketch':
        continue

did it like this, it didn’t log the floor creation, i’ll probably try a different hook

you could also inspect events using the revit lookup events inspector to figure out what is happening in Revit when creating a floor

1 Like

ah thanks, didn’t know this is the use of this, apparently floor creation wont be included in GetAddedElementIds, it’ll be on GetModifiedElementIds

1 Like