Developers Guide
Developers Guide
Developer's Guide
This Software Manual has been developed for use with the referenced Software. Use of the Software, and use of this
Software Manual are governed by a License Agreement. Among other provisions, the License Agreement sets certain
warranties for the Software and this Manual, disclaims other warranties, limits recoverable damages, defines permitted
uses of the Software, and determines whether you are an authorized user of the Software. All information set forth in
this manual is provided with the warranty set forth in the License Agreement. Please refer to the License Agreement for
important obligations and applicable limitations and restrictions on your rights. Trimble does not guarantee that the text
is free of technical inaccuracies or typographical errors. Trimble reserves the right to make changes and additions to this
manual due to changes in the software or otherwise.
In addition, this Software Manual is protected by copyright law and by international treaties. Unauthorized
reproduction, display, modification, or distribution of this Manual, or any portion of it, may result in severe civil and
criminal penalties, and will be prosecuted to the full extent permitted by law.
Tekla, Tekla Structures, Tekla BIMsight, BIMsight, Tekla Civil, Tedds, Solve, Fastrak and Orion are either registered
trademarks or trademarks of Trimble Solutions Corporation in the European Union, the United States, and/or other
countries. More about Trimble Solutions trademarks: http://www.tekla.com/tekla-trademarks. Trimble is a registered
trademark or trademark of Trimble Navigation Limited in the European Union, in the United States and/or other
countries. More about Trimble trademarks: http://www.trimble.com/trademarks.aspx. Other product and company
names mentioned in this Manual are or may be trademarks of their respective owners. By referring to a third-party
product or brand, Trimble does not intend to suggest an affiliation with or endorsement by such third party and
disclaims any such affiliation or endorsement, except where otherwise expressly stated.
D-Cubed 2D DCM 2010 Siemens Industry Software Limited. All rights reserved.
EPM toolkit 1995-2004 EPM Technology a.s., Oslo, Norway. All rights reserved.
Open CASCADE Technology 2001-2014 Open CASCADE SA. All rights reserved.
PolyBoolean C++ Library 2001-2012 Complex A5 Co. Ltd. All rights reserved.
To see the third party licenses, go to Tekla Structures, click File menu --> Help --> About Tekla Structures and then
click the 3rd party licenses option.
The elements of the software described in this Manual are protected by several patents and possibly pending patent
applications in the United States and/or other countries. For more information go to page http://www.tekla.com/tekla-
patents.
Contents
Contents ............................................................................................................................... i
Introduction ......................................................................................................................... 1
What is Tekla Open API?..................................................................................................................... 1
Where to utilize the Tekla Open API? .................................................................................................. 1
Where to find support? ........................................................................................................................ 2
Applications ........................................................................................................................ 9
Introduction .......................................................................................................................................... 9
Getting started ..................................................................................................................................... 9
ApplicationFormBase ......................................................................................................................... 11
Plug-ins.............................................................................................................................. 15
Introduction ........................................................................................................................................ 15
Basic steps for creating a plug-in ....................................................................................................... 15
Model plug-ins ................................................................................................................................... 16
Tekla Open API can be utilized in integration of Tekla Structures to other software.
Information can be transferred between Tekla Structures model and drawing
database and other software used in your office such as:
Office tools
A&D
MIS & ERP
With the API you can for instance get full geometric information for CNC.
Start-up package
The Start-up package, that can be downloaded from the Tekla Warehouse, is a good
starting point for learning and developing your first application or plug-in.
Introduction
Assemblies and reference manual can be found in the folders nt\bin\plugins,
nt\bin\dialogs and nt\help, respectively, in each version of Tekla Structures.
All assemblies except Tekla.Structures.Plugins and
Tekla.Structures.CustomPropertyPlugin are registered to GAC (Global Assembly
Cache).
Common principles
All object classes in the API have common methods for manipulating objects such as:
Select() for object selection from database or from interface
Insert() for creating new object instance
Modify() for modifying object in database or interface
Delete() for deleting object from database or interface
All object classes in API have been designed with following principles:
Object initialization is similar to object creation from user interface of Tekla
Structures. As example Beam is initialized by giving two positions in
constructor-method.
Field naming in object classes follows dialog field names (in English
language) as much as possible.
Tekla.Structures.dll
This assembly contains some basic common types shared by model and drawings.
Tekla.Structures.Model.dll
Model assembly consists of classes and methods used when connecting and
manipulating objects in Tekla Structures model database:
Tekla.Structures.Drawings.dll
Drawings assemblies are recommended to be used to edit the drawings, not for
drawing creation.
This assembly consists of classes and methods used when connecting and
manipulating objects in Tekla Structures drawing database:
Drawing object classes such as Drawing, View, Part, Text, Line.
Methods to manipulate and enumerate drawing objects.
Methods such as picking (dynamic selection) and selection for drawing views.
Tekla.Structures.Plugins.dll
Plugins assembly consists of classes and methods used when defining .NET
component tools (plug-ins) to Tekla Structures. The functionality of a plug-in is similar
to a generic component tool created using Developer Kit. The definition contains:
User interface
Input management
Database structure
Execution
Tekla.Structures.Catalogs.dll
Catalogs contain information on available profiles, bolts, materials, rebars, meshes
and printers. For example, the bolt catalog contains a library of standard bolts and
bolt assemblies used in structural steelwork.
With this assembly you can for example:
Enumerate the profiles from the profile catalog.
Collect the profiles information (name or prefix, type, subtype, parameter
string and parameters).
Select a library profile item by its profile name.
Tekla.Structures.Datatype.dll
The provided unit types are used to pass data to and from Tekla Structures and
between other Tekla Structures assemblies.
The following unit types are provided:
Distance
DistanceList
Boolean
Double
Integer
String
Conversions are supported only with distance unit.
Tekla.Structures.Dialog.dll
This assembly:
Enables dialog creation for Tekla Structures plug-ins
Enables a data connection to Tekla Structures plug-ins
Enables localization of dialogs
Enables support for Tekla Structures data types and conversions
Tekla.Structures.CustomPropertyPlugin.dll
Tekla.Structures.CustomPropertyPlugin assembly consists of classes and metadata
definitions which are needed for new .NET custom properorty (plug-ins) to Tekla
Structures. Custom properties are used in external template property value
calculations for reports, drawings and filtering.
The Tekla.Structures.CustomPropertyPlugin assembly provides
ICustomPropertyPlugin interface which must be implemented when a new
custom property is defined (see topic Custom Properties later in this document).
Introduction
Application can be for example
.NET application, which can be Windows Forms or console applications
COM application utilizing COM technology
VBA macro utilizing COM-technology i.e. like in Microsoft Office
The simplest way of using the Tekla Open API is a .NET application.
Application is executed in a separated process and cannot be started from Tekla
Structures (unless embedded to a macro).
Getting started
To start using the API you need to add references to the API assemblies and
directives to the namespaces in the source code. Please refer the Self Learning
Exercises for step-by-step instructions.
A .NET application that utilizes the API is usually run after Tekla Structures has been
started and a model opened. Because applications are not started together with Tekla
Structures they cannot thus expect to have Tekla Structures running upon execution.
Before interacting with the model, a handle to the model must be created; for
example:
// First we must connect to the model by creating a handle
Model model = new TSM.Model();
// Now we check that the model connection succeeded
if (model.GetConnectionStatus())
{
...
try
{
picker.PickPoint("Pick_point", out point, out view);
}
catch (PickerInterruptedException)
{
// User cancels selection (interrupt)
}
while(Enum.MoveNext())
{
while(AllObjects.MoveNext())
{
if(AllObjects.Current is Line)
{
AllObjects.Current.Delete();
}
}
ApplicationFormBase
ApplicationFormBase adds the following support:
Enables Tekla Structures data types and conversions
Enabling default storing of values
Enables multiple language support
The applications that want to make full use of ApplicationFormBase should inherit
from it. However this is not needed to when only making use of some of its features.
Applications inheriting ApplicationFormBase must call InitializeForm(). This must be
called after the InitializeComponent() method of the Form:
using Tekla.Structures.Dialog;
if(GetConnectionStatus())
{
string messageFolder = null;
Model.GetAdvancedOption("XS_MESSAGES", ref messageFolder);
messageFolder = Path.Combine(messageFolder, @"DotAppsStrings");
Dialogs.SetSettings(string.Empty);
Localization.Language =
(string) Settings.GetValue("language");
Localization.LoadFile(Path.Combine(
messageFolder, Application.ProductName + ".xml"));
Localization.Localize(this);
}
else
{
MessageBox.Show("Tekla Structures is NOT running...");
}
}
}
The following code shows how to create a separate localization instance, enabling
localization of several Forms (using the Localization field of Form1), without inheriting
from ApplicationFormBase and connecting to Tekla Structures through a Model
object:
using TeklaModel = Tekla.Structures.Model.Model;
using TeklaLocalization = Tekla.Structures.Dialog.Localization;
namespace LocalizationExample
{
public partial class Form1 : Form
{
private static TeklaModel _model;
private static TeklaLocalization _localization;
public Form1()
{
InitializeComponent();
Localization.Localize(this);
}
languageFile = Path.Combine(languageFile,
You can load several localization files by calling method LoadFile for each of them.
The translations are searched in the loading order and the first match is returned.
Introduction
Plug-ins are component tools used to automate creation of model or drawing objects.
Plug-ins are intelligent meaning they are modifiable and dependent of input objects.
Plug-ins are loaded inside the Tekla Structures process. Model plug-ins starts from
the Component Catalog, while drawings plug-ins are started from a toolbar.
Model plug-ins
Mandatory fields in the model plug-in
Plug-in has to have a name
StructuresData: gets the data from the user interface into the plug-in
Constructor of the plug-in: copies the data from Tekla Structures
DefineInput (public method): method that defines the input of the plug-in
Run (public method): main method of the plug-in
Class definition
The plug-in Form has to inherit from PluginFormBase:
using Tekla.Structures.Dialog;
The user interface for the plug-in is defined in a metadata attribute of the plug-in
class, PluginUserInterface.
using Tekla.Structures.Plugins;
[Plugin("DialogDemo")]
[PluginUserInterface(typeof(DialogDemo.MainForm))]
public class MainPlugin : PluginFormBase
{
..
If the plug-in is inherited from ConnectionPluginBase, the dialog class name must be
the same as plug-in name:
[Plugin("SpliceConnection")]
[PluginUserInterface("SpliceConnection")]
[Plugin("FloorToolPlugin")]
[PluginUserInterface("FloorTool.FloorToolForm")]
In both cases interface definition must refer to actual dialog class. In connections
class just has to be outside namespace and class name must be the same as plug-in
name.
Note that PluginFormBase dialog class name cannot end with "_01" or similar.
Data connections
Plug-in dialogs save their data to Tekla Structures. The values are then passed to the
corresponding plug-in when it is run.
To use a value entered in a dialog control in a plug-in, you need to set the Tekla
Structures-specific attributes for each control. They can be found for each control in
the Visual Studio Design view, in the Properties tab, under Tekla Structures (see
picture below).
The data is passed to the plug-in using a class defined by the developer of the plug-
in. Its instance must be the only parameter for the plug-in's constructor and it must
consist of public fields that have the Tekla.Structures.Plugins.StructuresField
attribute. The attribute's parameter is where the binding is done to the dialog field. It
must be the same as the name part of the AttributeName property for the field.
using Tekla.Structures.Plugins;
[Plugin("DialogDemo")]
[PluginUserInterface(typeof(DialogDemo.MainForm))]
public class DemoPlugin : PluginBase
{
private StructuresData _data;
public DialogDemo(StructuresData dialogData)
{
_data = dialogData;
}
In the Run method (for example), of the plug-in, you can now read the passed dialog
values from the _data variable.
Modify modifies the selected parts as was defined in the plug-ins run method.
The values are saved as with Apply if the dialog is closed with the OK button.
AttributeName
AttributeName is the name by which you can identify the control in the plug-in. If you
set the control's AttributeName to "length", you can access it in the plug-in side with
the corresponding attribute field in the StructuresData class.
[Tekla.Structures.Plugins.StructuresField("length")]
public double length;
AttributeNames in you Form needs to be different. Otherwise you will get Failed
loading plugin error message saying An item with the same key has already been
added. Maximum length is 19 chars.
AttributeTypeName
AttributeTypeName is the name of the Tekla.Structures.Datatype type for the control's
contents. In the example it is set as Distance. This setting affects the type of the
variable (integer, double or string) that you get to the plug-in, as well as automatic
formatting and localization of the field.
Plug-ins will always receive the data as Tekla Structures standard units, like
millimeters for Distance. The following datatypes and attribute type data mappings are
used:
DataType Plug-in attribute field type
Boolean integer
Distance double
DistanceList string
Double double
Integer integer
The Distance type for example formats the user input like in Tekla Structures and
adds the corresponding unit abbreviation according to the current settings. If, for
example, feet-inches units are active and the user types 14 in the field, the field will
automatically change to say 1'-2". All the datatypes are defined in the
Tekla.Structures.Datatype namespace in Tekla.Structures.Datatype.dll.
IsFilter
According to the Tekla Structures dialog practice you should create an enable/disable
checkbox for each control that the user can use to give input to your plug-in. If the
field's checkbox is unchecked, the value for that attribute will be left unchanged when
the user modifies the objects created with the plug-in.
The way to bind the checkbox to the corresponding control is to set the AttributeName
property to the same value as the input control's AttributeName. Additionally you
must set the IsFilter property to true. The AttributeTypeName should be left empty
(see green markings in the picture below).
Default values
Default values for the fields in the dialog can be set as with classic Tekla Structures
dialogs: create a standard-file and place it in the environment folder. Note that Tekla
Open API dialogs use an XML format for their save files instead of the old native
format.
Open your dialog from Tekla Structures, set the desired default values for the fields,
set the file name to standard and hit Save. The file will be stored under the currently
open model's folder, in the attributes subfolder. Its name is
standard.<AssemblyName>.<FormName>.xml. Copy the file from there to the Tekla
Structures environment structure.
When using INP for dialog definition, plug-in name is defined following way:
[Plugin("BeamPlugin")]
...
public class UserInterfaceDefinitions
{
public const string Plugin1 = @"" +
page(""TeklaStructures"","""")
{
plugin(1, BeamPlugin)
{
...
}
Note that in the above the plug-in names in bold must be the same. If a plug-in name
has a space, i.e. "Beam Plugin", it is not possible to open dialog ("Beam Plugin.inp")
from Tekla Structures Component Catalog.
A step-by-step example
The following steps create a basic plug-in that uses Windows Forms.
Create a new Visual C# project; select "Class Library", and enter an appropriate
name.
Add the following to References to the project:
nt\bin\dialogs\Tekla.Structures.Dialog.dll
nt\bin\plugins\Tekla.Structures.dll
nt\bin\plugins\Tekla.Structures.Datatype.dll
nt\bin\plugins\Tekla.Structures.Model.dll
nt\bin\plugins\Tekla.Structures.Plugins.dll
Add:
public class StructuresData
{
Add:
[TSPlugins.Plugin("FormPlugin")]
[TSPlugins.PluginUserInterface("FormPlugin.MainForm")]
return true;
}
In MainPlugin.cs, add the following to the StructuresData class for each attribute on
the dialog:
[TSPlugins.StructuresField("ATTRIBUTE_NAME")]
public VARIABLE_TYPE VARIABLE_NAME;
Replace ATTRIBUTE_NAME with the name entered for the AttributeName property,
VARIABLE_TYPE with a type corresponding to AttributeNameType, and
VARIABLE_NAME with a suitable variable name.
Add code to DefineInput() to prompt for input objects (parts, points, etc).
Add code to Run() to create parts.
Add a form (Project > Add Windows Form...), change the name to MainForm.cs or
something specific.
Design the dialog. For each control on the dialog, enter a unique name for the
AttributeName listed on the Properties panel (right-click on the control, select
Properties); also, select an appropriate type for the AttributeNameType.
Drawing plug-ins
Drawing plug-ins are created by extending the DrawingPluginBase class for defining
the plug-ins business logic, and the PluginFormBase class for defining their dialog.
The defining and retrieving inputs works a bit differently than in the model.
After the basic steps for creating a plug-in, the plug-in should have a .cs file for the
plug-in code and a Form for the user interface. The drawing plug-in requires few
mandatory fields in order to work.
User interface definition is not mandatory but if user interface is needed it is done with
Windows Forms.
StructuresData
StructuresData works as a gateway to the interface. The attribute names of the
controls in the interface should match the name in the plug-in code.
Supported data types are string, double and integer. Be sure to type the attribute
name right because they are strings.
Constructor
Every plug-in needs a constructor. The constructor sets the StructuresData from the
interface to be in use of the plug-in.
public SlotPlugin(SlotPluginData data)
{
Data = data;
}
DefineInput()
DefineInput is a public method and it is one of the two methods which make the plug-
in a plug-in. This method defines the input(s) of the plug-in. Drawing plug-ins supports
more than one inputs. Plugins with zero inputs works also. The inputs are passed to
the Run method as a List of InputDefinitions.
There is an InputDefinitionFactory that creates and retrieves input objects. They can
be points or certain drawing objects (bolts and parts are supported). The method is
executed when the drawing plug-in icon is pressed from Tekla Structures.
Inputs can be e.g. user based picked points or objects found by enumerating objects
from views.
Close the toolbar customization dialog and open a drawing. An icon for adding a new
plug-in object to the drawing should appear on the toolbar on which it was added.
Dialog opens when you double click the icon in the toolbar or when double clicking
the plug-in component created to the drawing.
For more information and to start testing, please see the MarkPlugin code example
in Start-up package that can be found on Extranet.
A step-by-step example
The following steps create a basic drawing plug-in that uses Windows Forms.
Create a new Visual C# project, select "Class Library", and enter an appropriate
name.
Add the following to References to the project:
nt\bin\dialogs\Tekla.Structures.Dialog.dll
nt\bin\plugins\Tekla.Structures.dll
nt\bin\plugins\Tekla.Structures.Drawing.dll
nt\bin\plugins\Tekla.Structures.Plugins.dll
nt\bin\plugins\Tekla.Structures.Datatype.dll
Add:
[Plugin("FormPlugin")]
[PluginUserInterface("FormPlugin.MainForm")]
return true;
}
Add a Form (Project > Add Windows Form...), change the name to MainForm.cs or
something specific.
Add event handlers for the OK and Modify buttons. For OK, this.Apply() and
this.Close() should be called; and for Modify, this.Modify() should be called.
Build the project and copy the dll created to nt\bin\plugins folder.
Run Tekla Structures, open a drawing and press the shortcut to start the plug-in.
Introduction
Custom property plug-ins are programmed tools for calculating template values used
in reporting and drawings.
Custom properties are loaded inside the Tekla Structures process. Those are called
using syntax CUSTOM.xxx in the same way as normal template properties are
called.
[Export(typeof(ICustomPropertyPlugin))]
[ExportMetaData("CustomProperty", "CUSTOM.NAME_OF_THE_PROPERTY")]
namespace CustomPropertyTest
{
/// <summary>The test plugin for retuning modified id value.</summary>
[Export(typeof(ICustomPropertyPlugin))]
[ExportMetadata("CustomProperty", "CUSTOM.TEST_PROPERTY")]
public class CustomPropertyTest : ICustomPropertyPlugin
{
/// <summary>Returns int value for object.</summary>
/// <param name="objectId">The object id.</param>
/// <returns>The <see cref="int"/>.</returns>
public int GetIntegerProperty(int objectId)
{
return -1 * objectId;
}
TransformationPlane class
Change the work plane using TransformationPlane class.
Model myModel = new Model();
WorkPlaneHandler myWorkPlaneHandler = myModel.GetWorkPlaneHandler();
Beam myBeam = new Beam();
//Using the current work plane
TransformationPlane currentPlane =
myWorkPlaneHandler.GetCurrentTransformationPlane();
myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
MatrixFactory class
Transform a point between coordinate systems using MatrixFactory class.
Model myModel = new Model();
WorkPlaneHandler myWorkPlaneHandler = myModel.GetWorkPlaneHandler();
Beam myBeam = new Beam();
Point myPoint = new Point(100,200,300);
Make sure what the current work plane is before using CoordinateSystem, Point and
Offset classes.
CoordinateSystem class
When creating a new CoordinateSystem instance, the Origin, AxisX and AxisY are
defined based on the current work plane coordinate system.
Point class
The beam's StartPoint and EndPoint properties return values in the current work
plane coordinate system.
Offset class
Offset.Dx is defined using the object's coordinate system. Offset.Dy and Offset.Dz are
defined using the current work plane coordinate system. Before trying to use the
offset values it is important to make sure what the current work plane is since these
values can be changed depends on the current work plane.
Picker class
Currently Picker.PickFace returns the face vertices in the global coordinate system.
Picker.PickLine returns the points in the current workplane coordinate system.
Solid class
Solid.Intersect(LineSegment) : the line segment must be as least 3.2mm long.
Tekla Open API contains Windows Forms dialogs for several catalogs to help
developers of .NET applications and plug-ins which have Forms and need to provide
for example profile selection in UI.
You can drag and drop a custom control from Visual Studios Toolbox into a Form.
There are two ways to add controls to Visual Studios Toolbox:
Right click on the Toolbox and select Choose items. Then click the browse
button to open Tekla.Structures.Dialog.dll. The controls will be added to the list.
You can select one control or all the controls to be added to the Toolbox.
Use Windows Explorer to navigate to the \Program Files\Tekla
Structures\<version>\nt\bin\dialogs\Tekla.Structures.Dialog.dll, open the Designer
and drag and drop the dll into the General tab of the Toolbox. All the controls will
be added to the Toolbox. See the snapshot below.
The item that user selects will be stored to a public property (SelectedProfile,
SelectedMesh, SelectedMeshName, SelectedMeshGrade, SelectedRebarSize,
SelectedRebarGrade, SelectedRebarBendingRadius).
Setting the public property to a certain value will select the value from the dialog
when the dialog opens (if the value is included in the catalog).
For more information, see the ReinforcedBeam code example and Self Learning
material, both can be found from the Start-up package on Extranet.
Localization means here translating and enabling the product for a specific language.
The translated strings for Tekla Structures components are stored in the file
plugins.ail. This file is located in Tekla Structures installation folder, for example
C:\Program Files\Tekla Structures\<version>\messages.
Continuing with the previous example, these lines are added at the bottom of
plugins.ail:
String_utf8 RebarPluginSample
{
Editing
The localization file must have XML content (like shown below) and must be of UTF-8
format.
<?xml version="1.0" standalone="yes"?>
<Table>
<MsgLibStrings>
<StrName>albl_MyString1</StrName>
<chs>My String 1***</chs>
<cht>My String 1***</cht>
<csy>My String 1***</csy>
<deu>My String 1***</deu>
<esp>My String 1***</esp>
<fra>My String 1***</fra>
<hun>My String 1***</hun>
<ita>My String 1***</ita>
<jpn>My String 1***</jpn>
<nld>My String 1***</nld>
<plk>My String 1***</plk>
<ptb>My String 1***</ptb>
<ptg>My String 1***</ptg>
<rus>My String 1***</rus>
<enu>My String 1</enu>
</MsgLibStrings>
<MsgLibStrings>
<StrName>albl_MyString2</StrName>
<chs>My String 2***</chs>
<cht>My String 2***</cht>
<csy>My String 2***</csy>
<deu>My String 2***</deu>
<esp>My String 2***</esp>
</Table>
It is recommended to use Visual Studio when creating or making changes (adding,
changing or removing strings) to a localization file. Make sure that the XML file is well
formed and valid.
Files open in Visual Studio is automatically checked to be well formed, meaning the
tags are symmetrical.
Multiple lines
When you have a long string that is split into multiple lines make sure that there are
no extra new lines or spaces that are easily added by some XML editors: extra new
lines and spaces are shown also in the user interface.
The string should NOT look like this:
<StrName>albl_Create_drawings</StrName>
<enu>
Select parts in the model.
Select a master drawing in the list below.
Then click this button to create drawings.
</enu>
Step-by-step instructions
A localization file is automatically loaded for plug-ins (Forms that inherit from
PluginFormBase) if the file name and path of the XML file is the same as for the plug-
in.
Localization.LoadFile("CommonStrings.xml");
Localization.LoadFile("MyApplicationStrings.xml");
Localization.Localize(myForm);
Note that in case you need many XML files, you can read an arbitrary amount of them
by calling Localization.LoadFile() method for each of them.