Guides and Articles

Use this documentation when building your Tekla Structures apps

Code example: Create drawing plug-in using Windows Forms

Updated: 13 May 2019

The following steps create a basic Tekla Structures drawing plug-in that uses Windows Forms.

Unfortunately, the whole source code of this example is not available for downloading. You can copy-paste the code snippets to your own project. 


  1. In Microsoft Visual Studio, create a new project. Select Class Library(.Net framework), and enter a name for your project.

  2. Add Tekla API assemblies to your project as references.

  3. Rename Class1.cs to MainPlugin.cs (this could be a more specific name).

  4. Edit MainPlugin.cs:

    • Add directives to needed namespaces: 

      using Tekla.Structures.Datatype;
      using Tekla.Structures.Drawing;
      using Tekla.Structures.Plugins;
    • Add a method that includes attributes passed from the dialog to the plug-in. Add the lines for each attribute on the dialog. 

      Public class StructuresData

      Replace ATTRIBUTE_NAME with the name entered for the AttributeName property, VARIABLE_TYPE with a type corresponding to AttributeNameType, and VARIABLE_NAME with a suitable variable name.

    • Add the description of your plug-in: 

    • Inherit from DrawingPluginBase and add code to MainPlugin class: 

      public class MainPlugin : DrawingPluginBase
          private StructuresData _data { get; set; } 
          //StructuresData gets the data from the user interface into the plug-in 
          public MainPlugin(StructuresData data)     
              // Link to input values.
              _data = data;
          // Specify the user input needed for the plugin.
          public override List<InputDefinition> DefineInput()     
              // Define input objects.
          // This method is called upon execution and it's the main method of the plug-in.
          public override bool Run(List<InputDefinition> input)
                  // Write your code here.
              catch (Exception e)         
                  // Handle exception.
              return true;
  5. On Project menu, click Add Windows Form to add a form. Name it MainForm.cs or something specific. Design the dialog and bound the values of controls to attributes.

  6. In Mainform.cs, add event handlers for the OK and Modify buttons: 

    Private void okButton_Click(object sender, EventArgs e)
    Private void modifyButton_Click(object sender,EventArgs e)
  7. Build the project and copy the .dll file created to \TeklaStructures\[version]\nt\bin\plugins. This adds your plug-in directly to the Applications & components catalog in Tekla Structures.

  8. Run Tekla Structures, open a drawing and look for the plug-in in the Applications & components catalog.

Plug-ins won't necessarily work in other Tekla Structures versions than the one they were created for. To use a plug-in in a different version, compile it for that version.