Code example: Create beam using two points
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.
-
Open the Form1.cs[Design] tab.
-
Click Toolbox on the View menu.
-
On the Toolbox tab, in the 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.
-
In Solution Explorer, right-click on the References node and choose Add Reference. Add references to Tekla.Structures and Tekla.Structures.Model.
-
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.
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();
}
}
Run you application inside the Microsoft Visual Studio
- Start Tekla Structures.
- In Tekla Structures, open an empty model.
- Now, run you code inside Microsoft Visual studio by clicking Start toolbar button.
- Microsoft Visual Studio runs your program, and a window called Form1 appears:
- Click button1 button. Tekla Structures creates a new Beam object to your model between the two points defined in the code.
Download and run the example application
-
Get the full source code of this example by clicking Get code on top of this guide.
-
Start Tekla Structures.
-
In Tekla Structures, open an empty model.
-
In Microsoft Visual Studio, open BeamApplication.csproj to create the application file. The file is located at \Examples\Model\Applications\BeamApplication.
-
Run the application BeamApplication.exe located at \Examples\Model\Applications\BeamApplication\bin\Debug.
-
Click BeamButton.
The result should look like this: