Code example: Create drawing plug-in using Windows Forms
The following steps create a basic Tekla Structures drawing plug-in that uses Windows Forms.
-
In Microsoft Visual Studio, create a new project. Select Class Library(.Net framework), and enter a name for your project.
-
Rename Class1.cs to MainPlugin.cs (this could be a more specific name).
-
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 { [TSPlugins.StructuresField("ATTRIBUTE_NAME")] public VARIABLE_TYPE VARIABLE_NAME; }
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:
[TSPlugins.Plugin("FormPlugin")] [TSPlugins.PluginUserInterface("FormPlugin.MainForm")]
-
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) { try { // Write your code here. } catch (Exception e) { // Handle exception. } return true; } }
-
-
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.
-
In Mainform.cs, add event handlers for the OK and Modify buttons:
Private void okButton_Click(object sender, EventArgs e) { this.Apply(); this.Close(); } Private void modifyButton_Click(object sender,EventArgs e) { this.Modify(); }
-
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.
-
Run Tekla Structures, open a drawing and look for the plug-in in the Applications & components catalog.