(API) Retrive Nodes of a group from exsisting group and then extracting the results

(API) Retrive Nodes of a group from exsisting group and then extracting the results

muhammad_hasan88NXQ
Enthusiast Enthusiast
788 Views
7 Replies
Message 1 of 8

(API) Retrive Nodes of a group from exsisting group and then extracting the results

muhammad_hasan88NXQ
Enthusiast
Enthusiast

Hi Guys,

 

I am trying to create VBA excel to extract the exsisting Node group list from robot and then extract the nodal and FE-Resulta of the selected node group from the list. For that As 1st setp I tried to retive the exsisting group list from robot

but I amgetting Mismatch error in the highlighted line.

Sub ListNodesGroup()
Dim RobApp As RobotApplication
Dim RGroups As RobotGroupServer
Set RobApp = New RobotApplication
Set RGroups = RobApp.Project.Structure.Groups
Dim Group As RobotGroup, GroupCnt As Integer, ObjTyp As IRobotObjectType
ObjTyp = IRobotObjectType.I_OT_NODE
GroupCnt = RGroups.GetCount(ObjTyp)
If GroupCnt <> 0 Then
For j = 1 To GroupCnt
Set Group = RGroups.Get(ObjTyp, j)
Cells(2 + j, 1) = j
Cells(2 + j, 2) = Group.Name
Next j
End If
Set RobApp = Nothing
End Sub

please help me 

 

0 Likes
789 Views
7 Replies
Replies (7)
Message 2 of 8

Stephane.kapetanovic
Mentor
Mentor

hi @muhammad_hasan88NXQ 

I have a script similar to yours and it works. See in your file or restart robot by terminating all instances.

See Also : 

(API) Get groups through API

How to add loads to a robot group selection (API) 

Group Colors

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 3 of 8

muhammad_hasan88NXQ
Enthusiast
Enthusiast

Hi Stephen Thyank you for your help,

Next I wanted to extract the nodes from specific group to excel sheet with nodal co-ordinates.

"Sub CreateNewSheetFromCellValue()
Dim ws As Worksheet
Dim GrpName As String
Dim NodeSheet As Worksheet, ResultSheet As Worksheet
Dim lastRow As Long, count As Long, row As Long
Dim I As Long

' Define the current worksheet
Set ws = ThisWorkbook.Sheets("NodeGroupList")

'Find Number of rows in column
lastRow = ws.Cells(ws.Rows.count, "A").End(xlUp).row
count = Application.WorksheetFunction.CountA(ws.Range("A3:A" & lastRow))

' Get the value from a specific cell to use as the new sheet name
row = 2
For I = 1 To count
If ws.Cells(row + I, 3).Value = "Yes" Then
GrpName = ws.Cells(row + I, 2).Value

' Check if the sheet with the same name already exists
If SheetExists(GrpName & "-Node") Or SheetExists(GrpName & "-Result") Then
MsgBox "Sheet with the name '" & GrpName & "' already exists!", vbExclamation
Exit Sub
End If

' Add and Rename a new worksheet
Set NodeSheet = ThisWorkbook.Sheets.Add
NodeSheet.Name = GrpName & "-Node"
Set ResultSheet = ThisWorkbook.Sheets.Add
ResultSheet.Name = GrpName & "-Result"
'Atictivate Node sheet
NodeSheet.Activate
Cells(1, 1).Value = "Node"
Cells(1, 2).Value = "X(m)"
Cells(1, 3).Value = "Y(m)"
Cells(1, 4).Value = "Z(m)"

'robot get nodes of selected group
Dim RobApp As RobotApplication
Dim RGroups As RobotGroupServer
Set RobApp = New RobotApplication
Set RGroups = RobApp.Project.Structure.Groups
Dim ObjType As IRobotObjectType
Dim Group As RobotGroup
ObjTyp = IRobotObjectType.I_OT_NODE
Set Group = RGroups.Get(ObjTyp, ws.Cells(row + I, 1).Value)
If Group.Name = GrpName Then
Dim NodeCol As RobotNodeCollection
Set NodeCol = RobApp.Project.Structure.Nodes.Get(Group.SelList)
Dim RNode As RobotNode
For ii = 1 To NodeCol.count
row = 2
Set RNode = NodeCol.Get(ii)
Cells(row, 1) = RNode.Number
Cells(row, 2) = RNode.X
Cells(row, 3) = RNode.Y
Cells(row, 4) = RNode.Z

