Tekla Open API: Rotate Part

This article explains how you can rotate existing parts in a Tekla Structure model using the Tekla Open API in VB.Net.

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 rotate. 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.

Rotation About Main Axis:

In order to rotate the part about its main axis, pass the reference to the part object to the function below:

Imports TSM = Tekla.Structures.Model
Imports TSG = Tekla.Structures.Geometry3d
''' <summary>
''' Rotates the part 90 deg about its main axis
''' </summary>
''' <param name="objBeam"></param>
''' <remarks></remarks>
Private Sub Rotate(ByRef objBeam As TSM.Beam)
Dim appTekla As New TSM.Model
objBeam.Position.RotationOffset = 90
appTekla = nothing
End Sub

Note: The main axis is the axis that extends from the start point to the end point of the part and may not be aligned with the center line of the part.

If you are trying to rotate the part about its centerline axis there are a couple solutions. One workaround would be to move the part after the rotation.

A better solution would be to offset the start and end points so that they are located at the center of the part.

Rotation About the Other 2 Axis:

Rotation about the other 2 axis can be done by moving the start and end points. In the example below the part is rotated 90 deg about the Y axis.

Imports TSM = Tekla.Structures.Model
Imports TSG = Tekla.Structures.Geometry3d
''' <summary>
''' Rotates the part 90 deg about Y axis
''' </summary>
''' <param name="objBeam"></param>
''' <remarks></remarks>
Private Sub RotateAboutY(ByRef objBeam As TSM.Beam)
Dim appTekla As New TSM.Model
Dim dblLen As Double
Dim dblXCen As Double
Dim dblYCen As Double
Dim dblZCen As Double
Dim objPoint1 As TSG.Point
Dim objPoint2 As TSG.Point
Dim objPoint1New As TSG.Point
Dim objPoint2New As TSG.Point
objPoint1 = objBeam.StartPoint
objPoint2 = objBeam.EndPoint
dblXCen = objPoint1.X
dblYCen = objPoint1.Y
dblZCen = (objPoint1.Z + objPoint2.Z) / 2
dblLen = ((objPoint1.X - objPoint2.X) ^ 2 + (objPoint1.Y - objPoint2.Y) ^ 2 + (objPoint1.Z - objPoint2.Z) ^ 2) ^ 0.5
objPoint1New = New TSG.Point
objPoint2New = New TSG.Point
objPoint1New.X = dblXCen
objPoint2New.X = dblXCen
objPoint1New.Y = dblYCen - dblLen / 2
objPoint2New.Y = dblYCen + dblLen / 2
objPoint1New.Z = objPoint1.Z + dblLen / 2
objPoint2New.Z = objPoint2.Z - dblLen / 2
objBeam.StartPoint = objPoint1New
objBeam.EndPoint = objPoint2New
appTekla = Nothing
End Sub


Similar to what was mentioned in the previous section, the main axis extends between the start and end points. Therefore this may not give correct results and may require an additional move command, or start and end points offsets.

You can download the sample files 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

Leave a Reply

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

Additional Info