Code example: Create beam using user input
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.
-
Open the Form1.cs[Design] tab.
-
On the Toolbox tab, select All Windows Forms group, double-click Button.
-
Place the button on the form.
-
Double-click the button to open the code for its Click event.
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.
myBeam.Insert();
//Make sure all changes that have been done are updated in Tekla Structures and that the model
//views are redrawn accordingly.
myModel.CommitChanges();
}
}
Test beam creation application
-
In Tekla Structures, open an empty model.
-
In Microsoft Visual Studio, on the Debug menu, click Start to run the application.
-
Click button1.
-
In Tekla Structures, pick a start point and a end point for the beam.
The result should look similar to this: