Guides and Articles

Use this documentation when building your Tekla Structures apps

Code example: Create single rebars and stirrups (application)

Updated: 29 Jun 2018

This Tekla Open API example creates single bars and stirrups. It is a static application that uses some of the basic reinforcement classes.

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 application.

See also Code example: Create single rebars and strirrups using system connections (application).

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

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 user selection. User selects objects in the model view and runs the application which does something to or with those objects. In this example you enumerate all selected objects of Beam type.

ModelObjectEnumerator myEnum = myModel.GetModelObjectSelector().GetSelectedObjects();
while(myEnum.MoveNext())
{    
    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());
myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(localPlane);
 .
 .
 .
// remember to restore current work plane 
myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);

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 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); // 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.
    bar.Insert();
  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.Clear(); 
    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.Insert();   
    // bar #3 at "upper right" 
    bar.Polygon.Points.Clear(); 
    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.Insert();   
    // bar #4 at "upper left" 
    bar.Polygon.Points.Clear(); 
    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.RadiusValues.Add(16.0); 
    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.Spacings.Add(250.0); 
    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.
    stirrup.Polygons.Add(polygon1); 
    stirrup.Polygons.Add(polygon2); 
    stirrup.Insert();

Test example application

You can test the application in Tekla Structures as follows:

  1. In Tekla Structures, open a model.

  2. Create some rectangular beams.

  3. Select the beams in model view.

  4. Open an build RebarSample1.csproj In Microsoft Visual Studio to create the application file. The file is located at \Examples\Model\Applications\RebarExamples\RebarSample1.

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

 

The result should look something like this:

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