Examples
Examples
Examples
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.
This product contains proprietary and confidential technology, information and creative works owned by Flexera
Software LLC and its licensors, if any. Any use, copying, publication, distribution, display, modification, or
transmission of such technology in whole or in part in any form or by any means without the prior express written
permission of Flexera Software LLC is strictly prohibited. Except where expressly provided by Flexera Software LLC
in writing, possession of this technology shall not be construed to confer any license or rights under any Flexera
Software LLC intellectual property rights, whether by estoppel, implication, or otherwise.
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
Preface ................................................................................................................................. 1
Contents
Characteristics of example #3 ................................................................................................. 22
2.2 SplicePlugin ............................................................................................................................. 23
Location ................................................................................................................................... 23
Purpose ................................................................................................................................... 23
Explanation .............................................................................................................................. 23
Using the plug-in...................................................................................................................... 23
Known problems ...................................................................................................................... 24
3 Scripts/Macros ......................................................................................................... 26
3.1 Dimensioning Center of Gravity ............................................................................................... 26
3.2 RebarExample1B .................................................................................................................... 26
3.3 RebarExample2B .................................................................................................................... 26
Purpose
This example shows in detail how to create a very simple .NET application which
utilizes the Model API to create a beam in a Tekla Structures model from a button
in application window.
Fill out the details as shown in the screenshot and press OK to create an empty
Windows application.
Application examples
4. Add button to application form and beam creation to Click-event
Go back to the design view of the form and add a button to it. Place the button on
the form and name it Create Beam. Double-click the button to open up the code
for its Click event.
private void button1_Click(object sender, EventArgs e)
{
Model myModel = new Model();
The following code can now be added to the click method. It will insert a Beam
between the points (1000,1000,1000) and (6000,6000,1000) in the model.
Explanation
A brief explanation of the code above and what it does:
1. Creates a new Model object that represents the Tekla Structures Model we
have opened in Tekla Structures.
2. Checks if we have a Tekla Structures Model that we can connect to.
3. Creates the two points that will be used as the start and end point for the
beam.
4. Creates a new Beam based on the two input points.
5. Sets the Beams Material and Profile.
6. Inserts the Beam into the Tekla Structures Model.
7. CommitChanges makes sure all changes that have been done are updated
in Tekla Structures and that the model view is updated accordingly. If this
command isn't run then you will have to refresh the view manually to see
the changes.
After this has been done all you need to do is make sure you have a Tekla
Structures Model opened and after choosing Start from the Debug menu in Visual
Studio to run your project. Your form with the Create Beam button should now
appear and pressing the Create Beam button should place a Beam at the wanted
coordinates into the model.
Application examples
1.2 Reinforcement example #1
This example creates single bars and stirrups.
Location
Together with this document you should have the source codes and the project
files for Visual Studio in Examples\Model\Applications\RebarExamples.
Content of folders and files:
Macro Tekla Structures macros
RebarSample1 source files and project files for example #1
RebarSample2 source files and project files for example #2
RebarSample3 source files and project files for example #3
RebarExamples.sln solution file for Visual Studio
Explanation
In this first example we are using some of the basic reinforcement classes. The
actual application has been implemented as an executable (file RebarSample1.exe)
but practically the same source code can be run as Tekla Structures macro (file
RebarSample1B.cs). One advantage of a macro is that it can be run both within
Tekla Structures 18.0 and 21. versions without any modifications. The executables
shall be compiled separately for both versions; however, the source code is still
100% compatible between 18.0 & 21..
In the next paragraphs we are going through the most important aspects of the
program code.
ModelObjectEnumerator myEnum =
myModel.GetModelObjectSelector().GetSelectedObjects();
while(myEnum.MoveNext())
{
Beam myPart = myEnum.Current as Beam;
TEKLA OPEN API EXAMPLES 7
Application examples
if(myPart != null)
{
.
.
.
}
}
myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(localPlane);
.
.
.
// remember to restore current work plane
myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
Application examples
bar.Grade = "A500HW";
bar.OnPlaneOffsets.Add(0.0); // please note the data type has to be 'double'
bar.FromPlaneOffset = 0.0;
bar.Name = "Longitudinal";
bar.Class = 7;
bar.EndPointOffsetType =
Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
bar.EndPointOffsetValue = 25.0;
bar.StartPointOffsetType =
Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
bar.StartPointOffsetValue = 25.0;
After we have initialized the object properties we can calculate the input points for rebar
shape polygon. To keep the example very simple we are using the solid boundary points.
Once we have the object fully defined, we can insert the object into model as follows. Now
we have created a new reinforcement bar into Tekla Structures model.
bar.Insert();
After we have created the first rebar, we are re-using the same object to create three other
rebars. To do this, we just clear the shape polygon and add new points to it. When we have
added the necessary point, we will call the insert method.
The actual shape of the stirrup and the range of the group is defined by two polygons. In
this example, we create two polygons representing stirrup shapes at both ends of the
group. After the new polygon is instantiated we add the necessary points to them.
Finally, after the polygons are added to array RebarGroup.Polygons, the stirrup can be
created by inserting the object into Tekla Structures model.
Application examples
stirrup.Polygons.Add(polygon1);
stirrup.Polygons.Add(polygon2);
stirrup.Insert();
Characteristics of example #1
This is a static application, meaning that it creates the bars and stirrup based on
situation as it was during the moment the application was run. If you make changes
to beam size or length, the rebars are not automatically adjusted. To be able to get
the reinforcement updated you need to modify it interactively or you need to
delete the reinforcement and re-run the application.
As you can see in the above picture the application is not able to manage the end
notches in anyway. This is of course because of the very simple geometry handling.
In the next example, we will be using one of the simple system components which
would add more intelligence to our application.
Location
Together with this document you should have the source codes for sample
programs and the project files for Visual Studio in
Examples\Model\Applications\RebarExamples.
Content of folders and files:
RebarSample2 source files and project files for example #2
RebarExamples.sln solution file for Visual Studio
Explanation
In this second example we are using two simple system components. With the help
of these components we can actually increase the intelligence of the application
due to their ability to manage notches and openings in the part.
The basic structure of the application is the same as in example one. The source
code of the standalone application can be found in 'RebarSample2.cs'. The
corresponding macro can be found in 'RebarSample2B.cs'.
In the next paragraphs we are going through parts of the program code which are
different from example one.
Then we will initialize the objects properties. For components we can utilize the "save as"
files and load the base values for all properties and only set the necessary values explicitly.
// mamange the settings i.e. load standard defaults and set the
// few important attribute values explicitly
component1.LoadAttributesFromFile("standard");
component1.SetAttribute("bar1_no", 4); // number of bars
component1.SetAttribute("cc_side", 45.0); // cover thickness at side
component1.SetAttribute("cc_bottom", 45.0); // cover thickness at bottom
Next we set up the input for the component. The input sequence shall be same as the input
when the component is applied interactively. In this case the input contains the part and
three points. Point class is included to "Tekla.Structures.Geometry3d" namespace which is
included with
Application examples
// prepare input points for the "longitudinal rebars" component
Point p1 = new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y,
solid.MaximumPoint.Z);
Point p2 = new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y,
solid.MaximumPoint.Z);
Point p3 = new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y,
solid.MinimumPoint.Z);
Finally we are ready to insert the component into Tekla Structures model.
1.4 SplitPolygonWeld
This example splits an existing polygon weld into its segments.
Location
All necessary source files for compiling application are found from folder
"Examples\Model\Applications\SplitPolygonWeld" in the Open API StartupPackage.
Explanation
Split Polygon Weld is an example application showing how to first use Picker class
to pick the weld and then how to handle the weld points in order to implement the
splitting. This example utilizes also method Operation.CopyObject.
Application examples
1.5 SimpleDrawingList
This example finds a list of drawings.
Location
All necessary source files for compiling application are found from folder
"Examples\Drawings\Applications\SimpleDrawingList" in StartupPackage.
Explanation
Simple Drawing List is an example application showing how to go through various
drawings and drawing objects. This application is not intended to provide any
meaningful functionality to Tekla Structures; it is only a simplified example of the
Drawings API.
Refresh: When you press this button is pressed, the tree view is re-
generated. Depending on the amount of drawings this might take a while.
Show views: When this check box is selected, the application will fetch the
views in the drawings. This is considerably slower than just fetching the
drawings.
Show objects in views: When this check box is selected, the application will
fetch the objects in the views. Show view must be selected to enable this.
Open selected drawing: When you press this button, the selected drawing
in the tree view is opened. If nothing is selected or if the selected tree view
item is not a drawing, this button will do nothing.
Delete selection: When you press this button, the selected item on the tree
view is deleted from the drawing database. This button deletes both
drawings and drawing objects.
Application examples
1.6 BasicViews
This example creates views in drawings.
Location
All necessary source files for compiling application are found from folder
"Examples\Drawings\Applications\BasicViews" in StartupPackage.
Explanation
Create Basic Views is an example application showing how to create general
arrangement drawings with different views. It uses the same definitions for the
view rotations as the model command "Add component basic views". This should
not be mixed with single part or assembly or cast unit drawing views, which have
they own definitions for views. Drawings created with this application are not
automatically updated. Therefore, if the basic views are created from assembly or
from task, these drawings must be recreated after adding new parts to the
assembly or task.
Application contains following functionality:
Create: Creates drawings from the selected model objects. If there are
several model objects selected, one drawing is created for each model
object. Model object can be part, assembly, task, component or cast unit.
Open drawings: If this check box is checked, drawing creation is visible. If
there are multiple model objects selected, the last drawing is left open
when the application has completed all drawings. When this check box is
not selected, the drawings are created in invisible mode similar to normal
Tekla Structures drawing creation.
Top/Front/End/3d view: When selected, the specified view is created.
Location
Together with this document you should have the source codes for sample
programs and the project files for Visual Studio in
Examples\Model\Applications\RebarExamples.
Content of folders and files:
RebarSample2 source files and project files for example #2
RebarExamples.sln solution file for Visual Studio
Explanation
In this third example, we are implementing a new plug-in component. We are using
the same method to create the reinforcement as we have used in example #2, and
by looking at the source code in file 'RebarSample3.cs', you can see that it uses the
system components in the same way.
In the next paragraphs we are going through parts of the program code which are
different from previous examples.
In this example, we only have two properties which control the number of bars at
top and bottom.
Plug-in examples
Plug-in name in component catalog
Every plug-in component will have a unique name in Tekla Structures component
catalog. This name is defined with following meta code statement. Together with
the plug-in component name we have to define the container variable for the user
interface. This will be discussed more at paragraph 4.4
[Plugin("RebarPluginSample")]
[PluginUserInterface(RebarPluginSample.UserInterfaceDefinitions.dialog)]
As you can see, we have also declared one member variable data which will be
explained later. This plug-in class needs to implement the virtual constructor which
is taking its parameter an object of class StructuresData:
Definition of input
This plug-in component will define its input sequence by overriding the method
DefineInput(). In this method, we will collect the input by using the Picker class and
its various methods and by adding the input into an ArrayList, returned as result of
the method.
ModelObject o1 = picker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART);
inputList.Add(input1);
return inputList;
}
[PluginUserInterface(RebarPluginSample.UserInterfaceDefinitions.dialog)]
In this method we are using the Tekla.Net API to create the reinforcement in similar
way as in example #2. However, there are certain differences because of the
reason how plug-ins are working.
First of all, as you can see there is no enumeration of selection. The reason for this
is that the part to be reinforced is given as input for the plug-in and we can get the
reference to part by simply selecting it with the identifier we can get from the
input.
Plug-in examples
Default value handling
As we wanted to add few properties for our plug-in we need to take care of the
default value handling. In Tekla Structures it is possible to leave the input empty
and the intention is that the plug-in or system component is expected to choose
the value based on it's best knowledge.
In simple cases the plug-in can use some fixed value but in general it will be
somehow dependent on input objects. For example in our case the number of bars
may be dependent on beam size, however here we are using a simple method with
fixed values.
// we need to calculate final values for input properties which have default
(=empty)
// input values.
if(IsDefaultValue(data.BottomNumber))
data.BottomNumber = 6;
if(IsDefaultValue(data.TopNumber))
data.TopNumber = 2;
Here, we can modify the properties of the plug-in component the same way as the
properties of custom components or system components.
Secondly, whenever some geometrical changes happen to the beam, the plug-in is
automatically called and the reinforcement will be adjusted.
Plug-in examples
2.2 SplicePlugin
This example creates beams and splice connections between them.
Location
All necessary source files for compiling application are found from folder
"Examples\Model\Plugins\SplicePlugin" in StartupPackage.
Purpose
SplicePlugin is simple example that creates beams and then creates splice
connections between them. This plug-in uses the Europe environment; this can be
changed by using other profiles, bolt standards and bolt sizes.
Explanation
The code is divided into 2 parts. First, the beams are created, and then each splice
is created. Creation of a splice can be divided again into two parts: creation of
plates and then creation of bolts.
The Run()-function does these:
Calculate amount of beams needed
Create those beams in loop and add those to array
Call CreateSplices() with the array as argument
The CreateSplices function loops through the beams and does these, starting from
the second beam:
Create two plates
Create bolt array
Known problems
If the last beam is too short, the result might look strange; a plate could stand out
from the beam.
Plug-in examples
TEKLA OPEN API EXAMPLES 25
Plug-in examples
3 Scripts/Macros
3.2 RebarExample1B
This is the same as Rebar example 1, but as macro:
Model\Applications\RebarExamples\Macro\RebarSample1B.cs.
3.3 RebarExample2B
This is the same as Rebar example 2, but as macro:
Model\Applications\RebarExamples\Macro\RebarSample2B.cs.
Scripts/Macros