The ITeklaExtension interface is designed for developing extensions in Tekla Structures, a powerful modeling software for the construction industry. While many concepts from the more general IAssistantExtension guide still apply, there are key differences specific to Tekla extensions.
To delve into the process of creating .NET extensions for Tekla Structures, you can refer to the Assistant .NET Extension Development Guide. The foundational knowledge presented there can be adapted to Tekla extensions.
A TeklaAppExtension template that enables users to create fully interactive, MVVM-based Tekla Extensions with a modern WPF UI is available. This template provides a foundation for building rich, user-friendly applications with support for data binding, command patterns, and seamless UI interactions. For a detailed guide on developing Tekla App Extensions, please refer to the Tekla App Extension .NET Extension Development Guide
Understanding the core distinctions between Tekla extensions and general Assistant extensions is crucial:
Tekla Model Interaction: The ITeklaExtension is tailored for interaction with Tekla Structures models. In your extension's implementation, you can work with the Tekla model, gather information, and perform tasks relevant to the construction domain.
Tekla Context: The TeklaExtensionContext provides a context specific to Tekla extensions.
Here's a basic example of an ITeklaExtension:
public class TeklaExtensionCommand : ITeklaExtension<TeklaExtensionArgs>
{
public IExtensionResult Run(ITeklaExtensionContext context, TeklaExtensionArgs args, CancellationToken cancellationToken)
{
// The Model class represents a single model open in Tekla Structures.
// Before interaction with the model, the user will have to create one
// instance of this class.
var model = new Model();
if (!model.GetConnectionStatus())
return Result.Text.Failed("Tekla has no active model open");
// The ModelHandler class provides information about the currently open Tekla Structures model.
var modelHandler = new ModelHandler();
// Get selected objects in the model
var selectedObjects = new Tekla.Structures.Model.UI.ModelObjectSelector().GetSelectedObjects();
// Create a message with the input text
var message = $"Input = {args.TextInput}";
// Return a result with the message
return Result.Text.Succeeded(message);
}
}
This sample implementation showcases the use of the ITeklaExtension to interact with a Tekla Structures model.
For a more comprehensive understanding, please refer to the Assistant .NET Extension Development Guide, adapting the principles for your Tekla extensions.
The [CustomTeklaAutoFill] attribute enables you to implement custom logic for collecting items, particularly for Tekla extension types. This attribute is used when defining Tekla extension arguments and specifying custom autofill collectors for those arguments.
Here's an example of how to use CustomTeklaAutoFill:
[CustomTeklaAutoFill(typeof(ControlNameAutoFillCollector))]
public string ControlName { get; set; }
internal class ControlNameAutoFillCollector : ITeklaAutoFillCollector<TeklaExtensionArgs>
{
public Dictionary<string, string> Get(TeklaExtensionArgs args)
{
var result = new Dictionary<string, string>();
try
{
var model = new Model();
if (!model.GetConnectionStatus()) return result;
// Implement your custom logic here to populate the result dictionary
result.Add("Item1", "Value1");
result.Add("Item2", "Value2");
result.Add("Item3", "Value3");
}
catch { }
return result;
}
}
In this example, the ControlName property within the TeklaExtensionArgs class is marked with the [CustomTeklaAutoFill] attribute. This attribute specifies that a custom autofill collector (ControlNameAutoFillCollector) should be used for the ControlName property.
The ControlNameAutoFillCollector class implements the ITeklaAutoFillCollector<TeklaExtensionArgs> interface, providing custom autofill data for the ControlName property. You can customize the logic within the Get method to populate the result dictionary based on your specific requirements.
The custom autofill collector can access the Tekla environment or any external data source to provide autofill values, which can be used within your Tekla extension.