1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import pandas as pd import subprocess
def run_midas_script(script_path): subprocess.run(['midas_civil_path', '-run', script_path], check=True)
def generate_midas_script(df, output_script_path): with open(output_script_path, 'w') as f: for index, row in df.iterrows(): node_id = row['NodeID'] stiffness_x = row['SpringStiffnessX'] stiffness_y = row['SpringStiffnessY'] stiffness_z = row['SpringStiffnessZ'] command = f""" *SPRING {node_id}, LINEAR,NO, NO, NO, NO, NO, NO, {stiffness_x}, {stiffness_y}, {stiffness_z}, 0, 0, 0, NO, 0, 0, 0, 0, 0, 0, 边界组, 0, 0, 0, 0, 0 """ f.write(command)
def main(): excel_file = 'soil_spring_data.xlsx' output_script_path = 'add_soil_springs.mct' df = pd.read_excel(excel_file) generate_midas_script(df, output_script_path) run_midas_script(output_script_path)
if __name__ == "__main__": main()
|