Code example: Custom property plug-in
Custom property plug-ins are programmed tools for calculating template values used in reporting and drawings. The following steps create a basic custom property plug-in that uses Windows Forms.
After downloading the TSOpenAPIExamples package from GitHub (button above), find CustomPropertyTest example at \CustomProperties\CustomPropertyTest.
Create a basic custom property plug-in
In Microsoft Visual Studio, create a new project. Select Class Library(.Net framework) as template and enter a name for your project.
Rename Class1.cs to CustomProperty.cs (this could be a more specific name). Edit CustomProperty.cs:
Add assemblies needed:
using System.ComponentModel.Composition; // only 2024 and older versions using Tekla.Structures.Model; using Tekla.Structures.CustomPropertyPlugin;In TeklaStructures 2024 and older versions Custom property functionality is using Managed Extensibility Framework (MEF) for loading custom property assemblies, therefore a reference to System.ComponentModel.Composition assembly is needed in the project.
Starting in TeklaStructures 2025 loading custom property assemblies only need Open API libraries.
Define needed metadata for custom property:
// only 2024 and older versions [Export(typeof(ICustomPropertyPlugin))] [ExportMetadata("CustomProperty", "CUSTOM.NAME_OF_THE_PROPERTY")] // available from TeklaStructures 2025 [CustomPropertyPlugin("CUSTOM.NAME_OF_THE_PROPERTY")]Implement the ICustomPropertyPlugin interface:
//Methods in the interface are passing object ID as argument. //Identifier of the object can be constructed using the ID in order to utilize //the functionality in Tekla.Structures.Model assembly. public class CustomPropertyTest : ICustomPropertyPlugin { //Return custom property int value for object. public int GetIntegerProperty(int objectId) { return -1 * objectId; } //Return string value for object. public string GetStringProperty(int objectId) { return "Hello " + objectId.ToString(); } //Return double value for object. public double GetDoubleProperty(int objectId) { return (double)(-1 * objectId); } }
Test example application
- In Microsoft Visual Studio, open and build project CustomProperty.cs to create the .dll file. The file is located at \Examples\CustomProperties\CustomPropertyTest.
- Copy the custom property .dll file to \environments\common\extensions\custom\properties\. (Create the \custom\properties\ folder if needed, inside the location where your common environment is located after installing Tekla Structures).
- Check if the plug-in loads:
- Open a model in Tekla Structures, on the File menu, click Logs and select session history log. From the list you can see if your plug-in has loaded.