Skip to content

Commit ba58623

Browse files
authored
Build STAAD Addin post added
1 parent 0ca4d74 commit ba58623

1 file changed

Lines changed: 220 additions & 0 deletions

File tree

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
title: Build STAAD Addin using User Tools
3+
description: Use STAAD User Tools to extend STAAD functionality using Visual Basic script
4+
date: 27-11-2025
5+
categories: [VBA, VBA-STAAD]
6+
tag: [staad, vba, openstaad, how to]
7+
image: /assets/images/staad/build-staad-addin.webp
8+
---
9+
10+
## Overview
11+
- In this tutorial, I'll show you how to use Visual Basic script to create a STAAD addin
12+
- What is User Tools?
13+
- STAAD User Tools allows you to extend STAAD functionality using Visual Basic script
14+
- You can access it from Utilities > User Tools
15+
- Why use this method?
16+
- Doesn't require any setup or external tools; it's built into STAAD
17+
- Better workflow, since you can't directly run your script from STAAD
18+
- It's older technology with limited functionality, making it more LLM friendly
19+
- I am assuming that:
20+
- You have basic knowledge of Visual Basic script and know how to add modules and create new subs
21+
- Keep in mind that Visual Basic script is a bit different from Excel VBA; syntax is similar, but VBA has much more functionality
22+
23+
## Setup
24+
- Create a new text file with *.vbs extension
25+
- For this tutorial, I am creating `Test.vbs` file
26+
- Add the sample code below and save the file
27+
- Open any STAAD model, go to Utilities > User Tools > Configure
28+
- Add a new menu item, name it "Test VBS", and in the command input, select the `Test.vbs` file and click OK to save
29+
- Now you can run this code from Utilities > User Tools > User Tools > `Test VBS`
30+
31+
```vb
32+
Sub Main
33+
MsgBox "Test.vbs is running successfully!", vbInformation, "Test Script"
34+
End Sub
35+
```
36+
![1](../assets/images/staad/build-staad-addin-1.webp)
37+
38+
39+
## Get Inputs
40+
41+
### Input Box
42+
- You can use an input box to get single inputs from the user
43+
- By default, it will return a string, so you have to convert it to double or integer as per your requirements
44+
45+
```vb
46+
Sub Main()
47+
Dim inputValue As String
48+
inputValue = InputBox("Text", "Input Box")
49+
50+
MsgBox inputValue, vbInformation, "Input Received"
51+
End Sub
52+
```
53+
54+
### User Form
55+
- More suitable for multiple inputs
56+
- You can refer to this video for more complex code: [Modelling Intze Tank Geometry using User Tool in STAAD.Pro](https://www.youtube.com/watch?v=Az1E9Qaq4UY)
57+
58+
```vb
59+
Sub Main()
60+
61+
Begin Dialog ModelInputs 200,140,"Model Inputs" ' %GRID:10,7,1,1
62+
GroupBox 10,0,180,105,"Geometry Inputs",.GeometryInputsGroupBox
63+
Text 25,20,70,14,"Length"
64+
TextBox 100,20,70,14,.LengthTextBox
65+
Text 25,50,70,14,"Width"
66+
TextBox 100,50,70,14,.WidthTextBox
67+
Text 25,80,70,14,"Height"
68+
TextBox 100,80,70,14,.HeightTextBox
69+
OKButton 20,110,80,20,.OKButton
70+
CancelButton 110,110,80,20,.CancelButton
71+
End Dialog
72+
73+
'Create new dialog instance
74+
Dim dlg As ModelInputs
75+
dlg.LengthTextBox = "10"
76+
dlg.WidthTextBox = "5"
77+
dlg.HeightTextBox = "3"
78+
79+
Dim result As Integer
80+
result = Dialog (dlg)
81+
82+
Dim volume As Double
83+
If result = -1 Then
84+
volume = CDbl(dlg.LengthTextBox) * CDbl(dlg.WidthTextBox) * CDbl(dlg.HeightTextBox)
85+
MsgBox "Length: " & dlg.LengthTextBox & vbCrLf & _
86+
"Width: " & dlg.WidthTextBox & vbCrLf & _
87+
"Height: " & dlg.HeightTextBox & vbCrLf & _
88+
"Volume: " & volume
89+
End If
90+
91+
End Sub
92+
```
93+
94+
## Generate Model
95+
- You can use this post [Automate STAAD model from Excel using OpenSTAAD](/posts/openstaad-generate-model) for the full version
96+
97+
```vb
98+
Sub Main
99+
'Create OpenSTAAD Object
100+
Dim objOpenSTAAD As Object
101+
Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
102+
103+
'Add nodes with node IDs 1 and 2
104+
objOpenSTAAD.Geometry.CreateNode 1, 0, 0, 0
105+
objOpenSTAAD.Geometry.CreateNode 2, 3#, 0#, 0#
106+
107+
'Add beam with ID 1 connecting nodes 1 and 2
108+
objOpenSTAAD.Geometry.CreateBeam 1, 1, 2
109+
110+
'Create rectangular section
111+
Dim width As Double, depth As Double
112+
Dim beamNo As Long
113+
Dim sectionPropertyNo As Long
114+
width = 0.3
115+
depth = 0.3
116+
beamNo = 1
117+
sectionPropertyNo = objOpenSTAAD.Property.CreatePrismaticRectangleProperty(depth, width)
118+
objOpenSTAAD.Property.AssignBeamProperty beamNo, sectionPropertyNo
119+
120+
'Create fixed support
121+
Dim supportNo As Long
122+
supportNo = objOpenSTAAD.Support.CreateSupportFixed
123+
124+
'Assign support at nodes 1 and 2
125+
objOpenSTAAD.Support.AssignSupportToNode 1, supportNo
126+
objOpenSTAAD.Support.AssignSupportToNode 2, supportNo
127+
128+
' Clean up
129+
Set objShell = Nothing
130+
Set objOpenSTAAD = Nothing
131+
End Sub
132+
```
133+
134+
## Extract Results
135+
- This is sample code to display node results
136+
- I am using fake data to display a report table
137+
- You can use the OpenSTAAD API to extract results as per your requirements
138+
- You can refer to this post for sample code on how to extract results using OpenSTAAD: [How to Extract Results from STAAD to Excel Using VBA](/posts/staad-excel-extract-results)
139+
140+
```vb
141+
Sub Main()
142+
'Create OpenSTAAD Object
143+
Dim objOpenSTAAD As Object
144+
Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
145+
146+
Dim reportID As Long, tableID As Long, numRows As Long, numCols As Long
147+
148+
numRows = 5
149+
numCols = 2
150+
151+
' Create report
152+
reportID = objOpenSTAAD.Table.CreateReport("Reports")
153+
154+
' Add table to report
155+
tableID = objOpenSTAAD.Table.AddTable(reportID, "Support Reactions", numRows, numCols)
156+
157+
' Set column headers
158+
objOpenSTAAD.Table.SetColumnHeader reportID, tableID, 1, "Node No."
159+
objOpenSTAAD.Table.SetColumnHeader reportID, tableID, 2, "FY (kN)"
160+
161+
' Fill table with data
162+
Dim i As Long
163+
For i = 1 To numRows
164+
objOpenSTAAD.Table.SetCellValue reportID, tableID, i, 1, CStr(i + 1)
165+
objOpenSTAAD.Table.SetCellValue reportID, tableID, i, 2, CStr(i * 10)
166+
Next i
167+
168+
End Sub
169+
```
170+
171+
## Run External Program from STAAD
172+
- You can use this code to run your external program directly from STAAD
173+
- If it's a Python script, convert it into an exe file and you can run it via STAAD
174+
175+
```vb
176+
Sub Main
177+
178+
'Create OpenSTAAD Object
179+
Dim objOpenSTAAD As Object
180+
Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
181+
182+
'Check if model is open
183+
Dim stdFilePath As String
184+
objOpenSTAAD.GetSTAADFile stdFilePath, True
185+
186+
If stdFilePath = "" Then
187+
'Model is not open; exit sub
188+
MsgBox "No Active Model Found. Please open a STAAD model and retry.", vbExclamation, "No Active Model"
189+
Set objOpenSTAAD = Nothing
190+
Exit Sub
191+
End If
192+
193+
'Create Shell object
194+
Dim objShell
195+
Set objShell = CreateObject("WScript.Shell")
196+
197+
' Get application path
198+
Dim applicationPath
199+
applicationPath = "C:\SampleApp\Console.exe"
200+
201+
' Construct the command to open the STAAD model
202+
Dim command
203+
command = """" & applicationPath & """ """ & stdFilePath & """"
204+
205+
' Execute the command to open STAAD.Pro with the specified model
206+
objShell.Run command, 1, False
207+
208+
' Clean up
209+
Set objShell = Nothing
210+
Set objOpenSTAAD = Nothing
211+
212+
End Sub
213+
```
214+
215+
## Conclusion
216+
- You can build small tools to assist with your regular tasks using STAAD Visual Basic script since it doesn't require any setup or admin permission
217+
- I personally prefer not to code using Visual Basic script since it's quite old, so I usually just use it to call my exe file
218+
- For large model generation or results extraction, running the script can be very slow, so my advice is to minimize STAAD while running your script to speed up execution
219+
- I'll try to keep this updated with more variations and use cases
220+

0 commit comments

Comments
 (0)