Category: Tekla API

A series of blog posts exploring the Tekla API.  Code examples, explanations and (where relevant) videos will be provided.

  • Refactoring the Code – Printing Selected Beams to Excel – Part 1 – (Tekla Open API)

    Improve by refactoring.
    Strive to improve the code. Just like this guy is trying to improve his swing. Looks like a fine golfer by the way. probably low single figure handicap, if not scratch.

    We will attempt to do something which is seldom done or discussed in Tekla code samples: and that is the very important issue of refactoring code.

     

    1. Start with Tests.

     

    The first thing you need is a good suite of tests. That way you will know whether something has gone wrong or not. It might be tricky doing this since we are developing within the Tekla environment, but I do suppose it’s possible.

     

    2. General Themes:

     

    • Change names to more appropriate titles.
    • Restructure the code to make it understandable.
    • Correct any obvious defects:

     

     

  • Write Selected Beam Members to an Excel File (Tekla Open API – Tutorial)

    Members. Looks good.
    Some nice looking steel. The picture has nothing to do with the Tekla API but it’s cool nonetheless.

    What is the task at hand? 

    1. The user selects some beams.
    2. We then want to collate the following information into various Excel spreadsheets:
      1. Name
      2. Profile
      3. Length and finally Weight
    3. We want two views: the first aggregates the beams by their name and finish, and the second merely lists all the beams selected with the information listed above (length/weight etc).

     

    WARNING: The code is very dirty. There’s a lot of repetition here. And I’ve gone up some cul de sacs incorrectly. But that’s ok. It’s code which works. We can worry about refactoring for another day – in fact, that will make for a very good exercise. Here is a link to where I document the refactoring process.

     

    I’ll walk you through the code:

    Here is the full code unencumbered by commentary:

  • Extracting Bolt Distances of Single Part Drawings (Beams) With an Output In Excel – Part 3 (Tekla Open API)

    Some holes in a person-hole lid.

    In the last part we left off having obtained all the bolt distance and placing them in a domain object. In this instalment we will try to export all that data into an Excel Spreadsheet. Please note that the following code is untested – unfortunately there was a lightening storm in Melbourne which short circuited my flux capacitor which means I cannot connect to the TeklaServer – so rather than wait, I thought to get this code out to you.

    Which library to write to Excel?

    There are many libraries out there: XLS compatible and not:

    1. OpenXML libraries
    2. ClosedXML libraries
    3. NPOI
    4. EPPlus

     

    The consensus is that the worst of the above is still better than using Microsoft’s office interop dll. If you use that approach, you will need to ensure that MS Office is installed in your deployment machine, and secondly, be sure to dispose of all relevant objects. If you forget, then you’ll be leaking memory. This is a very important point.

    How to use ClosedXML in your code:

    1. Firstly download closedXML using NuGet Package Manager. That should add the relevant references.
    2. Secondly add the `using ClosedXML.Excel` directives.
    3. Then add the code snippets I’ve provided for you below:

    Notes on the code:

    * A significant change has been made – we are now filtering the SinglePartDrawings based on: (i) whether they are beams or not and (ii) whether they have the relevant profile – a reader wrote an email asking for this version of the code. I have left the previous version out there as well.

    * I’m not an expert with ClosedXML – I just wanted to get the code out there. So it’s a very hackish and non-elegant solution, but I hope it serves to illustrate the point.

  • Extracting Bolt Distances of Single Part Drawings (Beams) With an Output In Excel – Part 2 (Tekla Open API)

    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.

     

    1. Get every SinglePartDrawing which name starts with “HEA/IPE/CC”
    2. Calculate the distance of every bolt distance from the start of the corresponding Single Part. ** This blog post will address Part II.
    3. Write the name of the Single Part and every bolt distance to Excel.
    4. 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?!

  • Extracting Bolt Distances From Single Part Drawing Files With an Output In Excel – Part 1 (Tekla Open API)

    We want the bolt distances of all the single parts.
    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.

    1. Get every SinglePartDrawing which name starts with “HEA/IPE/CC”
    2. Calculate the distance of every bolt distance from the start of the corresponding Single Part.
    3. Write the name of the Single Part and every bolt distance to Excel.
    4. 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.
  • Pick First Selection in the Drawing (Tekla Open API)

    Imagine you are in the Tekla Drawing space.

    Imagine you are in the Tekla Drawing space.

    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).

    The code is quite simple, but is very important:

  • Select Bolts From Tekla Model Based on its Tolerance using WPF (Tekla Open API) + Code Snippets + Video Demo

    Select bolts depending on their tolerance
    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.

    Video Demonstration of Bolt Selector Tool

    Select Bolts From Tekla Model Based on its Tolerance using WPF (Tekla Open API) Video Demo from Tek1 on Vimeo.

  • How to Programmatically Select Objects in the Model (Tekla Open API)

    Return a selection of objects back to the user.
    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:

     

  • How to Get Parallel Grid Line Points (Tekla Open API)

    All Gridlines Dimensioned
    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?

    1. 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.
    2. We need to get the actual grid, using that grid line.
    3. 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.
    4. 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!