0% found this document useful (0 votes)
4 views4 pages

Code - Sub Get Groups

The provided VBA script connects to STAAD.Pro via OpenSTAAD to retrieve group names and their associated data from a structural model. It checks for existing groups, creates or clears a worksheet named 'STAADGroups', and populates it with group type labels, group names, entity counts, and entities. Finally, it formats the worksheet and logs the progress of the extraction process.

Uploaded by

pushp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Code - Sub Get Groups

The provided VBA script connects to STAAD.Pro via OpenSTAAD to retrieve group names and their associated data from a structural model. It checks for existing groups, creates or clears a worksheet named 'STAADGroups', and populates it with group type labels, group names, entity counts, and entities. Finally, it formats the worksheet and logs the progress of the extraction process.

Uploaded by

pushp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sub Get_STAAD_Group_Names()

' Try to connect to STAAD.Pro via OpenSTAAD

Dim objOpenSTAAD As Object

On Error Resume Next

Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")

On Error GoTo 0

If objOpenSTAAD Is Nothing Then

MsgBox "STAAD.Pro is not running or OpenSTAAD is unavailable.", vbCritical

Exit Sub

End If

Dim OSGeometryUI As Object

Set OSGeometryUI = objOpenSTAAD.Geometry

' Get total group count

Dim TotalGroups As Long

TotalGroups = OSGeometryUI.GetGroupCountAll()

If TotalGroups <= 0 Then

MsgBox "NO Group found in the model.", vbExclamation

GoTo Cleanup

End If

' Create or clear the "STAADGroups" sheet

Dim ws As Worksheet

Set ws = Nothing

On Error Resume Next

Set ws = Worksheets("STAADGroups")

On Error GoTo 0

If ws Is Nothing Then

Set ws = Worksheets.Add(After:=ActiveSheet)
ws.Name = "STAADGroups"

Else

' Clear all contents

ws.Cells.Clear

' Reset outline levels

ws.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1

End If

' Group type labels

Dim GroupTypeNames As Variant

GroupTypeNames = Array("", "Node Groups", "Members Groups", "Plate Groups", "Solid


Groups", "Geometry Groups", "Floor Groups")

Dim rowOffset As Long

rowOffset = 1

Dim GroupNames() As String

Dim GroupCount As Long

Dim i As Long, j As Long, k As Long

Dim GroupEntityCount As Long

Dim EntityList() As Long

Dim EntityString As String

' Loop through group types 1 to 6

For j = 1 To 6

GroupCount = OSGeometryUI.GetGroupCount(j)

If GroupCount > 0 Then

ReDim GroupNames(GroupCount - 1)
OSGeometryUI.GetGroupNames j, GroupNames

' Write section header

ws.Cells(rowOffset, 1).Value = GroupTypeNames(j)

ws.Cells(rowOffset, 1).Font.Bold = True

ws.Cells(rowOffset + 1, 1).Value = "Group No"

ws.Cells(rowOffset + 1, 2).Value = "Group Name"

ws.Cells(rowOffset + 1, 3).Value = "Group Entity Count"

ws.Cells(rowOffset + 1, 4).Value = "Group Entities"

' Write group names and entity data

For i = 0 To GroupCount - 1

ws.Cells(rowOffset + 2 + i, 1).Value = i + 1

ws.Cells(rowOffset + 2 + i, 2).Value = GroupNames(i)

GroupEntityCount =
objOpenSTAAD.Geometry.GetGroupEntityCount(GroupNames(i))

ws.Cells(rowOffset + 2 + i, 3).Value = GroupEntityCount

If GroupEntityCount > 0 Then

ReDim EntityList(GroupEntityCount - 1)

objOpenSTAAD.Geometry.GetGroupEntities GroupNames(i), EntityList

EntityString = ""

For k = 0 To GroupEntityCount - 1

EntityString = EntityString & EntityList(k) & " "

Next k

ws.Cells(rowOffset + 2 + i, 4).Value = Trim(EntityString)

Else

ws.Cells(rowOffset + 2 + i, 4).Value = ""

End If

Next i

rowOffset = rowOffset + GroupCount + 4


End If

Next j

ws.Range("B1").Value = "Total Group:"

ws.Range("C1").Value = TotalGroups

' Autofit columns

ws.Columns("A:D").AutoFit

' Optional: Group columns and format

ws.Columns("D").Group

ws.Columns("D").EntireColumn.Hidden = True

Call LogStatus.LogProgress("All group types extracted successfully!")

Cleanup:

Application.ScreenUpdating = True

Application.Calculation = xlCalculationAutomatic

Set OSGeometryUI = Nothing

Set objOpenSTAAD = Nothing

Application.StatusBar = False

End Sub

You might also like