Code example: Create beam using user input

Updated: 13 May 2019

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


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. On the Toolbox tab, select All Windows Forms group, double-click Button.

  3. Place the button on the form.

  4. Double-click the button to open the code for its Click event.

Unfortunately, the whole source code of this example is not available for downloading. Please copy-paste the following code snippet to your project.

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 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 from the Picker class.
        Tekla.Structures.Model.UI.Picker _picker = new Tekla.Structures.Model.UI.Picker();

        // Create the two points that will be used as the start and end point for the beam from user input.
        TSG.Point startPoint = _picker.PickPoint("Pick the startpoint");
        TSG.Point endPoint = _picker.PickPoint("Pick the endpoint");

        // Create a new instance of the Beam class based on the two input points.
        Beam myBeam = new Beam(startPoint, endPoint);

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

        // 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 accordingly.

Test beam creation application

  1. In Tekla Structures, open an empty model.

  2. In Microsoft Visual Studio, on the Debug menu, click Start to run the application.

  3. Click button1.

  4. In Tekla Structures, pick a start point and a end point for the beam.


 The result should look similar to this:

Tekla structures model Open API create a beam using user input

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