Next ii
End If
Set RobApp = Nothing

End If
Next I
End Sub"

 

I am getting mismatch error in the highlited line. I am attaching my excel fro your reference.

0 Likes
Message 4 of 8

HI @muhammad_hasan88NXQ 

According to page 528 of the RobotAPI____.pdf guide, the NodeServer's Get method takes a number in long format as an argument. If you want to get a collection, you can use the GetMany method. For help on the Get and GetMany methods, see pages 34 and 35. As GetMany takes a selection as an argument, you must create it with the Create method and apply the text list obtained from the group. 

Dim Structure As RobotStructure
Dim nSel As RobotSelection, nCol As RobotNodeCollection
  
Set Structure = RobApp.Project.Structure
Set nSel = Structure.Selections.Create(I_OT_NODE): nSel.FromText ("1 2 3 4 5")
Set nCol = Structure.Nodes.GetMany(nSel)

All these extractions are likely to be long, you should think about your objective and how to achieve it as simply as possible.

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 5 of 8

muhammad_hasan88NXQ
Enthusiast
Enthusiast

Hi Stephan,

Thank u for you r help so you r creating a temp group as nsel for the nodes say "1,2,34,5". and applying to select the corresponding nodes.So My doubt is say I have already created group with nodes in the robot and I will extract the nodes by Group.SelList to a cell in excel say " 1 to 12 50 55 65 by 70" can i use this .ForText function will that work.

 

0 Likes
Message 6 of 8

To keep your internal lists in your own language, you can use the method that Roman Zhelezniak (@Romanich ) shared with us.

His method consists of temporarily changing the language during the transmission of the lists, so you will not be constrained if the project language differs from that used in your code. Your app becomes international

You can also interpolate the texts of your lists with the Replace method in VBA Excel but this may not cover all possible uses.

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 7 of 8

muhammad_hasan88NXQ
Enthusiast
Enthusiast

Hi Stephane,

   Sorry for late reply, To be frank I am not expert in both VBA or robot coding your guidence was very help full to me.On the topic of changing Language I am not familiar with it and try to know it. Any how I tried in my coding Now the mis match error is gone but even after providing node list as srting the code is not getting the nodes the "nsel" count remains 0. Please help.

"'robot get nodes of selected group
Dim RobApp As New RobotApplication
'get current language of Robot
Dim lang As Long
lang = RobApp.Preferences.GetLanguage(I_L_WORK)
RobApp.Kernel.Preferences.SetLanguage I_L_WORK, 1 'switch to English (code 1)
Dim RGroups As RobotGroupServer
Set RobApp = New RobotApplication
Set RGroups = RobApp.Project.Structure.Groups
Dim ObjType As IRobotObjectType
Dim Group As RobotGroup
ObjTyp = IRobotObjectType.I_OT_NODE
Set Group = RGroups.Get(ObjTyp, ws.Cells(row + I, 1).Value)
If Group.Name = GrpName Then
Dim NCol As RobotNodeCollection
Cells(1, 15) = Group.SelList
Dim nSel As RobotSelection
Set nSel = RobApp.Project.Structure.Selections.Create(I_OT_NODE): nSel.FromText (CStr(Cells(15, 1)))
Set NCol = RobApp.Project.Structure.Nodes.GetMany(nSel)
Dim RNode As RobotNode
For ii = 1 To nSel.count
row = 2
Set RNode = NodeCol.Get(ii)
Cells(row, 1) = RNode.Number
Cells(row, 2) = RNode.X
Cells(row, 3) = RNode.Y
Cells(row, 4) = RNode.Z

Next ii
End If
Set RobApp = Nothing

End If
Next I
End Sub"

 

muhammad_hasan88NXQ_0-1710993618591.png

@Romanich  , @Artur.Kosakowski @Rafacascudo @Rafal.Gaweda

 

0 Likes
Message 8 of 8

hi @muhammad_hasan88NXQ 

Remember, the forum's essence is to encourage open participation in API functionality discussions, prioritizing meaning over specific code provision.

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature