How to work with Tekla Structures Macro scripts

Tekla macro script, record scriptTekla Structures allows to record whole user activity to macro script, and then you could play it again and again. This allows to save time on some routine. And if we take in case that Tekla Structures developers loves menus, and submenus, and sub-submenus,  and buttons, and… all this stuff. With bunch of parameters, and applying /modifying… so save some clicks would be great idea, and macros really cool thing for this.

Tekla Macro script recording

To record macro script in Tekla you have to go thought few steps:

  • Goes to Tools > Macros to open Macros dialog.
  • Type a Name for a new macro
  • Push Record button
  • Do something in Tekla
  • To finish record push Stop button
Tekla macro script, record script
List of available macros

After that would be created new file with name which you type with .cs extension in folder which is set as default in Tekla Advanced Options – XS_MACRO_DIRECTORY

So you could find it at that folder, usually path to it could look  something like this:

C:\ProgramData\Tekla Structures\19.0\Environments\Common\macros\

To change default folder on something more suitable for your company (usually some common network folder) you have to replace path in advanced options. You could find these here:

Tools > Options > Advanced Options,

Or use hot key –  ctrl+E

  • Then goes to ‘File Locations’,  and find XS_MACRO_DIRECTORY line, it contains actual path to yours macro folder.
Tekla Macro script - advanced options, script path

How to edit Tekla Macro Scripts

Okay, now we got some macros which was recorded and it make something – great! But things which has been generated usually not fully satisfies sophisticated requirements. But we could solve this manually, because result of record – is a text which contains list of actions step by step. So we could modify it with any suitable editor:

  • You could use C# Visual Studio, Express version would be more than enough.
  • Visual Studio Code – also could be nice for these.
  • As well as NotePad++
  • Or with default windows notepad.

How Tekla Macro script looks like

In common case, right after record it looks something like this:

namespace Tekla.Technology.Akit.UserScript {

public class Script {
     public static void Run(Tekla.Technology.Akit.IScript akit) {

   akit.Callback(“acmd_display_dialog”, “dia_view_dialog”, “main_frame”);
  akit.PushButton(“v1_get”, “dia_view_dialog”);
  akit.ValueChange(“dia_view_dialog”, “v1_projection”, “1”);
  akit.PushButton(“v1_modify”, “dia_view_dialog”);
  akit.PushButton(“v1_ok”, “dia_view_dialog”);
}
}
}

At first look it looks a little bit weird. But actually it quite simple to read, especially if you take into account steps which you actually did.

Text of macro contains class which named as Script,  and this class contains method – Run which takes as argument akit object, it will be provided by Tekla instance when you run script in interface.

And these all requirements for scripts acutally – entru point named Run which takes as external dependency – akit object.

Inside this method you could do whatever you want. But by defauld you have to work with received object, which give you access to Tekla UI actions.

For example in script which is listed above we do:

  •  akit.Callback(“acmd_display_dialog”, “dia_view_dialog”, “main_frame”); –call view dialog.
  •  akit.PushButton(“v1_get”, “dia_view_dialog”); –  at this dialog push button Get
  • akit.ValueChange(“dia_view_dialog”, “v1_projection”, “1”); –  change some values.
  • and push buttons Modify to change settings of selected view in drawing
  • and Ok to close dialog

Accordingly we could edit scripts as simple text – add, edit or remove some actions. And because Tekla Structures use as scripting language C# we also could add some variables, make calculation, and even create our own menus and windows.  For example you could look at script from this article (link would be available soon)

More about scripts

5 thoughts on “How to work with Tekla Structures Macro scripts

  1. MEZHER January 20, 2019 at 12:22 pm

    To whom it may concern,
    This article is so useful, but could you mention how to run a macro ??

    • DonJad August 19, 2019 at 10:50 am

      You could run scripts exact the same way as you run default scripts. Just double click on desired macro. Or select it in list and push Run button.

  2. Md. Nurul Islam November 12, 2021 at 6:29 am

    Hi,
    Say; on a dwg file, there are a few lines whose layer names are according to the AISC shape profile (like W10X12, W16X50 and so on). I want to import this file on tekla when tekla will take the layer’s name as profile of the member. It should show a dialog box to take dwg file location and Top Of Steel (TOS) Level.
    Is it possible?

    Thank You,
    Md. Nurul Islam
    nislam04@yahoo.com

Leave a Reply

Name *
Email *
Website