Guides and Articles

Use this documentation when building your Tekla Structures apps

Code example: Create single rebars and stirrups using system connections (plug-in)

Updated: 13 May 2019

This Tekla Open API example creates single bars and stirrups using system connections.

The basic structure of the application is the same as in Code example: Create single rebars and stirrups using system connections (application) with a few additions which are typical to plug-ins, like default value handling. Also, the management of number of bars at bottom/top has been added.

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

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

Declare class to manage plug-in component properties

Declare a new class that contains the properties you need for your plug-in. These properties will be stored in Tekla Structures model with every instance of the plug-in component. By including the specific meta code statements, you can define the names for those properties as they appear in Tekla Structures model.

public class StructuresData  
{   
    [Tekla.Structures.Plugins.StructuresField("bottom_number")] 
    public int BottomNumber;  
    [Tekla.Structures.Plugins.StructuresField("top_number")]
    public int TopNumber; 
}

This example only has two properties which control the number of bars at top and bottom.

Name plug-in in Applications & components catalog

Every plug-in component has a unique name in Tekla Structures Applications & component catalog. Define this name by following the meta code statement. Together with the plug-in component name you have to define the container variable for the user interface.

[Plugin("RebarPluginSample")] 
[PluginUserInterface(RebarPluginSample.UserInterfaceDefinitions.dialog)] 

Declare plug-in class

To declare the actual plug-in class, derive the class from virtual PluginBase class.

public class RebarPluginSample: PluginBase
{ 
    private StructuresData data;     
    .
    .

Declare the plug-in class that implements the virtual constructor which is taking its parameter as an object of class StructuresData:

public RebarPluginSample(StructuresData data)  
{
    this.data = data; 
}

Define input

This plug-in component defines its input sequence by overriding the method DefineInput(). In this method, collect the input by using the Picker class and its various methods. Add the input into an ArrayList to be returned as result of the method.

// this is called by Tekla Structures when the command is started 
public override List<InputDefinition> DefineInput() 
{     
    Picker  picker = new Picker(); 
    List<InputDefinition> inputList = new List<InputDefinition>();  

    ModelObject o1 = picker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART); 

    InputDefinition input1 = new InputDefinition(o1.Identifier); 

    inputList.Add(input1);       

    return inputList; 
}

Introduce and define user interface

Since this plug-in component has properties, you need to define the property dialog for it. This is done by defining the static string variable that holds the user interface definition (.inp code) with a meta code statement. The definition is based on same inp-format as the dialogs of custom components.

[PluginUserInterface(RebarPluginSample.UserInterfaceDefinitions.dialog)] 
 
// this is a nested class containing the UI definition for plug-in component 
// the format for UI definition is same as for custom components 
public class UserInterfaceDefinitions
{ 
    public const string dialog = 
    @"page(""TeklaStructures"","""")
    {        
        plugin(1, ""RebarPluginSample"")      
        {     
            tab_page("""", ""Parameters 1"", 1)
            {            
                parameter(""Number of bottom bars"", ""bottom_number"", integer, number, 1)
                parameter(""Number of top bars"", ""top_number"", integer, number, 4)
            }                 
            depend(2)
            modify(1)
            draw(1, 100.0, 100.0, 0.0, 0.0)
        }
    }";
}

Implement the Run() method

The main method of the plug-in is the overridden Run() method.

// this is called by TS when the component is created or modified
public override bool Run(ArrayList Input)  
{
 . . . 

}

This method uses the Tekla Open API to create the reinforcement in similar way as in the application example. However, there are certain differences because of how plug-ins work.
There is no enumeration of selection. The reason for this is that the part to be reinforced is given as input for the plug-in and you can get the reference to part by simply selecting it with the identifier you get from the input.

Identifier id = ((InputDefinition)Input[0]).GetInput() as Identifier;
Part myPart = myModel.SelectModelObject(id) as Part;

Handle default values

To add properties for you plug-in you need to take care of the default value handling. In Tekla Structures it is possible to leave the input empty with the intention that the plug-in or system component is expected to choose the value based on its best knowledge.


In simple cases the plug-in can use some fixed value but in general it will be somehow dependent on input objects. For example in this case the number of bars are dependent on the properties of the beam. This example uses a simple method with fixed values.

// Calculate final values for input properties which have default (=empty) input values.
if(IsDefaultValue(data.BottomNumber))
    data.BottomNumber = 6;
if(IsDefaultValue(data.TopNumber)) 
    data.TopNumber = 2;

Test example plug-in

  1. In Microsoft Visual Studio, build the project RebarSample3.csproj. The file is located at \Examples\Model\Applications\RebarExamples\RebarSample3.
  2. Copy the created .dll file to \TeklaStructures\[version]\nt\bin\plugins. This adds your plug-in directly to the  Applications & components catalog in Tekla Structures.
  3. In Tekla Structures, open a model.
  4. Create some rectangular beams.
  5. Open Applications and components catalog (Ctrl+F) and  search for component RebarPluginSample.
  6. Click the component in the catalog and pick beam in the model view.

 

The result should look something like this:
Tekla Structures Open API code example create single rebars and stirrups system connections

 

Was this helpful?
The feedback you give here is not visible to other users. We use your comments to improve the content.