As per the code below, i call in the transaction to write shared parameter values thrice for around 1000 rooms. Each transaction takes about 30 seconds, hence total time- 90 seconds.
# _Function to write Shared Parameter values_
def set_parameter_by_name(element, parameterName, value):
element.LookupParameter(parameterName).Set(value)
# _Function to perform Set Parameter By Name as a Transaction_
def set_parameter_by_name_transaction(sample_elements, sample_param_name, sample_param_values):
t = Transaction(doc, 'script')
write_param_pass = []
write_param_fail = []
t.Start()
for e in sample_elements:
try:
write_param_pass = [set_parameter_by_name(e,sample_param_name,val) for e,val in zip(sample_elements, sample_param_values)]
except:
write_param_fail.append(val)
t.Commit()
# _Calling function, for clean set of parameter values_
reset_all_room_occupancies = set_parameter_by_name_transaction(rooms, 'Occupant', list_of_default_values)
# _Calling function, for writing available values_
write_occupant_count_to_rooms = set_parameter_by_name_transaction(rooms_with_valid_occupancy_values, 'Occupant', occupant_count_as_per_code_for_writing_to_param)
# _Calling function, for writing 'NA' for values not calculated_
write_occupant_count_NA_to_rooms_with_no_occupancy_type = set_parameter_by_name_transaction(rooms_with_NA_occupancy_values, 'Occupant', room_NA_occupancy_values)
Try running every thing you want to do to all the elements, all in one single transaction
t = Transaction(doc, 'script')
t.Start()
# none of these functions should have a transaction nested inside them
reset_all_room_occupancies()
write_occupant_count_to_rooms()
write_occupant_count_NA_to_rooms_with_no_occupancy_type()
t.Commit()
On your question about threading, Revit is single-threaded for API changes so only the main thread can make changes.
I tried running on a single transaction, but is taking the same amount of time. I think getting Room occupancy, as per selected code, for 1000 rooms in under 90 secs, is in itself an achievement. Thank you.
Ya not too bad. Generally the Revit API is the bottleneck. Also try using the .get_Parameter() method instead of .LookupParameter. You might see some performance improvements
Will definitely try this out