Skip to content

Examples

Each example shows the few changes a project needs for usage tracking. They build with the solution and use the library projects of this repo. A real project references the NuGet package instead (see Releasing).

Example Type Changes for tracking
ModelPluginExample Tekla model plugin with a WinForms dialog Run’s body in TeklaTracking.Run, TeklaTracking.TrackDialog(this) in the form; a custom event (beam_created)
DrawingPluginExample Tekla drawing plugin with a WPF dialog Run’s body in TeklaTracking.Run, TeklaTracking.TrackDialog(this) in the window
WinFormsToolExample standalone WinForms tool none; a custom event (export_done) and an error button
WpfToolExample standalone WPF tool none; a custom event (report_created) and an error button

Every example also has a plugboard-tracking.json next to its project file. They all use C# 9 or later, from the repo’s Directory.Build.props.

  1. Add the package: Plugboard.Tracking.Tekla for a Tekla plugin, Plugboard.Tracking.Core for a standalone tool.
  2. Build once. plugboard-tracking.json is created next to the project file; fill in endpoint and apiKey.
  3. .NET Framework projects: add <LangVersion>9.0</LangVersion> (or later) to the project file.
  4. Tekla plugins: change the base classes as in the table above.
  5. Build and run. The events appear on the dashboard within flushIntervalSeconds (30 s), and the first batch goes out after 5 s.

The examples’ plugboard-tracking.json point at https://your-app.example/api/usage-events, which doesn’t exist. Put your test tenant’s endpoint and API key in a plugboard-tracking.override.json next to the built DLL or EXE, so you don’t have to edit the example:

{ "endpoint": "https://your-server/api/usage-events", "apiKey": "aut_your_test_key" }

To try a plugin example, copy its build output to a Tekla Structures extension folder (e.g. C:\ProgramData\Trimble\Tekla Structures\<version>\Environments\common\extensions\), start Tekla and run the plugin from the Applications & components catalog.

Without a reachable endpoint, the events are kept in %LocalAppData%\AT Solutions\Plugboard.Tracking\queue\ and sent on a later start, and the log %LocalAppData%\AT Solutions\Plugboard.Tracking\logs\plugboard-tracking.log says why.

The code of the example projects, as it is in the repository.

