thank you stephane for your response
here my code :
'' Create new rigid links
Sub CreateNewRigidLinks()
Dim robApp As IRobotApplication
Dim storeyMngr As RobotStoreyMngr
Dim rigidLinkServer As IRobotNodeRigidLinkServer
Dim nodeServer As IRobotNodeServer
Dim nodeDisplacementServer As RobotNodeDisplacementServer
Dim i As Integer, j As Integer
Dim newNodeNumber As Long
Dim storeyCount As Integer
' Create a rigid link label
Dim labelLink As IRobotLabel
Dim RigidLinkLabel As String
RigidLinkLabel = "WalidBouzRigidLink"
Set labelLink = robApp.Project.Structure.Labels.Create(I_LT_NODE_RIGID_LINK, RigidLinkLabel)
' Set rigid link properties (parameterized)
Dim RLdata As IRobotNodeRigidLinkData
Set RLdata = labelLink.Data
RLdata.UX = True
RLdata.UY = True
RLdata.UZ = False
RLdata.rx = False
RLdata.ry = False
RLdata.RZ = True
' Store the label
robApp.Project.Structure.Labels.Store labelLink
' Initialize storey count
storeyCount = 0
' Loop through each storey
For i = 1 To storeyMngr.Count
Dim storeyHeight As Double
storeyHeight = storeyMngr.Get(i).TopLevel
' Retrieve the storey's reference point (G.X, G.Y)
Dim Gx As Double, Gy As Double
Gx = robApp.Project.Structure.Results.Storeys.values(i, 1).G.X
Gy = robApp.Project.Structure.Results.Storeys.values(i, 1).G.Y
' Find all nodes at the same elevation (storeyHeight)
Dim nodesAtElevation As Collection
Set nodesAtElevation = New Collection
For j = 1 To nodeServer.GetAll().Count
Dim node As IRobotNode
Set node = nodeServer.GetAll().Get(j)
If Abs(node.Z - storeyHeight) < 0.001 Then
nodesAtElevation.Add node.Number
End If
Next j
' Check if a node already exists at (G.X, G.Y, storeyHeight)
Dim masterNode As Long
masterNode = -1 ' Default value if no node is found
For j = 1 To nodesAtElevation.Count
Set node = nodeServer.Get(nodesAtElevation(j))
If Abs(node.X - Gx) < 0.001 And Abs(node.Y - Gy) < 0.001 And Abs(node.Z - storeyHeight) < 0.001 Then
masterNode = node.Number
Exit For
End If
Next j
' If no node exists, create a new master node
Dim nodeCreation As String
If masterNode = -1 Then
masterNode = nodeServer.FreeNumber
nodeServer.Create masterNode, Gx, Gy, storeyHeight
Else
' Remove the master node from the collection of nodes at the same elevation
For j = nodesAtElevation.Count To 1 Step -1
If nodesAtElevation(j) = masterNode Then
nodesAtElevation.Remove j
Exit For
End If
Next j
End If
' Create a rigid link with the master node and nodes at the same elevation
If nodesAtElevation.Count > 0 Then
' Format secondary nodes as a string
Dim secondaryNodesStr As String
secondaryNodesStr = ""
For j = 1 To nodesAtElevation.Count
secondaryNodesStr = secondaryNodesStr & nodesAtElevation(j) & " "
Next j
' Create the rigid link using the stored label
rigidLinkServer.Set masterNode, secondaryNodesStr, RigidLinkLabel
' Increment storey count
storeyCount = storeyCount + 1
End If
Next i
End Sub
1- You’re right, naming it storeyHeight isn’t the clearest choice. I’ll rename it to TopLevelOfStorey to better reflect its purpose. Thanks for pointing that out.
2- You’re right. I was using a Collection to store nodes at the same elevation as a way to group them for further processing. If there’s a more efficient way to directly select nodes by elevation without iterating through all nodes and minimize unnecessary iterations, I’d be glad to learn about it. The goal is to apply rigid links efficiently to nodes at the top level of each storey.
3- Right now, I loop through all nodes and compare their Z coordinate with the top level of each storey. It’s not efficient for large models. Does RSA’s API offer a way to directly query nodes by elevation or storey?
5-this is the correct way you mean
' Find all nodes at the same elevation (storeyHeight)
Dim nodesAtElevation As Collection
Set nodesAtElevation = New Collection
Set allNodes = nodeServer.GetAll()
For j = 1 To allNodes.Count
Dim node As IRobotNode
Set node = allNodes.Get(j)
If Abs(node.Z - TopLevelOfStorey) < 0.001 Then
nodesAtElevation.Add node.Number
End If
Next j
6- The structure I’m working on is a multi-storey building. The purpose of the code is to create rigid links between all nodes at the top level of each storey and a single master node.