API example: Looping through entities
Entities in studies are available though linked lists, one for each entity type, such as node, triangle, tetrahedron (tetra), and so forth. This example implements several loops for looking at each entity of each type.
This script performs the following tasks:
- Finds the maximum node number
- Counts the number of beams
- Counts the number of tetras
- Counts the number of triangles
You can use this script when you want to read nodal data.
'%RunPerInstance
'@
'@ DESCRIPTION
'@ Example of how to loop through entities using the API
'@
'@ SYNTAX
'@ LoopThroughEntities
'@
'@ PARAMETERS
'@ none
'@
'@ DEPENDENCIES/LIMITATIONS
'@ none
'@
'@ History
'@ Created DRA 9/8/2006
'@@
Option Explicit
SetLocale("en-us")
Dim SynergyGetter, Synergy
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
Set Synergy = SynergyGetter.GetSASynergy
Else
Set Synergy = CreateObject("synergy.Synergy")
End If
Synergy.SetUnits "METRIC"
Dim StudyDoc
Dim MaxNumber, Node, NodeNumber, Count, Tri, Tet, Beam
Set StudyDoc = Synergy.StudyDoc
' Loop through all nodes and find the highest Node Number
MaxNumber = 0
Set Node = StudyDoc.GetFirstNode()
While Not Node Is Nothing
NodeNumber = StudyDoc.GetEntityID(Node)
If NodeNumber > MaxNumber Then
MaxNumber = NodeNumber
End if
Set Node = StudyDoc.GetNextNode(Node)
Wend
MsgBox "Maximum Node Number in Model is: " & CStr(MaxNumber)
' Count all Triangular Elements in the Model
Count = 0
Set Tri = StudyDoc.GetFirstTri()
While Not Tri Is Nothing
Count = Count + 1
Set Tri = StudyDoc.GetNextTri(Tri)
Wend
MsgBox "Model Contains " & CStr(Count) & " Triangular Elements"
' Count all Tet Elements in the Model
Count = 0
Set Tet = StudyDoc.GetFirstTet()
While Not Tet Is Nothing
Count = Count + 1
Set Tet = StudyDoc.GetNextTet(Tet)
Wend
MsgBox "Model Contains " & CStr(Count) & " Tet Elements"
' Count all Beam Elements in the Model
Count = 0
Set Beam = StudyDoc.GetFirstBeam()
While Not Beam Is Nothing
Count = Count + 1
Set Beam = StudyDoc.GetNextBeam(Beam)
Wend
MsgBox "Model Contains " & CStr(Count) & " Beam Elements"
MsgBox "Script Complete"
Wscript.Quit