Guides and Articles

Use this documentation when building your Tekla Structures apps

Checklists before starting

Updated: 8 Feb 2018

Before you begin to build an application, please review the checklists below.

You might not have thought about these things but you should take them into account while coding with Tekla Open API.

 

User interface checklist

Check the following guides before starting implementing user interface to your application:

  1. Keep logic and user interface separate
  2. Keep tool always above Tekla Strucures
  3. Hide tool from Windows taskbar
  4. Start tool from Tekla Structures user interface

If Tekla Structures is closed the tool is closed too

You need to check when Tekla Structures is closed. This feature can be added to the startup code as follows:

if (TeklaStructures.Connect())
{
    TeklaStructures.Closed += delegate
    {
        Application.Exit();
    };
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    try
    {
        Form1 form1 = new Form1();
        form1.Show(TeklaStructures.MainWindow);
        Application.Run(form1);
    }
    finally
    {
        TeklaStructures.Disconnect();
    }
}

Additionally this prevents the tool from being started when Tekla Structures is not running.

You can also check manually whether Tekla Structures is running using a timer:

  1. On the Toolbox tab, under All Windows Forms, double-click Timer to add it on your form.

  2. Set Enable property to true. 

    Checklists before starting: Tekla structures Open API before publishing is closed
  3. Switch to Events view and double-click the Tick event to create the event handler. Checklists before starting: Tekla structures Open API before publishing is closed
  4. Modify the event handler code to this: 
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (!TeklaStructures.IsRunning)
        {
            Application.Exit();
        }
    }

The tool handles common cases where model may not be available

In certain cases a tool may be started before a model has been loaded. The easiest way to see whether a model is loaded is to check whether the model has a name. (The examples below use Tekla.Application.Library).

if (!string.IsNullOrEmpty(TeklaStructures.Model.Name))
{
    // Model is available.
}

After a model has been loaded, an event is raised.

TeklaStructures.Model.Loaded += delegate
{
    // Model has been loaded.
};

Decimal separator is dot, not comma

Tekla Structures strings always use dot (.) as a decimal separator.

Use Invariant culture info for string to double conversions to make sure user's local culture
settings (for example, Finnish and comma (,)) do not interfere with conversion.

double Value = Convert.ToDouble("3.141", CultureInfo.InvariantCulture);
// instead of just
// double Value = Convert.ToDouble("3.141");

Only one instance of tool can be started

In certain cases is it preferable that no more than one instance of the tool can be started.

The easiest way to do this is to use the Visual Basic application services. (The example

below uses Microsoft.VisualBasic assembly).

using System;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;
namespace WindowsApplication1
{
    class Program : WindowsFormsApplicationBase
    {
        public Program()
        {
            IsSingleInstance = true;
            EnableVisualStyles = true;
        }
        protected override void OnCreateMainForm()
        {
            MainForm = new Form1();
        }
        protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
        {
            eventArgs.BringToForeground = true;
            base.OnStartupNextInstance(eventArgs);
        }
        [STAThread]
        static void Main(string[] args)
        {
            Program program = new Program();
            program.Run(args);
        }
    }
}

Tool is located in right folder

Make sure the tool is copied to the correct folder inside Tekla Structures installation folder; applications to \nt\bin\applications (Drawings or Model subfolder), and plug-ins to \nt\bin\plugins (Drawings or Model subfolder).

Handle exceptions in applications and plug-ins

Follow the steps below to create safe applications and plugins.

  • Minimize the use of IO in the methods called when an application or plug-in is loaded by Tekla Structures. Make sure it cleans up all IO and memory so there is no problem that would cause Tekla Structures to hang.

  • Keep the constructor as simple as possible.

  • Check any input from the user, and if it is not what is required, either ask again or exit.

  • For errors where you need to terminate the application or plug-in, throw the exception or let the highest level method catch it.

  • Only exit the application from the highest level method. In case a plug-in, it should be the plug-ins Run method and make sure the Run method handles all exceptions.

Application should not collect any personally identifiable information

Personal data means any information that identifies a natural person, directly or indirectly. Person can be identified by an identifier such as a name, an identification number, location data, or a factor specific to the physical, physiological, genetic, mental, economic, cultural or social identity of that natural person.

In case your application collects any personally identifiable information you should have a privacy policy in place which explains for instance how you collect, store, process, transfer and use any personal data. You must ensure that you comply with your privacy policy and all privacy and data protection laws applicable to you, such as General Data Protection Regulation of the European Union (“GDPR”).