How to work with Events in Tekla Structures.

Tekla structures open API Events, how to work withUsing Events in C# is a good way to make your application more sensitive and add interactivity abilities to your solutions. These allows you to reply at changes in Tekla Model or Drawing, as soon as they arrived. But in other side Events is pretty complicated for understanding and it not so easy to apply in your solution. So for better understanding of mechanism of Events you should understand of how delegates work.

But if you want just to add ability to react at your script or application listing bellow should helps. 

This is a listing with code for a simple form, which allow to catch Event from Tekla Model which happens each time when user change selection in model.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tekla.Structures.Model;

namespace EventFormRegister
{
    public partial class Form1 : Form
    {
        //create event first 
        private Tekla.Structures.Model.Events _events = new Tekla.Structures.Model.Events();
        private object _selectionEventHandlerLock = new object();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //add function to event 
            _events.SelectionChange += Events_SelectionChangeEvent;
            //and register it
            _events.Register();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //unregister it on exit.
            _events.UnRegister();
        }

        void Events_SelectionChangeEvent()
        {
            //Make sure that the inner code block is running synchronously.
            lock (_selectionEventHandlerLock)
            {
                MessageBox.Show("Selection changed event received");
            }
        }
    }
}

Tekla Structures openApi Events Examples:

Now let’s make something useful with this feature: Custom Inquire Tekla Structures Macro Script

One thought on “How to work with Events in Tekla Structures.

Leave a Reply

Name *
Email *
Website