In order to
successfully run an
OpenSTAAD macro, you must
first open a model within STAAD.Pro.
This example
continues by using a function in
OpenSTAAD to access model
data.
-
Type
Sheet1.[A1].Value =
"Nodes:"
and then press Return.
Much like the
Hello World
example, this simply populates a
cell with a text string. Here, it’s useful to provide a label for your data.
-
Type
Sheet1.[B1].Value =
objOpenSTAAD.Geometry.GetNodeCount
and then press Return.
Here, you are assigning the value of a cell to the
returned value of the
GetNodeCount
function, which is in the
Geometry
class within the
OpenSTAAD object.
This approach accesses the GetNodeCount function
directly within the objOpenSTAAD object.
-
Type
Dim objGeometry As OSGeometryUI
and then press
Return.
If you
connected the
VBA Editor to STAAD, then you will notice that the editor will begin
auto-completion when you start typing
OSGeometryUI
. You can press
Tab to accept
the highlighted result in the auto-completion pop-up list and move to the end
of that entry.
-
Type
Set geometry = objOpensTAAD.geometry
and then press
Return.
This will assign the object geometry to the geometry
class within the OpenSTAAD object.
-
Type
Sheet1.[A2].Value =
"Members:"
and then press Return.
-
Type
Sheet1.[B2].Value = geometry.GetMemberCount
and then
press Return.
Here, you will notice that the auto-completion menu
opens again once you type
geometry.
to show you all of the functions and
methods within the geometry class in OpenSTAAD. This is the benefit of first
setting the object to that class.
-
Run your macro.
The spreadsheet populates with the number of
nodes and members in the currently open STAAD.Pro model.
The spreadsheet will now populate with the number of
nodes and members in the currently open STAAD.Pro model.
You complete code
should look like this:
Sub OpenSTAADTutorial()
Dim objOpenSTAAD As Object
Dim stdFile As String
Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
Sheet1.[A1].Value = "Nodes:"
Sheet1.[B1].Value = objOpenSTAAD.geometry.GetNodeCount
Dim geometry As OSGeometryUI
Set geometry = objOpenSTAAD.geometry
Sheet1.[A2].Value = "Members:"
Sheet1.[B2].Value = geometry.GetMemberCount
End Sub
Next, you will create a simple UI element in your spreadsheet to access
the macro.