Tekla Open API: Get Part Length

This article explains how you can get the length of a part using the Tekla Open API.


Contents

Step 1:

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


Step 2:

You will need to get reference to the part you wish to get its length. Below are some of the options for achieving this:

1  – Create a new part and keep a reference to the part: Insert Concrete Beam Using VB.Net (Tekla Open API)

2 – Get reference to an existing part in the tekla model: VB.Net Get Reference to Object, Tekla Open API

3- Ask the user to select parts from the model: Tekla Open API: Ask User to Select Objects.


Step 3:

Pass the reference to the part object obtained in step 2 to the function below to get the length of the part:

Imports TSM = Tekla.Structures.Model
Imports TSG = Tekla.Structures.Geometry3d

    ''' <summary>
    ''' Returns the length of the input part
    ''' </summary>
    ''' <param name="objBeam">The part object to return its length</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function Length(ByRef objBeam As TSM.Beam) As Double
        Dim dblOutput As Double
        Dim objPoint1 As TSG.Point
        Dim objPoint2 As TSG.Point
        objPoint1 = objBeam.StartPoint
        objPoint2 = objBeam.EndPoint
        dblOutput = ((objPoint1.X - objPoint2.X) ^ 2 + (objPoint1.Y - objPoint2.Y) ^ 2 + (objPoint1.Z - objPoint2.Z) ^ 2) ^ 0.5
        Return dblOutput
    End Function

Note: If the part has offset values in the X direction the previous function will not return correct results. In order to account for the offsets the function below could be used:

Imports TSM = Tekla.Structures.Model
Imports TSG = Tekla.Structures.Geometry3d

    ''' <summary>
    ''' Returns the length of the input part
    ''' </summary>
    ''' <param name="objBeam">The part object to return its length</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function LengthWithOffsset(ByRef objBeam As TSM.Beam) As Double
        Dim dblOutput As Double
        Dim objPoint1 As TSG.Point
        Dim objPoint2 As TSG.Point
        objPoint1 = objBeam.StartPoint
        objPoint2 = objBeam.EndPoint
        dblOutput = ((objPoint1.X - objPoint2.X) ^ 2 + (objPoint1.Y - objPoint2.Y) ^ 2 + (objPoint1.Z - objPoint2.Z) ^ 2) ^ 0.5
        dblOutput = dblOutput + objBeam.EndPointOffset.Dx - objBeam.StartPointOffset.Dx
        Return dblOutput
    End Function

You can download the sample file and code for 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: Get Part Length”

Leave a Reply

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