First time here? Check out the Help page!
1 | initial version |
I've figured out the question. Let me ask and answer myself. I am using OpenStudio Python API.
import csv
import openstudio
def create_meter_customs_from_csv(csv_file_path, model):
meter_dict = {}
output_meter_dict = {}
with open(csv_file_path, 'r') as csvfile:
csvreader = csv.reader(csvfile)
next(csvreader) # Skip the header
for row in csvreader:
meter_name, fuel_type, key_name, output_variable_or_meter_name = row
if meter_name not in meter_dict:
meter = openstudio.model.MeterCustom(model)
meter.setName(meter_name)
meter.setFuelType(fuel_type)
meter_dict[meter_name] = meter
# Create and configure OutputMeter for the same MeterCustom
output_meter = openstudio.model.OutputMeter(model)
output_meter.setName(meter_name)
output_meter.setReportingFrequency('timestep') # Options: 'detailed','timestep','hourly','daily', 'monthly'
output_meter_dict[meter_name] = output_meter
meter = meter_dict[meter_name]
meter.addKeyVarGroup(key_name, output_variable_or_meter_name)
print(f"Meter:Custom objects created: {list(meter_dict.keys())}")
print(f"Output:Meter objects added: {list(output_meter_dict.keys())}")
# Usage
model = m # Replace this with your OpenStudio model
create_meter_customs_from_csv('csv_file_path', model)