How to modify number of steps and step end time by reading an Excel file?
Adapt the following code:
import os import csv # User inputs times_file_path = r'link_to_csv' analysis_time_column = "A" analysis = Model.Analyses[1] # Read .csv file for time steps definition def column_letter_to_index(letter): return ord(letter.upper()) - ord('A') analysis_time_idx = column_letter_to_index(analysis_time_column) analysis_time = [] if os.path.exists(times_file_path): # Open and read the CSV file with open(times_file_path, 'r') as file: csv_reader = csv.reader(file) # Read each row and extract the specified columns for row in csv_reader: try: # Column A -> analysis_time if len(row) > analysis_time_idx: analysis_time.append(row[analysis_time_idx]) except IndexError: # Skip rows that don't have enough columns continue print("CSV file read successfully!") print("Number of rows processed: {0}".format(len(analysis_time))) else: print("CSV file not found: {0}".format(csv_file)) # Change analysis settings to match the number of columns analysis.AnalysisSettings.NumberOfSteps = len(analysis_time) with Transaction(): # Define time stepping, per step for index, value in enumerate(analysis_time): analysis.AnalysisSettings.CurrentStepNumber = index+1 step_end_time = Quantity(str(value) + ' [s]') analysis.AnalysisSettings.StepEndTime = step_end_time Tree.Refresh()