Guides and Articles

Use this documentation when building your Tekla Structures apps

Code example: Create single rebars and stirrups (macro)

Updated: 1 Nov 2017

This example creates single bars and stirrups. The example uses some of the basic reinforcement classes.

This is a static application. If you make changes to beam size or length, the rebars are not automatically adjusted. To be able to get the reinforcement updated you need to modify it interactively or you need to delete the reinforcement and re-run the macro.

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


Set up the connection between the application and Tekla Structures

Before you can access any of the Tekla Open API objects, you need to initialize the connection between Tekla Structures and your application. This is done by creating a new instance of the Model class:

Model myModel = new Model();

Enumerate Tekla Structures model objects

In many practical applications the most fundamental user input is the users pre selection. User selects objects in the model view and runs the application which does something to or with those objects. This example enumerates all selected objects of Beam type.

ModelObjectEnumerator myEnum = myModel.GetModelObjectSelector().GetSelectedObjects();
    Beam myPart = myEnum.Current as Beam;  
    if(myPart != null)     

Manage current work plane

In most practical cases it makes sense to set the current work plane so that the geometrical calculations are straightforward. In this example you will set the work plane parallel to the beams local coordinate system. This way you can ensure that the behavior and output of the application is not dependent on the beams location or orientation in the 3D model.

Whenever the application changes the current work plane it is a good practice to restore the previous work plane set by the user.

// first store current work plane  
TransformationPlane currentPlane = myModel.GetWorkPlaneHandler().GetCurrentTransformationPlane();   

// set new work plane same as parts local coordinate system 
TransformationPlane localPlane = new TransformationPlane(myPart.GetCoordinateSystem());
// remember to restore current work plane 

Get the solid geometry data

In this example you are not concentrating on solid geometry and how it can be used in application development. For this reason, only the minimal solid data, solid boundary data will be used. However, to get the boundary corner coordinates you need a reference to the parts solid geometry data.

// get solid of part to be used for rebar point calculations 
Solid solid = myPart.GetSolid() as Solid; 

Create longitudinal reinforcement bars

In this example, you create reinforcement bars by using the SingleRebar class. This class represents single reinforcement bar in model and user interface of Tekla Structures.

  1. Create the new instance of the class and set the basic property values. This example uses hard coded values but in real applications the values are usually retrieved from some calculations or user input.
    // initialize the single rebar object to be used in longitudinal bar creation 
    SingleRebar bar = new SingleRebar(); 
    bar.Father = myPart; 
    bar.Size = "20"; 
    bar.Grade = "A500HW";
    bar.OnPlaneOffsets.Add(0.0); // please note the data type has to be 'double' 
    bar.FromPlaneOffset = 0.0; 
    bar.Name = "Longitudinal"; 
    bar.Class = 7; 
    bar.EndPointOffsetType = Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
    bar.EndPointOffsetValue = 25.0; 
    bar.StartPointOffsetType = Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
    bar.StartPointOffsetValue = 25.0;
  2. Calculate the input points for rebar shape polygon. To keep the example very simple, use the solid boundary points.
    // create longitudinal bars at four boundary corners of the solid bar #1 at "lower left" 
    bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y + 40, solid.MinimumPoint.Z + 40)); 
    bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y + 40, solid.MinimumPoint.Z + 40));
  3. Once you have the object fully defined, insert the object into model as follows. Now you have created one new reinforcement bar into Tekla Structures model.
  4. After you created the first rebar, you can re-use the same object to create three other rebars. To do this, just clear the shape polygon and add new points to it. When you have added the necessary points, call the insert method.
    // bar #2 at "lower right" 
    bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y + 40, solid.MaximumPoint.Z - 40)); 
    bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y + 40, solid.MaximumPoint.Z - 40)); 
    // bar #3 at "upper right" 
    bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y - 40, solid.MaximumPoint.Z - 40));
    bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y - 40, solid.MaximumPoint.Z - 40)); 
    // bar #4 at "upper left" 
    bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y - 40, solid.MinimumPoint.Z + 40)); 
    bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y - 40, solid.MinimumPoint.Z + 40)); bar.Insert();

Create stirrup reinforcement

  1. In principle, the creation of stirrups follows the same logic as the longitudinal bars. However, in this case use the RebarGroup class as it is the most effective way to model stirrups.
    //First, create the new instance of the class and initialize the basic properties. 
    // initialize the rebar group object for stirrup creation 
    RebarGroup stirrup = new RebarGroup(); 
    stirrup.Father = myPart; 
    stirrup.Size = "8"; 
    stirrup.Grade = "A500HW"; 
    stirrup.OnPlaneOffsets.Add(20.0);  // Note that the data type has to be 'double' 
    stirrup.FromPlaneOffset = 50; 
    stirrup.Name = "Stirrup"; 
    stirrup.Class = 4; 
    stirrup.EndPointOffsetType = Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
    stirrup.EndPointOffsetValue = 20.0; 
    stirrup.StartPointOffsetType = Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
    stirrup.StartPointOffsetValue = 20.0; 
    stirrup.StartHook.Angle = 135; 
    stirrup.StartHook.Length  = 80; 
    stirrup.StartHook.Radius = 16; 
    stirrup.StartHook.Shape = RebarHookData.RebarHookShapeEnum.HOOK_90_DEGREES; 
    stirrup.EndHook.Angle = 135; 
    stirrup.EndHook.Length = 80; 
    stirrup.EndHook.Radius = 16; 
    stirrup.EndHook.Shape = RebarHookData.RebarHookShapeEnum.HOOK_90_DEGREES;  
    // set group spacing 
    stirrup.SpacingType = Reinforcement.RebarSpacingTypeEnum.SPACING_TYPE_TARGET_SPACE;
  2. The actual shape of the stirrup and the range of the group is defined by two polygons. Create two polygons representing stirrup shapes at both ends of the group. After the new polygon is implemented add the necessary points to it.
    // set the polygon and insert stirrup into model
    Polygon polygon1 = new Polygon();
    polygon1.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y, solid.MinimumPoint.Z));
    polygon1.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y, solid.MaximumPoint.Z));
    polygon1.Points.Add(new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y, solid.MaximumPoint.Z));
    polygon1.Points.Add(new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y, solid.MinimumPoint.Z));
    polygon1.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y, solid.MinimumPoint.Z));
    Polygon polygon2 = new Polygon();
    polygon2.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y, solid.MinimumPoint.Z)); 
    polygon2.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y, solid.MaximumPoint.Z)); 
    polygon2.Points.Add(new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y, solid.MaximumPoint.Z));
    polygon2.Points.Add(new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y, solid.MinimumPoint.Z)); 
    polygon2.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y, solid.MinimumPoint.Z));
  3. After the polygons are added to the RebarGroup.Polygons array list, create the stirrup by inserting the object into Tekla Structures model.

Test example macro

You can test the macro in Tekla Structures as follows:

  1. Copy the file RebarSample1B.cs  located at \Examples\Model\Applications\RebarExamples\macro to \Tekla Structures\[Version]\Enviroments\common\macros\modeling to add the macro to Applications & components Catalog.

  2. In Teka Structures, open a model.

  3. Create some rectangular beams.

  4. Select the beams in model view.

  5. Open Applications & components Catalog (Ctrl+F) and  search for component RebarSample1B.
  6. Double-click the component in the catalog and select a beam in the model.


The result should look something like this:

Tekla Structures Open API code example create single rebars and stirrups macro
The application is not able to manage the end notches in any way because of the very simple geometry handling.