Code example: Create beam using two points

Updated: 13 May 2019

This Tekla Open API code example shows in detail how to create a very simple .NET application. Application uses Model API to create a beam in a Tekla Structures model. You will insert beam between two points using a button in a form.

After downloading the TSOpenAPIExamples package from GitHub (button above), find BeamApplication example at Model\Applications\BeamApplication.

Add button to application form

Before you start, create a new .NET application project. The project automatically includes a form, which you can modify.

  1. Open the Form1.cs[Design] tab.

  2. Click Toolbox on the View menu.

  3. On the Toolbox tab, in the All Windows Forms group, double-click Button.

  4. Place the button on the form.

  5. Double-click the button to open the code for its Click event.Starting point of coding application to Tekla Structures model using Tekla Open API

  6. In Solution Explorer, right-click on the References node and choose Add Reference. Add references to Tekla.Structures and Tekla.Structures.Model.

  7. Copy these using directive lines to your code: 

    using Tekla.Structures.Model;
    ​using TSG = Tekla.Structures.Geometry3d; 

Add code to click event

Copy the following code to your click event:

private void button1_Click(object sender, EventArgs e)
    // Create a new Model object that represents the Tekla Structures Model you have opened in Tekla Structures.
    Model myModel = new Model();

    // Check if we have a Tekla Structures Model that you can connect to.
    if (myModel.GetConnectionStatus())
        // Create a new instance of the Beam class based on created start and end points for the beam.
        Beam myBeam = new Beam(new TSG.Point(1000, 1000, 1000), new TSG.Point(6000, 6000, 1000));

        // Set the Beams Material and Profile.
        myBeam.Material.MaterialString = "S235JR";
        myBeam.Profile.ProfileString = "HEA400";

        // Insert the Beam into the Tekla Structures Model.

        //Make sure all changes that have been done are updated in Tekla Structures and that the model views are redrawn 

Run you application inside the Microsoft Visual Studio

  1. Start Tekla Structures.
  2. In Tekla Structures, open an empty model.
  3. Now, run you code inside Microsoft Visual studio by clicking Start toolbar button. 
  4. Microsoft Visual Studio runs your program, and a window called Form1 appears:Create beam form Tekla Open API code example
  5. Click button1 button. Tekla Structures creates a new Beam object to your model between the two points defined in the code.

Tekla Open API application created a beam to Tekla Structures model

Download and run the example application

  1. Get the full source code of this example by clicking Get code on top of this guide.

  2. Start Tekla Structures.

  3. In Tekla Structures, open an empty model.

  4. In Microsoft Visual Studio, open  BeamApplication.csproj to create the application file. The file is located at \Examples\Model\Applications\BeamApplication.

  5. Run the application BeamApplication.exe located at \Examples\Model\Applications\BeamApplication\bin\Debug.

  6. Click BeamButton.


The result should look like this:

Tekla structures Open API create a beam using two points

Was this helpful?
The feedback you give here is not visible to other users. We use your comments to improve the content.