VB.Net Get Reference to Object, Tekla Open API

This article explains how you can reference to existing objects in a Tekla Structure model using the Tekla Open API in VB.Net.


Contents

Step 1:

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


Get Reference to Concrete Part:

The following code will loop through all the objects in the model. It will return the first instance of a concrete part it finds:

Imports TSM = Tekla.Structures.Model
    ''' <summary>
    ''' Returns reference to first concrete part found in model
    ''' </summary>
    ''' <remarks></remarks>
    Private Function GetConcretePart() As TSM.Beam
        Dim appModel As TSM.Model
        appModel = New TSM.Model
        Dim objModel As TSM.ModelObject
        Dim objBeam As TSM.Beam
        For Each objModel In appModel.GetModelObjectSelector.GetAllObjects
            objBeam = TryCast(objModel, Tekla.Structures.Model.Beam)
            If IsNothing(objBeam) = False Then
                appModel = Nothing
                objModel = Nothing
                Return objBeam
            End If
        Next
        appModel = Nothing
        objModel = Nothing
        Return Nothing
    End Function

Note that the “Beam” object could actually be any concrete part (column, slab, foundation, …). lines 11~16 loop through every object in the model. Line 12 tries to cast the object into a beam object. If it succeeds then line 14 will return the beam object.


Get Reference to Single Rebar:

Similar to the code in the previous section the code in this section will return the first instance of a single rebar it finds:

Imports TSM = Tekla.Structures.Model

     ''' <summary>
    ''' Returns reference to first single rebar found in model
    ''' </summary>
    ''' <remarks></remarks>
    Private Function GetSingleRebar() As TSM.SingleRebar
        Dim appModel As TSM.Model
        appModel = New TSM.Model
        Dim objModel As TSM.ModelObject
        Dim objSingelRebar As TSM.SingleRebar
        For Each objModel In appModel.GetModelObjectSelector.GetAllObjects
            objSingelRebar = TryCast(objModel, Tekla.Structures.Model.SingleRebar)
            If IsNothing(objSingelRebar) = False Then
                Return objSingelRebar
            End If
        Next
        Return Nothing
    End Function

Other Object Types:

In the previous 2 sections I’ve explained how you can get reference to the first instance of a concrete part and single reinforcement found in the model. Similarly you get reference to any other object type in the model by replacing the cast type on line 12.

  • TSM.RebarGroup
  • TSM.Grid
  • TSM.Weld
  • TSM.RebarMesh

Specific Objects:

Sometimes you may be looking for a specific a specific object or group of objects. For example:

  • All single rebars whose class value is “5”.
  • All concrete parts whose name is “Column”.
  • All group reinforcements with a rebar size equal to 22
  • All concrete slabs who start at the elevation “12m”

This can easily be done by checking the object properties prior to returning them from the function. I have provide an example in the link below:

Example: Tekle Open API: Get All Parts With Specific Class

You can download the file and code 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 “VB.Net Get Reference to Object, Tekla Open API”

Leave a Reply

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