Code example: Create model plug-in using Windows Forms
The following steps create a basic Tekla Structures model plug-in that uses Windows Forms.
-
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 MainPlugin.cs (this could be a more specific name).
-
Edit MainPlugin.cs:
-
Add assemblies needed:
using TSDatatype = Tekla.Structures.Datatype; using TSModel = Tekla.Structures.Model; using TSPlugins = 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 PluginBase and add code to MainPlugin class:
public class MainPlugin : TSPlugins.PluginBase { // Enable inserting of objects in a model private readonly TSModel.Model _model; public TSModel.Model Model { get { return _model; } } // Enable retrieving of input values private readonly StructuresData _data; public MainPlugin(StructuresData data) { // Link to model. _model = new TSModel.Model(true); // 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 of the plug-in 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) { MessageBox.Show(e.ToString()); } 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 and look for the plug-in in the Applications & components catalog.