This is a picture of a rusty beam. I added the picture here because it looks cool and for no other reason.
In the last part, we left off having collected the relevant Single Part Drawings that we were after. Hopefully we have applied the correct property to filter out the ‘HEA’, ‘IPE’ and ‘CC’ drawings. We will now focus on part II – extracting the distance of the bolts from the beam’s start position.
Get every SinglePartDrawing which name starts with “HEA/IPE/CC”
Calculate the distance of every bolt distance from the start of the corresponding Single Part. ** This blog post will address Part II.
Write the name of the Single Part and every bolt distance to Excel.
Refactor the code.
I did refactor the code a little bit, so it might not look exactly the same as the last version. The code is pretty self explanatory. But you will note that:
I am projecting the bolt positions along the beam’s vector (defined from the start to end point of the beam).
Therefore we do not need to save and set the transformation plane.
A corollary (and potentially unintended consequence) is that this will capture the bolt positions of all bolts, no matter if they are on the flange of the beam, or on the web etc. This may have some unintended consequences. Again, caveat emptor – programmer beware!
Here is the code in all it’s glory – simply follow the well detailed comments and it should be fairly straightforward. As always, any questions, feel free to ask.
We now have extracted the relevant information. Part III will delve into extracting this data in an Excel format. We will most likely use an OpenXML on other such library for that purpose. That post will come shortly, when I get a spare moment. Till that time, enjoy the following – or perhaps it can be left as an exercise for the user?!
We want the bolt distances of all the single parts.
Every now and again we obtain a request from our readership to tackle a problem. If it is of general interest to the public and given our commitments we do sometimes oblige. Here is one such interesting problem. We will tackle this in three parts, and will focus on part 1 in this blog post.
Get every SinglePartDrawing which name starts with “HEA/IPE/CC”
Calculate the distance of every bolt distance from the start of the corresponding Single Part.
Write the name of the Single Part and every bolt distance to Excel.
Refactor the code.
The first part is easy enough – and the code is pretty self-explanatory. We want to iterate through all the drawings and filter for the specific drawings that we are after.
Here is the code:
In the next part, we will look at obtaining the relevant parts that we want and calculating the bolt distances from the start and end points. And finally, we will look at refactoring the code, because it is a little slow, and also from a maintainability point of view.
An Addendum
I was simply following the instructions of the question without inquiring too far into its purpose. If you actually want to extract NC information via the API – Tekla can very easily do this. But that was not the scope of this particular task – it was to deliver a very specific and peculiar set of requirements to a particular reader, but it is a topic which will be of general import to the public.
We want to dimension certain objects in the drawing.
First we need to identify the objects that we want to select. Since the Tekla Closed Open API doesn’t have much of a picker exposed, we would be forced to select the objects we need before running our command. We can do so with a pick first selection (to use the AutoCAD terminology).
It’s not easy to find which bolt has a tolerance of 10 when you have 1000s of them in your model. You can really only do that type of thing with a tool.
This is a repost from our sister site – I needn’t repeat it here, but it’s something that I’ve worked on, and which we hope to utilize to a greater degree when working with Tekla. Anyways, you can get the full blog post if you click this link here. Thank you for stopping by.
We can easily select objects as an input – objects which was can iterate over and apply a series of operations or checks out. But how do we return a selection of objects back to the user?
Background: What are we trying to do?
We have programmatically identified some model objects that we want to select in the model – to attract attention to the user and to allow her to easily identify all such objects. In this particular case we will be creating some beams. And then, we will select those beams in the model. Here is a code snippet to get you started:
When marked to all grid lines, this makes it easy for the folks on the floor to mark out. Don’t make it hard for them!
What is the task at hand?
So I get some phone calls the other day – people complaining. They want changes. Yet again! Why can’t these people make up their minds! That means I have to get off Facebook, go back to my code – which I hopefully haven’t forgotten, and I have to try and make their changes fit in, with the least amount of trouble.
What did they want this time?
They wanted to dimension bolts not just to one grid line, but to every single one. Ok that’s fine. How am I going to select all parallel gridlines, given an input of just one gridline?
First I need the input Gridline. This is given. We have the input gridline because we’ve asked the user to select a relevant gridline.
We need to get the actual grid, using that grid line.
We need to get all pertinent gridlines using the grid – we want to get only the gridlines that are parallel with our originally selected gridline.
Using those filtered gridline points, we need to extract out a pertinent reference point and add that to the set of points used to create the dimensions.
1. The Input Gridline
This has been obtained by selection.
2. Getting the Actual Grid
3. Getting Pertinent Gridlines
Now we extract the relevant points given the above information.
This is the final result:
4. Create the dimensions
We’ve got the bolt dimension (previous post). We have some grid line dimensions (see above code). Add the above points to the bolt positions and then create those dimensions as outlined in the previous post. Voila! We are finished! Now back to WoW!
An example of us copying a column from one object, to the rest – to the rest of the beams.
What is the task at hand? We want to make the Copy Object To Object command more efficient
There is a nifty little command – little oft used in Tekla. The “Copy Object To Object” command. It’s handy, but it could be made better: all the model objects have to be selected individually. That can be a little bit of a pain. In this lesson we will create some code, using the Open API, to allow users to select multiple objects (all at once) by which the copy object to object command can be applied to.
Where is the pertinent Call in the API? I’d prefer this type of thing to be a method on the relevant ModelObject. But it’s static method in the Operation class. Here is the hello world example, straight from the documentation:
Copying Object to Object – Hello World Example:
This is fantastic! Now let us outline what we want the command to do:
What do we want our command to do?
We want the user to select an object (or group of objects).
We then want the user to select a “source” object.
We want the user to then select all objects to copy to.
The program should then use the parent object as a source, and use that as a reference to copy everything selected in step #1 to all the objects selected in step #3.
1. Ask the user to select a bunch of model objects – The objects to copy
We can use the Picker class, located in the Tekla.Structures.Model.UI namespace. And there is a handy object which thankfully has been exposed: PickObjects(Picker.PickObjectsEnum, String). This returns a ModelObjectEnumerator which we can iterate over.
2. Ask the user to select the source object:
You can get the source object in the same manner as the above code – except you would use the PickObject method instead of the PickObjects (plural) method.
3. Ask the user to select the objects to copy to:
We can use the same method used in step 1.
4. Copy from Object To Object
The rest is as easy as A-B-C:
5. Finally, we want to Redraw Views after the Copying Operation has completed
What we want to do is to select and dimension all the bolts to a particular grid line. Here’s how it should work:
* The user selects a group of bolts.
* The user selects a gridline.
* Dimensions are drawn from the Bolts to the Gridline.
But quelle surprise – the Tekla API doesn’t expose an object which can select or pick multiple drawing objects.
What are some solutions around this problem?
We’ll we’re gonna have to be a little creative. Thankfully, Trimble have exposed the ability to programmatically obtain drawing objects. Given these objects we need to somehow filter out the stuff we want to dimension. Here are some possible ways:
We could provide a Control where we can choose and filter what objects we want to dimension, after reading/seeing it’s properties in some type of user interface (you could have a WPF application and use its fancy data binding ability + MVVM pattern + Command objects working with Service layers and Messengers) – but that would require considerable effort.
You could just select everything individually. But that would take forever.
You could extend the PickerInputWithinAView abstract method to allow you to select multiple objects.
Or you could find a way to easily filter it all. And I think I’ve found a way.
Deep in the annals of the Tekla API Reference Guide, I found that the Picker type exposes the PickTwoPoints method. And if we can pick two points, then we can certainly filter our selections.
Issues In the Algorithm We Need to Address
User picks two points.
User picks a gridline
We then filter all bolts within the bounding box of the original two picked points, and we create dimensions to the appropriate gridline. We need to understand the Drawing API.
We also need to know about saving and reverting transformation planes.
This is the hello world version of what we are trying to do, but perhaps on a scale that is a little more grand. We need some basic code on how to create dimensions.
How to Programmatically Pick Two Points
How to programmatically select a grid line
Warning – I no longer recommend this approach because it is very, very difficult to actually select a bolt. A better approach would be to select a point, and programmatically filter to get the grid line you want.
Understanding the Tekla Drawing API
Please refer to the below diagram.
An Explanation of how the Tekla API categorises its objects.
The things that you see in the drawing, are not exactly what you can see on the model. They are drawing representations of what you see in the model. If you want specific geometry based information concerning what you see in the drawing you must:
1. First get the drawing object (i.e. the drawing representation you see as a Bolt in the drawing).
2. Then you must get that same Bolt in the model.
3. You must then inquire in the model about the particular attributes or positional properties of that bolt – which is represented as a bolt in the drawing.
4. You must also bear in mind that Views etc have their own coordinate system. So if you may need to translate any differences which exist in the model to the local coordinate system of the particular view you are using. You can set and retrieve the transformation plane like so:
How to Save And Revert Transformation Planes
5. So if you need to create some dimensions, the exact lengths etc must be derived by querying the pertinent model object representations of what you see in the drawing.
How to Create some Dimensions
The diagram provides a handy summary and visual representation of the parameters you need to pass in when creating a set of dimensions using the Tekla Open API.
How to get the drawing objects (in this case bolts) and programmatically filter them out
A Primer on how the Tekla.Structures.Drawing namespace is structured
Firstly you have a Drawing class. There are many types of drawing sub-classes:
Within each drawing is what is called the ConatinerView. A sheet is a container view. A container view is simply – if I were to use an everyday metaphor if you were grocery shopping – a bag which you can use to put: (i) other bags or (ii) shopping items inside. In order to get the ContainerView object, you can use the Drawing.GetSheet method – and you will be returned a ContainerView object.
Inside a container view you can typically:
* GetObjects()
* Or you can GetAllViews
* Or you can GetAllObjects of a certain type.
And within the container view, using some of the above methods you can get all sorts of DrawingObjects:
* DetailMark
* Dimensions etc
* Drawing representations of ModelObjects – like: Bolts, Connections, Grids, Gridlines, Parts, Welds etc.
Put all the elements together
If you put all the elements together, you can create some powerful little Plugins. I can’t post the full code because my boss will murder me, so I’ve done my best to teach you the key elements so you can create something powerful yourselves.