Guides and Articles

Use this documentation when building your Tekla Structures apps

Code example: Create single rebars and stirrups using system connections (macro)

Updated: 1 Nov 2017

This example creates single bars and stirrups using system connections. This example uses two simple system components. With the help of these components you can increase the intelligence of the application due to their ability to manage notches and openings in the part.

The basic structure of the application is the same as in Code example: Create single stirrups rebars and stirrups (macro).

This is also a static macro. However, unlike basic reinforcement objects the components add some intelligence into the model. For example, adding or deleting the notches at beam ends will cause the components to be updated and the reinforcement adjusted.

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

The next paragraphs go through parts of the program code which are different from the previous example.

 

Use system component to create longitudinal bars

  1. Create new instance of the class Component
    // initialize the component used to model longitudinal bars 
    Component component1 = new Component(); 
    component1.Number = 30000070;  // unique number for "longitudinal rebars" component
  2. Initialize the objects properties. For components you can use the "save as" files and load the base values for all properties and only set the necessary values explicitly. 
    // manage the settings i.e. load standard defaults and set the few important attribute values explicitly
    component1.LoadAttributesFromFile("standard"); 
    component1.SetAttribute("bar1_no", 4);      // number of bars 
    component1.SetAttribute("cc_side", 45.0);   // cover thickness at side 
    component1.SetAttribute("cc_bottom", 45.0); // cover thickness at bottom
  3. Set up the input for the component. The input sequence shall be same as the input when the component is applied interactively. In this case the input contains the part and three points. Point class is included to Tekla.Structures.Geometry3d namespace. 
    // prepare input points for the "longitudinal rebars" component
    Point p1 = new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y, solid.MaximumPoint.Z); 
    Point p2 = new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y, solid.MaximumPoint.Z); 
    Point p3 = new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y, solid.MinimumPoint.Z);
    
    // set up component input sequence 
    ComponentInput input1 = new ComponentInput(); 
    input1.AddInputObject(myPart); 
    input1.AddTwoInputPositions(p1, p2); 
    input1.AddOneInputPosition(p3);   
    
    // Add the input for component  
    component1.AddComponentInput(input1);
  4. Insert the component into Tekla Structures model. 

    // insert new component instance into model 
    component1.Insert();

Test example macro

You can test the macro in Tekla Structures as follows:

  1. Copy the file RebarSample2B.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 Tekla 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 RebarSample2B.
  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 system connections
The application is able to recognize the notches at beam end which causes the longitudinal bar at the bottom being shorter like the stirrup range.