What is Tekla Open API? A guide for detailers and engineers

Tekla Open API is the C# library that lets your own program read and change a Tekla Structures model while Tekla is running. A part’s profile, a UDA on a wall panel, the rebars in a hollow-core slab, a drawing’s revision: if Tekla stores it, code can usually reach it.

My first Open API code, about ten years ago, was for rebars in precast elements. It was a repetitive job at work, the same steps on every element, and I wanted it gone. Most people start the same way: not with a plan to become a developer, but with one chore they’re tired of.

A C# library that talks to the Tekla on your PC

It isn’t a web API, and it isn’t a scripting language of its own. It’s a set of .NET assemblies: Tekla.Structures.Model for the model, Tekla.Structures.Drawing for drawings, Tekla.Structures.Plugins for plug-ins, and a few more. You get them from NuGet as Tekla.Structures.* packages, write C# on .NET Framework 4.8, and your code connects to the Tekla that’s open on the same machine. There’s no separate licence to buy: the Open API comes with Tekla Structures. Python can reach it too, through pythonnet, but it fails just as quietly when the runtime or the DLLs are wrong.

Two things follow from that, and both catch beginners. Tekla has to be running with a model open. And the package version has to be the Tekla version: 2024 packages for Tekla 2024. Get either one wrong and nothing crashes. The connection check returns false and the tool does nothing. The 2024 upgrade post has the rest of the version rules.

Macro, app or plug-in: four kinds of tool on one API

KindWhere it runsPick it whenA precast example
Macro (.cs)Inside Tekla, compiled when you run itA one-off command you want to share as a single fileLock every element in a released phase
Standalone app (.exe)Its own window, connected to TeklaA bigger tool: its own UI, files, other softwareA take-off that writes volumes and weights to Excel
Plug-in (.dll)Inside Tekla, re-run when its inputs changeThe result must follow the modelEmbeds that move when the wall panel changes
Custom property plug-in (.dll)Inside Tekla, called by templates and marksA value Tekla can’t compute for a report or markA CUSTOM. property for a production report

One question sorts most cases. If the output has to update when the model changes, it’s a plug-in, and Tekla runs it again for you. If it runs once and it’s done, it’s a macro or an app, and you choose between them by how you want to ship it: one .cs file, or an exe in a .tsep package.

A first program: count the rebars in the selected elements

using System;
using Tekla.Structures.Model;
using UISelector = Tekla.Structures.Model.UI.ModelObjectSelector;

var model = new Model();
if (!model.GetConnectionStatus())   // false = no running Tekla with an open model
{
    Console.WriteLine("Start Tekla and open a model first.");
    return;
}

var selected = new UISelector().GetSelectedObjects();
while (selected.MoveNext())
{
    if (selected.Current is not Part part) continue;   // skip bolts, welds, components
    var rebars = part.GetReinforcements();              // null on failure, not an exception
    int count = 0;
    while (rebars != null && rebars.MoveNext()) count++;
    Console.WriteLine($"{part.Name} {part.Profile.ProfileString}: {count} reinforcement objects");
}

That’s the whole program. Select a few precast elements in Tekla, run it, and it prints each one with its profile and the number of reinforcement objects attached to it. A rebar group counts as one. The UI selector reads what you selected in the model view. What it returns isn’t a list, which is why LINQ won’t work on a selection until you wrap it. To query the whole model without touching the selection, there’s a second selector from model.GetModelObjectSelector(), and its GetAllObjectsWithType has a type trap of its own.

The API rarely throws. It returns false.

This is the habit that separates tools that work from tools that look like they work. Insert() on a beam with a profile Tekla doesn’t know returns false, which is also why a debugger often has nothing to stop on. GetUserProperty on a UDA that was never set, or that holds a different type, returns false and leaves your variable as it was. GetReportProperty with the wrong overload, same again. The code runs to the end, the model doesn’t change, and nobody is told.

A crash tells you where to look. A false tells you nothing unless you check it. So check every one, and turn it into a message a detailer can read.

You need some C#. Not years of it.

The thing I hear most from detailers is that you have to be a real programmer to start. You need to read C#: an if, a loop, a method call, like the program above. The part that takes years is knowing Tekla. Which property holds the number you want, which phase is released, why that numbering series exists. Detailers already have that part, and it’s the part no one can install for you.

An AI agent writes the C# faster than either of us. It also invents Tekla methods that don’t exist, because there’s little public Tekla code to learn from. That’s why a chatbot isn’t enough, why the agent needs the real API in front of it, and why you still read what it wrote and try it on a copy of the model first.

Tekla Open API in five lines

  • A .NET library: C# on .NET Framework 4.8, from the Tekla.Structures.* NuGet packages.
  • It talks to a running Tekla with a model open, and the package version must be the Tekla version.
  • Four kinds of tool: macro, standalone app, plug-in, custom property plug-in.
  • A plug-in only when the result must follow the model.
  • Check every false. That’s where the bugs hide.

Every post, by task

This page is the map. Each post below takes one job from it and goes all the way down, traps included.

Set up, debug and ship

Read and change the model

Reports, drawings and output

Macros, automation and AI

Free tools built on the Open API

From one chore to your own tools. The course starts close to where this page does: a read-only macro that reports on the parts you select, written by an AI agent with the Tekla Open API skill loaded and read line by line by you. From there you build a quantity take-off checked against Tekla’s own report, tools that write to the model, a WPF app, and finally a plug-in packaged as a .tsep. You bring the Tekla knowledge. The course brings the rest.

Tekla Open API Course: build real Tekla tools with an AI agent →

Related: AI agent for Tekla Open API: why a chatbot isn’t enough · Tekla Open API 2024 upgrade: why your exe stops connecting · Tekla TSEP packaging: build a .tsep with BatchBuilder

Tags

Greg Olszewski

Greg Olszewski builds Tekla Open API tools: Grasshopper Tekla Drawing Link, Smart Select, Tekla Lookup. Ten years of C# on Tekla Structures, day job in precast. Now he teaches engineers to build their own.

About Greg ›

COURSE

Build your own Tekla tools

Learn the Tekla Open API in C#, from your first plug-in to tools your team actually uses.

See the course ›