Check the connection between the application and Tekla Structures

Updated: 17 Sep 2024

Before you can access any of the Tekla Open API objects, you will need to initialize the connection between Tekla Structures and your application.

Because applications are not started together with Tekla Structures they cannot expect to have Tekla Structures running upon execution.

This is one way of checking if the Tekla Structures is running and a model is open.

// Create a new instance of class Tekla.Structures.Model: 
Model myModel = new Model();

// Check that the model connection succeeded:
if (myModel.GetConnectionStatus()) 
{ 
    …
}

NOTE: It is recommended to copy applications in a subfolder inside the Tekla Structures Extension folder. Each version of Tekla Structures uses a different folder. For example, the default Extension folder of Tekla Structures 2024 is here:

C:\ProgramData\Trimble\Tekla Structures\2024.0\Environments\common\extensions\

Starting with Tekla Structures 2024, developers testing applications from the Microsoft Visual Studio should read this guide to get more information:

Gacless Tekla Structures 2024 - Developer Impact

Debug application when using Tekla Open API 2024

When creating a new application with Tekla Open API 2024 (Console application or with UI), it is possible a connection error is found if the developer only follows these steps in Visual Studio: Create a new application (4.8 .NET Framework), Add nuget packages of Tekla Open API 2024, Build and start to debug the application. The connection error looks something like the image below

Open API 2024 Connection Error

This document describes one possible way of avoiding that connection error and create/debug applications that use Tekla Open API 2024.

First of all, you can create/prepare one folder where to store all Visual Studio projects that will use Tekla Open API 2024. For example in this location: C:\Users\<MyUserName>\source\repos\2024

And in this folder, you copy the Directory.Build.Props file attached to this document, it will be used later on to create correct exe.config files for the applications. To get this file, you can use the blue Download button visible on the top part of this page, just below the title and date of this document. 

Visual Studio Projects Folder

Once the folder is ready, you don't need to modify the Directory.Build.Props file anymore. Keep reading to see what to do when creating new tools with Open API 2024.

The next steps must be followed every time when creating new applications that use Tekla Open API 2024.

- Open Visual Studio normally and select the .NET Framework 4.8 application type you want to create (it can be a Console app, Windows Forms App or WPF App). Always make sure you select the .NET Framework application.

- Make sure the .NET Framework version is 4.8 or higher, and the project Location will be the folder you created before, where the Directory.Build.Props file is located.

Visual Studio UI

- Use Tools/NuGet Package Manager to add the Tekla Open API libraries you will need in your project. For example, Tekla.Structures.Model. Like you have probably done before when working with older versions of Tekla Open API.

- Now, use NuGet Package Manager to add this additional package: TSAppConfigPatcherTask. The role of this library is to create the correct exe.config file for the application automatically, which will be used when debugging the tool.

Nuget TSAppConfigPatcherTask

After these steps, write code with Tekla Open API 2024 and the application will connect with Tekla Structures 2024, and it will also be possible to debug the code. 

FAQ: Do I need to make any additional steps when deploying applications to customer computers?

No. If applications are copied to the Tekla Structures extension folder (for example: C:\ProgramData\Trimble\Tekla Structures\2024.0\Environments\common\extensions\MyTest\ ), the correct exe.config files are created automatically when TeklaStructures starts. Thanks to these correct exe.config files, the Tekla Open API 2024 applications will connect with the Tekla Structures 2024 process.

 

Was this helpful?
The feedback you give here is not visible to other users. We use your comments to improve the content.