Python in TechEditor: Code Integration and Engineering Report Automation

Python in TechEditor: Code Integration and Engineering Report Automation

Modern engineering demands flexibility. Standard software tools often fall short when you need to run complex algorithms or process specific data. This is where Python comes in — the industry standard for data analysis and engineering.

In this guide, we’ll show you how to combine the power of Python libraries with TechEditor’s documentation capabilities. You will learn how to turn TechEditor into a script execution environment, manage data exchange between the program and your code, and unlock new possibilities for automating your reports. You don’t need to be a pro developer — understanding the basics covered here is enough.

General Concept: How TechEditor Works with Python

In general, the TechEditor environment allows you to:

  • Run Python code directly within a TechEditor project.
  • Transfer variable values from Python to the report and vice versa.
  • Handle units of measurement while taking Python code into account.

Key Principle: When integrating Python with TechEditor, TechEditor acts as the server. It triggers the request, sends input data to the Python interpreter, awaits execution, and retrieves the results into the report. This means you can leverage any library (NumPy, SciPy, Pandas) installed on your computer.

Important Note: If you share a .tec file containing Python code, the recipient needs the same modules and libraries installed to run it.

Do you need to modify your code for TechEditor? No — and that’s the best part. If your code is bug-free and runs in a standard Python environment, it is almost guaranteed to run in TechEditor. This article will show you how to use simple commands to pass data from your code to the main TechEditor report and back.

Also, note that running Python code grants access to file operations and specific modules, such as APIs of other programs. With this toolkit, you can, for example, query a BIM application, extract the necessary data, and pass it to TechEditor for calculation or reporting.

Environment Setup

How to Install Python

To successfully work with Python in TechEditor, you first need to install the Python environment on your computer. You can do this:

  • Via the TechEditor installer: Upon completion of the installation, check the "Python" box and follow the on-screen instructions.
  • Manually: By downloading it from the official repository.

Important Note on the 32-bit Version

For Python code to run correctly in TechEditor, the 32-bit version is required. If you already have 64-bit Python installed, you must also install the 32-bit version (they will work fine side-by-side).

Integrating Python Code with TechEditor Calculations

Let's look at an example of how to execute elementary Python code within TechEditor.

  1. Launch TechEditor. Ensure it opens with a single empty report (if not, add a report manually).
  2. Add a Python Script resource document to the project. A Resource is simply a text document where the code is placed. Do not close the report yet; we will need it shortly.

In the resource document, let's write a simple function that calculates the doubled sum of "x+y" in Python:

# Python Script
def func_double_sum(x, y):
    double_sum = 2 * (x + y)
    return double_sum
# finish

The resource document is purely for storing source code and cannot be run independently. To execute this code, we need to call it from the main document. This is where the report comes in.

  1. Switch to the report tab. Add a special Script Integration object, located in the Objects > Math / Script Integration tab.
  2. In the dropdown list, select the newly created resource (Resource1), and in the Output script text field, write your function with numerical arguments.

Click OK. Verify that the function executed correctly.

Passing Mathematical Data from the Report to Python

Above, we showed an example of Python code that doesn't depend on our document. Now, let's rewrite the script so that it becomes a helper module for the main calculations.

  1. Add a block of input data to the beginning of the report. You can do this using a Math Object, Math LaTeX Object, or others.
  2. Let's use a Slider. So, we have two variables, x and y, controlled by sliders.

Return to the resource document. Change the code to the following:

# Python Script
import techeditor
def func_double_sum():
    x = techeditor.math_translator_calc( "x" )
    y = techeditor.math_translator_calc( "y" )
    double_sum = 2 * (x + y)
    return double_sum
# finish

