# Step-by-step guide to using the OpenSTAAD API from Python

### 1. Install prerequisites

```bash
pip install comtypes pywin32 openstaad
```

<div data-v-e8248998="" id="bkmrk-"></div>### 2. Launch STAAD.Pro and connect

```python
import subprocess, time, comtypes.client
from pythoncom import CoInitialize, CoUninitialize

CoInitialize()                       # Initialise COM
staad_path = r"C:\Program Files\Bentley\Engineering\STAAD.Pro 2024\STAAD\Bentley.Staad.exe"
subprocess.Popen([staad_path])
time.sleep(8)                        # Wait for STAAD to open

openstaad = comtypes.client.GetActiveObject("StaadPro.OpenSTAAD")
```

<div data-v-e8248998="" id="bkmrk--1"></div>### 3. Create or open a model

```python
from pathlib import Path
std_file_path = Path.cwd() / "my_model.std"
length_unit = 4   # 4 = metres
force_unit   = 5  # 5 = kN
openstaad.NewSTAADFile(str(std_file_path), length_unit, force_unit)
time.sleep(3)
```

<div data-v-e8248998="" id="bkmrk--2"></div>### 4. Define material and section

```python
prop = openstaad.Property
prop.SetMaterialName("STEEL")

# European IPE200 section
prop_no = prop.CreateBeamPropertyFromTable(
    country_code=7,        # 7 = European database
    section_name="IPE200",
    type_spec=0,           # single section from table
    add_spec_1=0.0,
    add_spec_2=0.0
)
```

<div data-v-e8248998="" id="bkmrk--3"></div>### 5. Add nodes and beams

```python
geom = openstaad.Geometry
geom.CreateNode(1, 0, 0, 0)
geom.CreateNode(2, 5, 0, 0)
geom.CreateBeam(1, 1, 2)          # Beam 1: node 1 → node 2
prop.AssignBeamProperty(1, prop_no)
```

<div data-v-e8248998="" id="bkmrk--4"></div>### 6. Supports and loads

```python
sup = openstaad.Support
sup_no = sup.CreateSupportFixed()
sup.AssignSupportToNode(1, sup_no)
sup.AssignSupportToNode(2, sup_no)

ld = openstaad.Load
case = ld.CreateNewPrimaryLoad("Self-Weight")
ld.SetLoadActive(case)
ld.AddSelfWeightInXYZ(case, -1.0)   # factor −1 in global Y
```

<div data-v-e8248998="" id="bkmrk--5"></div>### 7. Run the analysis (silent mode)

```python
cmd = openstaad.Command
cmd.PerformAnalysis(6)      # 6 = static analysis
openstaad.SetSilentMode(1)
openstaad.Analyze()
while openstaad.isAnalyzing():
    time.sleep(2)
```

<div data-v-e8248998="" id="bkmrk--6"></div>### 8. Retrieve results

```python
from openstaad import Output
out = Output()
fx, fy, fz, mx, my, mz = out.GetMemberEndForces(beam=1, start=True, lc=1)
print("Start-end forces:", fx, fy, fz, mx, my, mz)
```

<div data-v-e8248998="" id="bkmrk--7"></div>### 9. Clean up

```python
openstaad.SaveModel(1)
CoUninitialize()
```

<div data-v-e8248998="" id="bkmrk--8"></div>### 10. Helper wrappers

<div class="paragraph" id="bkmrk-if-you-prefer-a-high">If you prefer a higher-level interface, install **OpenStaadPython**:</div>```bash
pip install openstaad
```

<div class="paragraph" id="bkmrk-then-use-convenience">Then use convenience classes:</div>```python
from openstaad import Geometry, Root
print(Geometry().GetBeamList())
print(Root().GetSTAADFile())
```

<div class="paragraph" id="bkmrk-%28note%3A%C2%A0openstaad-cur">(Note: `openstaad` currently focuses on **querying** an **already-open** model.)</div>### Documentation &amp; Community

- <div class="paragraph">**Official docs**:  
    `C:\Program Files\Bentley\Engineering\STAAD.Pro 2024\OSAPP_Help`  
    (Examples are mainly VB/C++; Python help lives in the Bentley forums.)</div>
- <div class="paragraph">**GitHub samples**:  
    [viktor-platform/sample-staad-integration](https://github.com/viktor-platform/sample-staad-integration)</div>

<div class="paragraph" id="bkmrk-you-can-now-create%2C-">You can now create, modify, analyse and extract results from STAAD.Pro entirely from Python scripts.</div>