(API) Selecting Items with API and show selection in GUI

(API) Selecting Items with API and show selection in GUI

rick.boender
Contributor Contributor
1,228 Views
6 Replies
Message 1 of 7

(API) Selecting Items with API and show selection in GUI

rick.boender
Contributor
Contributor

I have made a program that selects beams and nodes from values specified in an Excel sheet, this selection is used to extract bar forces at a connection. Now I would like to add a module to check the user input. I would like to select the nodes of bars listed in a certain cell, and have Robot show the selection in the GUI. The problem is, nothing shows if I select items through the API interface (from an Excel macro).

 

I use the following code to select items:

Set RSelection = RobApp.Project.Structure.Selections.Create(I_OT_NODE)
Dim NodeCol As RobotNodeCollection

RSelection.FromText Cells(CurrentRow, 2)

Set NodeCol = RobApp.Project.Structure.Nodes.GetMany(RSelection)

This code works perfectly for what it is intended to do, but how can I change it so that the selection will show in the GUI?

 

Thanks in advance for any help.

0 Likes
Accepted solutions (1)
1,229 Views
6 Replies
Replies (6)
Message 2 of 7

Rafal.Gaweda
Autodesk Support
Autodesk Support
0 Likes
Message 3 of 7

rick.boender
Contributor
Contributor

Hello Rafal,

 

Thanks for your reaction. Unfortunately I could not get around to the debugging until now, but it does not seem to work. The program selects the bars and nodes, but the window does not show anything.

 

I found the following in the locals window. The property Me.Robapp.Visible = -1, could that have something to do with it?

 

I have the following code:

 

Sub showSelectedLineInRobot()

Dim CurrentRow As Long
CurrentRow = Selection.row

Set RobApp = New RobotApplication
Dim RSelection As RobotSelection
Dim RSelection2 As RobotSelection

 

'sets the connection node number
Set RSelection = RobApp.Project.Structure.Selections.Create(I_OT_NODE)
Dim NodeCol As RobotNodeCollection
Dim n1 As RobotNode

If (Cells(CurrentRow, 2) <> "") Then
RSelection.FromText Cells(CurrentRow, 2)

Set NodeCol = RobApp.Project.Structure.Nodes.GetMany(RSelection)
Else
MsgBox ("No nodes in selection cell B" & Str(CurrentRow))
Set NodeCol = Nothing
Exit Sub
End If

If (NodeCol.Count <> 1) Then
MsgBox ("No Valid Node number in cell B" & Str(CurrentRow) & ", please enter a single existing node number.")
Exit Sub
Set NodeCol = Nothing
Else

Set n1 = NodeCol.Get(1)
End If

'set Brace member number
Set RSelection = RobApp.Project.Structure.Selections.Create(I_OT_BAR)
Dim BarCol As RobotBarCollection
Dim Cbar As RobotBar

If (Cells(CurrentRow, 3) <> "") Then
RSelection.FromText Cells(CurrentRow, 3)
Set BarCol = RobApp.Project.Structure.Bars.GetMany(RSelection)
Else
MsgBox ("No bars in selection cell C" & Str(CurrentRow))
Set BarCol = Nothing
Exit Sub
End If

If (BarCol.Count <> 1) Then
MsgBox ("No Valid Bar number in cell C" & Str(CurrentRow) & ", please enter a single existing bar number.")
Set BarCol = Nothing
Exit Sub
Else
Set Cbar = BarCol.Get(1)
End If

'set Chord member number(s) May be 1 or 2 members

Dim BarCol2 As RobotBarCollection
Set RSelection2 = RobApp.Project.Structure.Selections.Create(I_OT_BAR)

If (Cells(CurrentRow, 4) <> "") Then
RSelection2.FromText Cells(CurrentRow, 4)
Set BarCol2 = RobApp.Project.Structure.Bars.GetMany(RSelection2)
Else
MsgBox ("No bars in selection cell D" + Str(CurrentRow))
Set BarCol2 = Nothing
Exit Sub
End If

If (BarCol2.Count <> 1 And BarCol2.Count <> 2) Then
MsgBox ("No Valid Bar number in cell D" & Str(CurrentRow) & ", please enter 1 or 2 existing bar numbers.")
Set BarCol = Nothing
Exit Sub
Else
RSelection2.Add RSelection
End If

Dim Rv As RobotView
Set Rv = RobApp.Project.ViewMngr.GetView(1)
Dim RVP As RobotViewDisplayParams
Set RVP = Rv.ParamsDisplay
RVP.Set I_VDA_STRUCTURE_ONLY_FOR_SELECTED_OBJECTS, True
RVP.Set I_VDA_STRUCTURE_NODE_NUMBERS, True
RVP.Set I_VDA_STRUCTURE_BAR_NUMBERS, True


RobApp.Project.ViewMngr.Refresh


End Sub

 

Thanks in advance for any help,

Best Regards,

Rick Boender

0 Likes
Message 4 of 7

carlos_meri
Explorer
Explorer
Accepted solution

I got Access Denied, can you please share it openly? Thank you

 

0 Likes
Message 5 of 7

Stephane.kapetanovic
Mentor
Mentor

hi @carlos_meri 

 

When working with selections, you must use the Get method instead of Create to instantiate your selection.

While both methods allow for selection, only Get enables interaction with the view.

 

At Autodesk’s initiative (see topic), older topics, though still valuable, have been deleted and not archived. However, you can still access copies via the links below.

https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-highlight-nodes-in-robot/td-p/953...

The previous method used to display nodes with instabilities is now less relevant, as this functionality is now integrated directly into the program.

https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-macro-for-highlighting-nodes-with...

 

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
Message 6 of 7

carlos_meri
Explorer
Explorer

thank you @Stephane.kapetanovic for the fast response, 
it works using Get instead of Create

Python example:

selection = RobotOM.RobotSelection(RobotObject.Project.Structure.Selections.Get(RobotOM.IRobotObjectType.I_OT_PANEL))
selection.AddText("131 183")
 

 

0 Likes
Message 7 of 7

Stephane.kapetanovic
Mentor
Mentor

Remember that AddText appends to the existing selection, while FromText replaces it with the new text

selection.FromText("131 183")

 

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