-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
249 lines (209 loc) · 5.97 KB
/
file.py
File metadata and controls
249 lines (209 loc) · 5.97 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# -*- coding: utf-8 -*-
"""
file.py - File helpers.
Thin wrappers around the SAP2000 File API.
SAP2000 API:
- File.New2DFrame - New 2D frame template
- File.New3DFrame - New 3D frame template
- File.NewBeam - New beam template
- File.NewBlank - New blank model
- File.NewSolidBlock - New solid block template
- File.NewWall - New wall template
- File.OpenFile - Open file
- File.Save - Save file
"""
from PySap2000.global_parameters.units import UnitSystem as Units
# =============================================================================
# Model creation
# =============================================================================
def new_blank(model, units: Units = Units.KN_M_C) -> int:
"""
Create a blank model.
Args:
model: SapModel object
units: Unit system
Returns:
`0` on success
Example:
new_blank(model, Units.KN_M_C)
"""
return model.File.NewBlank(int(units))
def new_2d_frame(
model,
template_type: int,
num_stories: int,
story_height: float,
num_bays: int,
bay_width: float,
restraint: bool = True,
beam_section: str = "",
column_section: str = "",
brace_section: str = "",
units: Units = Units.KN_M_C
) -> int:
"""
Create a new 2D frame template model.
Args:
model: SapModel object
template_type: Template type
0 = portal frame
1 = continuous beam
2 = simply supported beam
3 = cantilever beam
4 = truss
num_stories: Number of stories
story_height: Story height
num_bays: Number of bays
bay_width: Bay width
restraint: Whether to add supports
beam_section: Beam section name
column_section: Column section name
brace_section: Brace section name
units: Unit system
Returns:
`0` on success
"""
return model.File.New2DFrame(
template_type, num_stories, story_height, num_bays, bay_width,
restraint, beam_section, column_section, brace_section, int(units)
)
def new_3d_frame(
model,
template_type: int,
num_stories: int,
story_height: float,
num_bays_x: int,
bay_width_x: float,
num_bays_y: int,
bay_width_y: float,
restraint: bool = True,
beam_section: str = "",
column_section: str = "",
brace_section: str = "",
units: Units = Units.KN_M_C
) -> int:
"""
Create a new 3D frame template model.
Args:
model: SapModel object
template_type: Template type
0 = open frame
1 = perimeter frame
2 = braced frame
num_stories: Number of stories
story_height: Story height
num_bays_x: Number of bays along X
bay_width_x: Bay width along X
num_bays_y: Number of bays along Y
bay_width_y: Bay width along Y
restraint: Whether to add supports
beam_section: Beam section name
column_section: Column section name
brace_section: Brace section name
units: Unit system
Returns:
`0` on success
"""
return model.File.New3DFrame(
template_type, num_stories, story_height,
num_bays_x, bay_width_x, num_bays_y, bay_width_y,
restraint, beam_section, column_section, brace_section, int(units)
)
def new_beam(
model,
num_spans: int,
span_length: float,
restraint: bool = True,
section: str = "",
units: Units = Units.KN_M_C
) -> int:
"""
Create a new beam template model.
Args:
model: SapModel object
num_spans: Number of spans
span_length: Span length
restraint: Whether to add supports
section: Section name
units: Unit system
Returns:
`0` on success
"""
return model.File.NewBeam(num_spans, span_length, restraint, section, int(units))
def new_solid_block(
model,
width_x: float,
width_y: float,
height: float,
restraint: bool = True,
units: Units = Units.KN_M_C
) -> int:
"""
Create a new solid block template model.
Args:
model: SapModel object
width_x: Width along X
width_y: Width along Y
height: Height
restraint: Whether to add supports
units: Unit system
Returns:
`0` on success
"""
return model.File.NewSolidBlock(width_x, width_y, height, restraint, int(units))
def new_wall(
model,
num_x: int,
num_z: int,
width: float,
height: float,
restraint: bool = True,
section: str = "",
units: Units = Units.KN_M_C
) -> int:
"""
Create a new wall template model.
Args:
model: SapModel object
num_x: Number of divisions along X
num_z: Number of divisions along Z
width: Width
height: Height
restraint: Whether to add supports
section: Section name
units: Unit system
Returns:
`0` on success
"""
return model.File.NewWall(num_x, num_z, width, height, restraint, section, int(units))
# =============================================================================
# File operations
# =============================================================================
def open_file(model, file_path: str) -> int:
"""
Open a model file.
Args:
model: SapModel object
file_path: File path
Returns:
`0` on success
Example:
open_file(model, r"C:\\Models\\example.sdb")
"""
return model.File.OpenFile(file_path)
def save(model, file_path: str = "") -> int:
"""
Save the current model.
Args:
model: SapModel object
file_path: Target file path. Empty string saves to the current path.
Returns:
`0` on success
Example:
save(model) # Save to the current path
save(model, r"C:\\Models\\example.sdb") # Save as
"""
if file_path:
return model.File.Save(file_path)
else:
return model.File.Save()