First, we import the techeditor module (we'll discuss it below). We remove the arguments from the function itself — they will now be taken directly from our report.

Next, we have a block for variables x and y. The value of each variable is assigned using the special function math_translator_calc, into which we pass the name of the TechEditor variable (the variable used in the slider).

Return to the Python object already integrated into our report. Double-click it to edit and adjust the function according to the new format. Click OK.

Verify that moving the sliders affects the calculations in your Python code.

Functions of the techeditor Module

In the last example, we used the techeditor module. It contains special functions that allow data exchange between TechEditor and Python:

  • math_translator_add( cmd ) — adds the string cmd to the document's mathematical model;
  • math_translator_calc( cmd ) — calculates the expression cmd and returns a real number (float) or a text string (str);
  • math_translator_clear() — clears the document's mathematical model.

The math_translator_add function is useful if you need to add a variable or function to the report via Python. The following code adds the variable "delta=5.5" to the report:

techeditor.math_translator_add( "delta=5.5" )

The math_translator_calc function calculates the value of an argument. We already examined it above.

The math_translator_clear function removes all variables and functions from the report, so it should be used with caution.

Working with Units of Measurement in Python

The Python programming language does not have standard data types that allow engineers to operate on physical quantities with arbitrary units of measurement. However, TechEditor handles this, so our task is to correctly pass this data to Python.

Let's add units of measurement to variables x and y. Let's assume they have the dimension of length and are measured in millimeters.

If we look at the report now, we'll see a specific picture:

Python in TechEditor

Python perceived our data as plain text strings. This is technically correct: it first concatenated them as text constants and then printed them twice (remember the coefficient 2 in the formula).

Let's rewrite the code. Since Python "doesn't know" about physical quantities, let TechEditor perform all operations with them using the math_translator_calc function:

# Python Script
import techeditor
def func_double_sum():
    double_sum = techeditor.math_translator_calc( "2*(x+y)" )
    return double_sum
# finish

Now we have the correct result.

Python in TechEditor

But the question remains: is it possible to work with TechEditor variables inside Python so that we can process physical quantities as regular float numbers?

Yes, this is possible if we "strip" the units of measurement:

# Python Script
import techeditor
def func_double_sum():
    x = techeditor.math_translator_calc( "empiric(x•{mm})" )
    y = techeditor.math_translator_calc( "empiric(y•{mm})" )
    double_sum = 2 * (x + y)
    return double_sum
# finish

Here we use the standard TechEditor function empiric(), which cuts off the physical units and leaves only the numerical value. As a result, we get a correct number of type float (having previously converted everything to millimeters).

Passing Data from Python to the Report

TechEditor also allows for reverse data transfer — from Python code to the report. This can be useful if your code performs specific calculations and needs to pass several key values to the final report.

Let's look at an example of Python code that generates a random number in the range 1..25 and passes it to the variable RANDOM_VALUE. TechEditor should display this variable and its doubled value in the report.

Code in the resource document:

# Python Script
import random
r = random.randint(1, 25)
# finish

We proceed via the Script Integration object, just as before. Select the Python resource, and in the Output script field, write the name of the Python variable r.

Below, in the Integrate with mathematical model field, specify the name of the target variable — RANDOM_VALUE (this is now for TechEditor), and opposite it, the base variable r. Click OK.

Display the doubled value of RANDOM_VALUE in the report below using the Math Object. From now on, this is a fully-fledged variable, and you can work with it in the report according to standard TechEditor rules (including adding units of measurement and converting it into a physical quantity).

Python in TechEditor

You can update the random value by pressing the F5 key (manual report recalculation).


As we can see, integrating Python transforms TechEditor from a reporting tool into a powerful computational platform. By using the Script Integration object, you can:

  • Perform complex mathematical operations unavailable in the standard editor.
  • Automate routine data generation processes.
  • Work with external APIs and file systems directly from the report.

What's next? Try reproducing the example from this article in your own project. If you have questions or ideas for more complex scenarios, we invite you to discuss them in our Discord community. Also, don't forget to check out ready-made solutions in the Dystlab Store, which can significantly speed up your work.

FAQ

Q: Can I perform calculations in Python and automatically format the results in TechEditor?

A: Yes. The Script Integration object is used for this. It allows you to pass variables from Python into the TechEditor environment, where they become available for use in formulas and report text.

Q: Is it possible to launch TechEditor report generation automatically via a Python script (externally)?

A: No. TechEditor's architecture assumes that the program acts as the server (host). That is, TechEditor runs the Python code inside itself, not the other way around.

Q: Does Python in TechEditor support working with physical quantities (units of measurement)?

A: Yes, and this is a key advantage. By using the specialized techeditor module, you can operate with physical quantities, and the program correctly recognizes dimensions when returning data to the report.

Q: Can I access another program from Python?

A: Yes, provided that the other program has an appropriate API.

Q: I already have Python installed, but my code doesn't run in TechEditor. What is the problem?

A: Most likely, your computer is missing the 32-bit version of Python (it can be installed alongside the 64-bit version).

Image

Vitalii Artomov

"I am working to make «Made in Ukraine» a global symbol of quality and style"

CEO, co-founder of Dystlab, developer of TechEditor. Engineer, scientist, Ph.D. with over 20 years of experience in structural analysis and automation of engineering calculations. I advise engineering companies in Ukraine, Europe, and North America.

Discuss business solutions: This email address is being protected from spambots. You need JavaScript enabled to view it. | +380504576819 (WhatsApp)

dystlab-logo4-bg-white1920.png
dystlab-logo4-bg-white1920.png

Technology center Dystlab

We develop digital solutions for engineering companies and design businesses. We advise, research, and help with the automation of calculations, design, and systematization of technical documentation.

innot needed textfoanother not needed text@dystlabdummy text.com

Visa MasterCard | DS.Store

© Copyright 2019-2026 Dystlab™, Ukraine. All rights reserved.
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.