examples/ModelPluginExample/BeamPlugin.cs
using System.Collections.Generic;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Model;
using Tekla.Structures.Model.UI;
using Tekla.Structures.Plugins;
using Plugboard.Tracking;
using Plugboard.Tracking.Tekla;
namespace ModelPluginExample;
/// <summary>What the user enters in the dialog. Sent with run events when <c>pluginData.enabled</c> is on.</summary>
public class BeamPluginData
{
[StructuresField("profile")] public string Profile = "";
[StructuresField("material")] public string Material = "";
[StructuresField("comment")] public string Comment = ""; // left out by "excludeFields" in plugboard-tracking.json
}
/// <summary>Creates a beam between two picked points.</summary>
[Plugin("PlugboardTrackingBeamExample")]
[PluginUserInterface("ModelPluginExample.BeamPluginForm")]
public class BeamPlugin : PluginBase // stays PluginBase: Tekla only finds plugins that inherit it directly
{
private readonly BeamPluginData _data;
public BeamPlugin(BeamPluginData data)
{
_data = data;
}
public override List<InputDefinition> DefineInput()
{
var picker = new Picker();
var points = picker.PickPoints(Picker.PickPointEnum.PICK_TWO_POINTS, "Pick the beam's start and end point");
return new List<InputDefinition> { new((Point)points[0], (Point)points[1]) };
}
// The only change for usage tracking: Run's body goes into TeklaTracking.Run.
// plugin_run_started / plugin_run_completed (duration, success, exception, plugin data) are sent around it.
public override bool Run(List<InputDefinition> Input) => TeklaTracking.Run(this, Input, () =>
{
var points = (System.Collections.ArrayList)Input[0].GetInput();
var beam = new Beam((Point)points[0], (Point)points[1])
{
Profile = { ProfileString = IsDefaultValue(_data.Profile) ? "HEA300" : _data.Profile },
Material = { MaterialString = IsDefaultValue(_data.Material) ? "S355" : _data.Material },
};
var created = beam.Insert();
// A custom event, next to the automatic ones.
PlugboardTracker.Track("beam_created", new { profile = beam.Profile.ProfileString });
return created;
});
}
examples/ModelPluginExample/BeamPluginForm.cs
using System;
using System.Windows.Forms;
using Tekla.Structures.Dialog;
using Tekla.Structures.Dialog.UIControls;
using Plugboard.Tracking.Tekla;
namespace ModelPluginExample;
/// <summary>
/// The plugin dialog. form_opened, form_closed and button_clicked (including Tekla's OK / Apply / Modify /
/// Get / On/Off / Cancel buttons) are sent automatically; what's typed into the text boxes never is.
/// </summary>
public class BeamPluginForm : PluginFormBase // stays PluginFormBase: Tekla only loads dialogs that inherit it directly
{
public BeamPluginForm()
{
TeklaTracking.TrackDialog(this); // the only change for usage tracking
Text = "Beam (usage tracking example)";
Width = 420;
Height = 220;
var profile = new TextBox { Name = "profileTextBox", Left = 120, Top = 16, Width = 260 };
var material = new TextBox { Name = "materialTextBox", Left = 120, Top = 48, Width = 260 };
Controls.Add(new Label { Text = "Profile", Left = 16, Top = 20 });
Controls.Add(profile);
Controls.Add(new Label { Text = "Material", Left = 16, Top = 52 });
Controls.Add(material);
// Tekla's attribute binding: the text boxes edit the plugin data fields with these names.
structuresExtender.SetAttributeName(profile, "profile");
structuresExtender.SetAttributeName(material, "material");
var buttons = new OkApplyModifyGetOnOffCancel { Dock = DockStyle.Bottom };
buttons.OkClicked += (_, _) => { Apply(); Close(); };
buttons.ApplyClicked += (_, _) => Apply();
buttons.ModifyClicked += (_, _) => Modify();
buttons.GetClicked += (_, _) => Get();
buttons.OnOffClicked += (_, _) => ToggleSelection();
buttons.CancelClicked += (_, _) => Close();
Controls.Add(buttons);
}
}
examples/ModelPluginExample/plugboard-tracking.json
{
"endpoint": "http://localhost/api/usage-events",
"apiKey": "aut_u0z7L39LdGbchF3HKWlBZ3gjRBKcVnLNa4plRtNPft2KPVG2",
"toolName": "Example Model Plugin",
"events": {
"plugin_loaded": true,
"plugin_run_started": true,
"plugin_run_completed": true,
"application_started": true,
"application_closed": true,
"form_opened": true,
"form_closed": true,
"button_clicked": true,
"unhandled_exception": true,
"update_notified": true,
"update_download_clicked": true,
"update_skipped": true,
"custom": true,
"customAllowList": [],
"customDenyList": []
},
"pluginData": {
"enabled": true,
"excludeFields": [ "Comment" ]
},
"updates": {
"enabled": true,
"checkIntervalHours": 24
},
"includeButtons": [],
"excludeButtons": [ "btnDebug*" ]
}
examples/DrawingPluginExample/NotePlugin.cs
using System.Collections.Generic;
using Tekla.Structures.Drawing;
using Tekla.Structures.Drawing.Tools;
using Tekla.Structures.Drawing.UI;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Plugins;
using Plugboard.Tracking.Tekla;
namespace DrawingPluginExample;
public class NotePluginData
{
[StructuresField("note")] public string Note = "";
}
/// <summary>Writes a note at a picked point of a drawing view.</summary>
[Plugin("PlugboardTrackingNoteExample")]
[PluginUserInterface("DrawingPluginExample.NoteWindow")]
public class NotePlugin : DrawingPluginBase // stays DrawingPluginBase: Tekla only finds plugins that inherit it directly
{
private readonly NotePluginData _data;
public NotePlugin(NotePluginData data)
{
_data = data;
}
public override List<InputDefinition> DefineInput()
{
var picker = new DrawingHandler().GetPicker();
var picked = picker.PickPoint("Pick the note's position");
return new List<InputDefinition> { InputDefinitionFactory.CreateInputDefinition(picked.Item2, picked.Item1) };
}
// The only change for usage tracking: Run's body goes into TeklaTracking.Run.
public override bool Run(List<InputDefinition> InputDefinitions) => TeklaTracking.Run(this, InputDefinitions, () =>
{
var input = InputDefinitions;
var view = InputDefinitionFactory.GetView(InputDefinitions[0]) as View;
var point = InputDefinitionFactory.GetPoint(InputDefinitions[0]);
if (view is null)
{
return false;
}
var text = new Text(view, point, IsDefaultValue(_data.Note) ? "Note" : _data.Note);
return text.Insert();
});
}
examples/DrawingPluginExample/NoteWindow.xaml.cs
using System;
using System.ComponentModel;
using Tekla.Structures.Dialog;
using Plugboard.Tracking.Tekla;
namespace DrawingPluginExample;
public partial class NoteWindow // base class: PluginWindowBase (in NoteWindow.xaml)
{
public NoteWindow()
{
InitializeComponent();
TeklaTracking.TrackDialog(this); // the only change for usage tracking
DataContext = new NoteViewModel();
}
private void OnOk(object sender, EventArgs e) { Apply(); Close(); }
private void OnApply(object sender, EventArgs e) => Apply();
private void OnModify(object sender, EventArgs e) => Modify();
private void OnGet(object sender, EventArgs e) => Get();
private void OnOnOff(object sender, EventArgs e) => ToggleSelection();
private void OnCancel(object sender, EventArgs e) => Close();
}
/// <summary>The dialog's data, bound to the plugin data field "note".</summary>
public class NoteViewModel : INotifyPropertyChanged
{
private string _note = "";
public event PropertyChangedEventHandler? PropertyChanged;
[StructuresDialog("note", typeof(Tekla.Structures.Datatype.String))]
public string Note
{
get => _note;
set
{
_note = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Note)));
}
}
}
examples/WinFormsToolExample/Program.cs
using System;
using System.Windows.Forms;
namespace WinFormsToolExample;
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ExportForm());
}
}
examples/WpfToolExample/App.xaml.cs
namespace WpfToolExample;
public partial class App
{
}