-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_staad_model.py
More file actions
125 lines (86 loc) · 4.02 KB
/
Copy pathrun_staad_model.py
File metadata and controls
125 lines (86 loc) · 4.02 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
import subprocess
import time
from datetime import datetime
from pathlib import Path
from openstaadpy import os_analytical
def run_staad() -> None:
length_unit_meter = 4
force_unit_kilonewton = 5
section_table_european = 7
self_weight_direction_global_y = 2
results_local = 0
start_end = 0
final_end = 1
staad_path = Path(r"C:\Program Files\Bentley\Engineering\STAAD.Pro 2025\STAAD\Bentley.Staad.exe")
if not staad_path.is_file():
raise FileNotFoundError(f"STAAD.Pro executable was not found at: {staad_path}")
input_path = Path.cwd() / "inputs.json"
with input_path.open(encoding="utf-8") as json_file:
nodes, lines, section_name = json.load(json_file)
nodes = {int(node_id): values for node_id, values in nodes.items()}
lines = {int(line_id): values for line_id, values in lines.items()}
staad_process = subprocess.Popen([str(staad_path)])
print(f"Launching STAAD.Pro from: {staad_path}")
# Wait for STAAD.Pro to fully start before connecting. Increase this value if STAAD.Pro takes longer on the worker machine.
time.sleep(30)
staad = os_analytical.connect()
staad.SetSilentMode(True)
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
std_file_path = Path.cwd() / f"Structure_{timestamp}.std"
staad.NewSTAADFile(str(std_file_path), length_unit_meter, force_unit_kilonewton)
time.sleep(8)
geometry = staad.Geometry
prop = staad.Property
support = staad.Support
load = staad.Load
for node_id, coordinates in nodes.items():
geometry.CreateNode(int(node_id), float(coordinates["x"]), float(coordinates["y"]), float(coordinates["z"]))
for line_id, line_data in lines.items():
geometry.CreateBeam(int(line_id), int(line_data["node_i"]), int(line_data["node_j"]))
property_id = prop.CreateBeamPropertyFromTable(section_table_european, section_name, 0, 0.0, 0.0)
member_ids = list(lines.keys())
raw_property = prop._property
raw_property.SetMaterialName("STEEL")
for member_id in member_ids:
raw_property.AssignBeamProperty(int(member_id), property_id)
raw_property.AssignMaterialToMember("STEEL", int(member_id))
fixed_support_id = support.CreateSupportFixed()
for node_id in [1, 2, 5, 6]:
support._support.AssignSupportToNode(int(node_id), fixed_support_id)
load_case = load.CreateNewPrimaryLoad("Self Weight")
load.SetLoadActive(load_case)
load.AddSelfWeightInXYZ(self_weight_direction_global_y, -1.0)
staad.UpdateStructure()
time.sleep(2)
staad.Command.PerformAnalysis(6)
time.sleep(2)
staad.SaveModel(True)
time.sleep(2)
staad.Analyze()
analysis_deadline = time.time() + 300
while staad.IsAnalyzing():
if time.time() > analysis_deadline:
raise TimeoutError("STAAD.Pro analysis did not finish within the timeout.")
print("...Analyzing")
time.sleep(2)
time.sleep(3)
analysis_status = staad.GetAnalysisStatus()
print(f"Analysis status: {analysis_status}")
if analysis_status["ReturnValue"] not in [2, 3]:
raise RuntimeError(f"STAAD.Pro analysis did not complete successfully: {analysis_status}")
time.sleep(3)
output = staad.Output
end_forces = [output.GetMemberEndForces(int(line_id), final_end, int(load_case), results_local) for line_id in lines]
end_headers = [f"Beam:{lines[line_id]['line_id']}/Node:{lines[line_id]['node_j']}" for line_id in lines]
start_forces = [output.GetMemberEndForces(int(line_id), start_end, int(load_case), results_local) for line_id in lines]
start_headers = [f"Beam:{lines[line_id]['line_id']}/Node:{lines[line_id]['node_i']}" for line_id in lines]
forces = end_forces + start_forces
headers = end_headers + start_headers
output_path = Path.cwd() / "output.json"
with output_path.open("w", encoding="utf-8") as json_file:
json.dump({"forces": forces, "headers": headers}, json_file)
staad.Quit()
staad_process.terminate()
if __name__ == "__main__":
run_staad()