Python can drive Tekla. It can’t be a Tekla plug-in. And the two hardest failures to spot end in the same line: GetConnectionStatus() returns False, with Tekla open and a model loaded.
Python loads the same .NET DLLs your C# does
There’s no Python API for Tekla Structures. There’s pythonnet, which loads .NET assemblies into CPython, so your script calls Tekla.Structures.Model like a console exe would. It runs outside Tekla and talks to it over the same connection. That makes it fine for scripts, batch edits, reports and AI agent tools. It doesn’t make it a plug-in: Tekla loads plug-ins and custom properties as compiled .NET DLLs inside its own process, and a .py file isn’t one.
A script that connects and reads the selected parts:
import os, sys
import pythonnet
pythonnet.load("netfx") # .NET Framework 4.8, before "import clr"
import clr
TEKLA_BIN = r"C:\TeklaStructures\2026.0\bin" # the version that's running
for folder in (TEKLA_BIN, os.path.join(TEKLA_BIN, "Net48Runtime")): # 2026 keeps Tekla.Structures.dll here
if os.path.isdir(folder):
sys.path.append(folder) # pythonnet resolves dependencies from sys.path
clr.AddReference("Tekla.Structures")
clr.AddReference("Tekla.Structures.Model")
from Tekla.Structures.Model import Model, Part
from Tekla.Structures.Model.UI import ModelObjectSelector
model = Model()
if not model.GetConnectionStatus():
sys.exit("No connection: check the runtime, the DLL folder and the version")
for obj in ModelObjectSelector().GetSelectedObjects(): # a plain for loop over the enumerator
if isinstance(obj, Part): # arrives as a Beam or ContourPlate, no cast
ok, weight = obj.GetReportProperty("WEIGHT", 0.0) # 0.0 picks the double overload
print(obj.Name, round(weight, 1) if ok else "no weight")
Each setup line above the imports matches a row in the next table.
Four ways not to connect, with Tekla open
| What you did | What you see | Fix |
|---|---|---|
Loaded the .NET Core runtime (pythonnet.load("coreclr"), or a host that defaults to it) | TypeLoadException: System.Runtime.Remoting.Lifetime.ClientSponsor, then False | pythonnet.load("netfx"). Tekla’s connection needs .NET Framework. |
| Pointed at the DLLs from the NuGet packages | ReflectionTypeLoadException, no Tekla module, or a missing System.Runtime.CompilerServices.Unsafe | Load from Tekla’s own bin. NuGet spreads the dependencies over a dozen packages. |
Used the bin of another Tekla version | Loads fine, never connects | Same version as the running Tekla. The connection name carries the DLL’s build number. |
Added only bin on Tekla 2026 | FileNotFoundException: Could not load file or assembly ‘Tekla.Structures’ | Add bin\Net48Runtime too. Tekla.Structures.dll moved there. |
Rows two and four throw, so you find them. Rows one and three only return False. The third is the one the error text gives away. Run the script above with the 2024 bin while Tekla 2025 is open, and it prints Cannot connect to remoting service ‘Tekla.Structures.Model-TeklaStructures-Console:2024.0.59077.0’. That number is the build of the DLL you loaded, not the Tekla you opened. On Windows, pythonnet uses the .NET Framework by default, so the first row mostly bites in hosts that change it. Rhino’s documentation says Rhino 8 runs on .NET Core unless you switch it with SetDotNetRuntime.
One more thing that error text tells you: Tekla writes it to standard output, not standard error. A script that prints CSV gets a stack trace in the middle of it. An MCP server that talks to its AI agent over stdout gets a corrupted channel.
The placeholder’s type picks the overload
In C#, GetReportProperty takes a ref double, ref int or ref string. Python has no ref, so pythonnet takes a placeholder value and hands back a tuple: the bool, then the value. The placeholder’s type decides which of the three overloads runs.
ok, weight = part.GetReportProperty("WEIGHT", 0.0) # (True, 8294.4): a 6 m wall panel, in kg
ok, weight = part.GetReportProperty("WEIGHT", 0) # (False, 0): the int overload
ok, profile = part.GetReportProperty("PROFILE", "") # (True, '3600*160')
0 and 0.0 look the same to a Python reader. To pythonnet they’re Int32 and Double. It’s the silent false from GetReportProperty again, one character wide.
The selection goes the other way. In C#, ModelObjectEnumerator is an IEnumerator, which is why LINQ won’t compile on it. pythonnet iterates an IEnumerator with a plain for, and each object arrives as its real type, so isinstance(obj, Part) works without a cast. Python lists don’t convert to .NET, though. A method that wants an ArrayList needs a real System.Collections.ArrayList.
Two open-source projects that already load Tekla from Python
tekla_mcp_server (GPL-3.0) is a Python MCP server that lets an AI agent work in a Tekla model. Its loader is a good template. It puts both bin and bin\Net48Runtime on sys.path, and it redirects .NET’s console output to standard error before loading anything, which is the stdout fix above. Its connection wrapper retries three times. Its comments say a lost connection can’t be re-established in the same process: restart the script.
PyTekla (MIT) wraps the API in Python style: generators instead of enumerators, dictionaries instead of Hashtable. Check two things before you install it. The PyPI release is from March 2023 and pins pythonnet==3.0.1, which doesn’t install on Python 3.12 or newer, so pip install pytekla needs Python 3.11. And it loads Tekla.Structures.dll from bin only. Point it at a valid Tekla 2026 bin and it asks you to “set a valid path”.
Python or C#: where the line is
The line isn’t taste. It’s what Tekla loads. A script that reads a model, writes a CSV, renames a phase’s wall panels or feeds an AI agent can be Python. Anything Tekla has to load itself has to be a .NET DLL: a plug-in, a custom property in a drawing table, a TSEP your colleagues install. Python talks to Tekla. C# runs inside it.
Before your first Python script connects
- Runtime: netfx. Call
pythonnet.load("netfx")beforeimport clr, and check what your host loads. - DLLs: Tekla’s
bin, same version. Not NuGet, not last year’s install. - 2026: add
bin\Net48Runtime. ReferenceTekla.Structuresexplicitly. - Placeholders:
0.0,0,"". They choose the overload. - Stdout isn’t yours alone. Redirect .NET’s console if anything parses your output.
The course is C#, and this is the reason. Plug-ins, custom properties and TSEP packages are .NET, so that’s where the course goes once your first scripts work. Your AI agent writes the C#, and the Tekla Open API skill gives it the rules on version matching and the 2024 NuGet change. The traps in the table above come from the same place in both languages: the DLLs.
Tekla Open API Course: build real Tekla tools with an AI agent →
Related: Tekla Open API 2024 upgrade: why your exe stops connecting · Get selected objects in Tekla Open API (and use LINQ on them) · AI agent for Tekla Open API: why a chatbot isn’t enough
