Tekla Open API: Ask User to Select Objects

This article explains how you can ask the user to select objects from the model using the Tekla Open API. It also provides examples as to how to filter the objects selected by the user.


Contents

Step 1:

Add reference to the Tekla.Structures.Model and Tekla.Structures.Drawing library located in the path “C:Program FilesTekla Structures20.0ntbinplugins” and manually open the tekla model. This has been covered in the article below:


Ask User to Select Objects:

The following code asks the user to select objects from the model. It returns a list of all selected objects by the user.

Imports TSM = Tekla.Structures.Model
Imports TSD = Tekla.Structures.drawing

    ''' <summary>
    ''' Ask the user to select objects from the model
    ''' </summary>
    ''' <returns>The list of selected objects by the user</returns>
    ''' <remarks></remarks>
    Private Function SelectObjects() As List(Of Object)
        Dim objUIPICker As TSM.UI.Picker
        Dim objModelObjectEnumerator As TSM.ModelObjectEnumerator
        Dim lstOutput As List(Of Object)

        objUIPICker = New TSM.UI.Picker()
        lstOutput = New List(Of Object)

        Try
            'This line asks the user to select an object from the model
            objModelObjectEnumerator = objUIPICker.PickObjects(Tekla.Structures.Model.UI.Picker.PickObjectsEnum.PICK_N_OBJECTS, "Select Objects")
            'loops through all the objects selected by the user
            While objModelObjectEnumerator.MoveNext
                'adds the object to the output list
                lstOutput.Add(objModelObjectEnumerator.Current)
            End While
        Catch
        End Try
        Return lstOutput
    End Function

The code in line 19 asks the user to select objects. The first parameter is the type of object the user will be selecting. In this example we have used the generic “Object” type. The second parameter is the text that is displayed at the bottom of the screen when prompting the user to select objects.
Blog_Tekla_AskUser2SelectObjects_1

Lines 21~24 loop through the list of objects selected by the user.


Ask User to Select Specific Object Types (Parts, Rebars, Welds, ….):

In the previous example the user was asked to select objects of any kinds. In this example the user will be asked to only select a specific type of object. For example parts:

Imports TSM = Tekla.Structures.Model
Imports TSD = Tekla.Structures.drawing

    ''' <summary>
    ''' Ask the user to select parts from the model
    ''' </summary>
    ''' <returns>The list of selected parts by the user</returns>
    ''' <remarks></remarks>
    Private Function SelectParts() As List(Of TSM.Part)
        Dim objUIPICker As TSM.UI.Picker
        Dim objModelObjectEnumerator As TSM.ModelObjectEnumerator
        Dim lstOutput As List(Of TSM.Part)

        objUIPICker = New TSM.UI.Picker()
        lstOutput = New List(Of TSM.Part)

        Try
            'This line asks the user to select an object from the model
            objModelObjectEnumerator = objUIPICker.PickObjects(Tekla.Structures.Model.UI.Picker.PickObjectsEnum.PICK_N_PARTS, "Select Objects")
            'loops through all the objects selected by the user
            While objModelObjectEnumerator.MoveNext
                'adds the object to the output list
                lstOutput.Add(objModelObjectEnumerator.Current)
            End While
        Catch
        End Try
        Return lstOutput
    End Function

When the function is called the user will only be able to select parts from the model.

Other options include:

  • PICK_N_OBJECTS
  • PICK_N_PARTS
  • PICK_N_REINFORCEMENTS
  • PICK_N_WELDS
  • PICK_N_BOLTGROUPS

Filter Selected Objects:

Assume we set the first parameter to PICK_N_REINFORCEMENTS. The user will only be able to select reinforcements  But lets we are only interested in “Single Rebars”. Using the previous function the user will be able to end up selecting not only Single Rebars but also all other reinforcements as well:

  • Single Rebars
  • Group Reinforcements
  • Meshes

In order to overcome this problem the function below can be used:

Imports TSM = Tekla.Structures.Model
Imports TSD = Tekla.Structures.drawing

   ''' <summary>
    ''' Ask the user to select SingleRebars from the model
    ''' </summary>
    ''' <returns>The list of selected Single Rebars by the user</returns>
    ''' <remarks></remarks>
    Private Function SelectSingleRebars() As List(Of TSM.SingleRebar)
        Dim objUIPICker As TSM.UI.Picker
        Dim objModelObjectEnumerator As TSM.ModelObjectEnumerator
        Dim lstOutput As List(Of TSM.SingleRebar)
        Dim objSingleRebars As TSM.SingleRebar

        objUIPICker = New TSM.UI.Picker()
        lstOutput = New List(Of TSM.SingleRebar)

        Try
            'This line asks the user to select an object from the model
            objModelObjectEnumerator = objUIPICker.PickObjects(Tekla.Structures.Model.UI.Picker.PickObjectsEnum.PICK_N_REINFORCEMENTS, "Select Singel Rebars")
            'loops through all the objects selected by the user
            While objModelObjectEnumerator.MoveNext
                objSingleRebars = TryCast(objModelObjectEnumerator.Current, TSM.SingleRebar)
                If IsNothing(objSingleRebars) = False Then
                    'adds the object to the output list
                    lstOutput.Add(objSingleRebars)
                End If

            End While
        Catch
        End Try
        Return lstOutput
    End Function

Line 23 tries to convert the select object to a single rebar. If it fails the the variable objsinglerebar will be empty. Line 24 checks if the conversion has been successful. If true then single rebar object is added to the output list.

Another scenario would be, only looking for objects of a certain class, name, material, … . This could also be accomplished using the function below. Similar to the example above, the program asks the user to select reinforcements. Among the selected reinforcements only the single rebars are accepted. Another IF statement is used to filter the single rebars whose class is not equal to 5:

Imports TSM = Tekla.Structures.Model
Imports TSD = Tekla.Structures.drawing

 ''' <summary>
    ''' Ask the user to select SingleRebars from the model. Only return rebars with a class of 5
    ''' </summary>
    ''' <returns>The list of selected Single Rebars by the user</returns>
    ''' <remarks></remarks>
    Private Function SelectSingleRebars() As List(Of TSM.SingleRebar)
        Dim objUIPICker As TSM.UI.Picker
        Dim objModelObjectEnumerator As TSM.ModelObjectEnumerator
        Dim lstOutput As List(Of TSM.SingleRebar)
        Dim objSingleRebars As TSM.SingleRebar

        objUIPICker = New TSM.UI.Picker()
        lstOutput = New List(Of TSM.SingleRebar)

        Try
            'This line asks the user to select an object from the model
            objModelObjectEnumerator = objUIPICker.PickObjects(Tekla.Structures.Model.UI.Picker.PickObjectsEnum.PICK_N_REINFORCEMENTS, "Select Singel Rebars")
            'loops through all the objects selected by the user
            While objModelObjectEnumerator.MoveNext
                objSingleRebars = TryCast(objModelObjectEnumerator.Current, TSM.SingleRebar)
                If IsNothing(objSingleRebars) = False Then
                    If objSingleRebars.Class = 5 Then
                        'adds the object to the output list
                        lstOutput.Add(objSingleRebars)
                    End If
                End If

            End While
        Catch
        End Try
        Return lstOutput
    End Function

Line 25 checks the class of the rebar. If it is equal to 5, it will be added to the output list.

You can download the sample files and codes used in this article from the link below:

If you need assistance with your Tekla model, or you are looking for a Tekla Open API programmer to hire feel free to contact me. Also please visit my home page  www.software-solutions-online.com

One thought on “Tekla Open API: Ask User to Select Objects”

Leave a Reply

Your email address will not be published. Required fields are marked *