Examples
Examples
Examples
Examples
Contents
Contents ............................................................................................................................... i
Preface ................................................................................................................................. 1
1
1.2
1.3
1.4
SplitPolygonWeld .................................................................................................................... 14
Location ................................................................................................................................... 14
Explanation .............................................................................................................................. 14
Testing the example application .............................................................................................. 14
1.5
SimpleDrawingList ................................................................................................................... 15
Location ................................................................................................................................... 15
Explanation .............................................................................................................................. 15
Testing the example ................................................................................................................ 15
1.6
BasicViews .............................................................................................................................. 17
Location ................................................................................................................................... 17
Explanation .............................................................................................................................. 17
Testing the example application .............................................................................................. 17
ii
SplicePlugin ............................................................................................................................. 23
Location ................................................................................................................................... 23
Purpose ................................................................................................................................... 23
Explanation .............................................................................................................................. 23
Using the plug-in...................................................................................................................... 23
Known problems ...................................................................................................................... 24
Scripts/Macros ......................................................................................................... 26
3.1
3.2
RebarExample1B .................................................................................................................... 26
3.3
RebarExample2B .................................................................................................................... 26
iii
Preface
Application examples
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.
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.
Location
Together with this document you should have the source codes and the project
files for Visual Studio 2010 in Examples\Model\Applications\RebarExamples.
Content of folders and files:
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 20.0 versions without any modifications. The executables
shall be compiled separately for both versions; however, the source code is still
100% compatible between 18.0 & 20.0.
In the next paragraphs we are going through the most important aspects of the
program code.
bar.Size = "20";
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.
// create longitudinal bars at four boundary corners of the solid
// bar #1 at "lower left"
bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y +
40, solid.MinimumPoint.Z + 40));
bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y +
40, solid.MinimumPoint.Z + 40));
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.
// bar #2 at "lower right"
bar.Polygon.Points.Clear();
bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MinimumPoint.Y +
40, solid.MaximumPoint.Z - 40));
bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MinimumPoint.Y +
40, solid.MaximumPoint.Z - 40));
bar.Insert();
// bar #3 at "upper right"
bar.Polygon.Points.Clear();
bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y 40, solid.MaximumPoint.Z - 40));
bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y 40, solid.MaximumPoint.Z - 40));
bar.Insert();
// bar #4 at "upper left"
bar.Polygon.Points.Clear();
bar.Polygon.Points.Add(new Point(solid.MinimumPoint.X, solid.MaximumPoint.Y 40, solid.MinimumPoint.Z + 40));
bar.Polygon.Points.Add(new Point(solid.MaximumPoint.X, solid.MaximumPoint.Y 40, solid.MinimumPoint.Z + 40));
bar.Insert();
First, create the new instance of the class and initialize the basic
properties.
// initialize the rebar group object for stirrup creation
RebarGroup stirrup = new RebarGroup();
stirrup.Father = myPart;
stirrup.Size = "8";
stirrup.RadiusValues.Add(16.0);
stirrup.Grade = "A500HW";
stirrup.OnPlaneOffsets.Add(20.0); // please note the data type has to be
'double'
stirrup.FromPlaneOffset = 50;
stirrup.Name = "Stirrup";
stirrup.Class = 4;
stirrup.EndPointOffsetType =
Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
stirrup.EndPointOffsetValue = 20.0;
stirrup.StartPointOffsetType =
Reinforcement.RebarOffsetTypeEnum.OFFSET_TYPE_COVER_THICKNESS;
stirrup.StartPointOffsetValue = 20.0;
stirrup.StartHook.Angle = 135;
stirrup.StartHook.Length = 80;
stirrup.StartHook.Radius = 16;
stirrup.StartHook.Shape = RebarHookData.RebarHookShapeEnum.HOOK_90_DEGREES;
stirrup.EndHook.Angle = 135;
stirrup.EndHook.Length = 80;
stirrup.EndHook.Radius = 16;
stirrup.EndHook.Shape = RebarHookData.RebarHookShapeEnum.HOOK_90_DEGREES;
// set group spacing
stirrup.Spacings.Add(250.0);
stirrup.SpacingType =
Reinforcement.RebarSpacingTypeEnum.SPACING_TYPE_TARGET_SPACE;
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.
// set the polygon and insert stirrup into model
Polygon polygon1 = new Polygon();
polygon1.Points.Add(new Point(solid.MinimumPoint.X,
solid.MinimumPoint.Z));
polygon1.Points.Add(new Point(solid.MinimumPoint.X,
solid.MaximumPoint.Z));
polygon1.Points.Add(new Point(solid.MinimumPoint.X,
solid.MaximumPoint.Z));
polygon1.Points.Add(new Point(solid.MinimumPoint.X,
solid.MinimumPoint.Z));
polygon1.Points.Add(new Point(solid.MinimumPoint.X,
solid.MinimumPoint.Z));
Polygon polygon2 = new Polygon();
polygon2.Points.Add(new Point(solid.MaximumPoint.X,
solid.MinimumPoint.Z));
polygon2.Points.Add(new Point(solid.MaximumPoint.X,
solid.MaximumPoint.Z));
polygon2.Points.Add(new Point(solid.MaximumPoint.X,
solid.MaximumPoint.Z));
polygon2.Points.Add(new Point(solid.MaximumPoint.X,
solid.MinimumPoint.Z));
polygon2.Points.Add(new Point(solid.MaximumPoint.X,
solid.MinimumPoint.Z));
solid.MaximumPoint.Y,
solid.MaximumPoint.Y,
solid.MinimumPoint.Y,
solid.MinimumPoint.Y,
solid.MaximumPoint.Y,
solid.MaximumPoint.Y,
solid.MaximumPoint.Y,
solid.MinimumPoint.Y,
solid.MinimumPoint.Y,
solid.MaximumPoint.Y,
Finally, after the polygons are added to array RebarGroup.Polygons, the stirrup can be
created by inserting the object into Tekla Structures model.
10
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.
11
Location
Together with this document you should have the source codes for sample
programs and the project files for Visual Studio 2010 in
Examples\Model\Applications\RebarExamples.
Content of folders and files:
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
12
Finally we are ready to insert the component into Tekla Structures model.
// insert new component instance into model
component1.Insert();
13
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 contains following functionality:
14
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.
Application contains following functionality:
Refresh: When you press this button is pressed, the tree view is regenerated. 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.
15
16
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.
17
Plug-in examples
Location
Together with this document you should have the source codes for sample
programs and the project files for Visual Studio 2010 in
Examples\Model\Applications\RebarExamples.
Content of folders and files:
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.
18
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:
public RebarPluginSample(StructuresData data)
{
this.data = data;
}
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.
// this is called by TS when the command is started
public override ArrayList DefineInput()
{
Picker picker = new Picker();
ArrayList inputList = new ArrayList();
ModelObject o1 = picker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART);
InputDefinition input1 = new InputDefinition(o1.Identifier);
inputList.Add(input1);
return inputList;
}
19
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.
Identifier id = InputDefinition)Input[0]).GetInput() as Identifier;
Part myPart = myModel.SelectModelObject((id) as Part;
20
21
Characteristics of example #3
Compared to previous examples, this example has few advantages. First of all we
have now few properties we can adjust. By double clicking the reinforcement in
model view the following dialog will open.
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.
22
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:
The CreateSplices function loops through the beams and does these, starting from
the second beam:
23
Known problems
If the last beam is too short, the result might look strange; a plate could stand out
from the beam.
24
25
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.
26