Tag: Tekla Open API

  • 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.
  • 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:

     

  • Copying From Object To Object – Tekla Open API (Code Snippets + Video)

    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?

    1. We want the user to select an object (or group of objects).
    2. We then want the user to select a “source” object.
    3. We want the user to then select all objects to copy to.
    4. 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

    Video demonstration

    …That’s all folks. Hope you learned something!

  • How to programmatically insert Reference Models into Tekla (Tekla Open API)

    Wouldn’t it be handy if we could programmatically insert reference models into Tekla? Well you can now do so quite easily.

    Here is the code which does the hard work. (You will of course add the appropriate references and directives):

    And if you want to see a video demonstration, here it is:

    Inserting XRefs into Tekla as Reference Models from Tek1 on Vimeo.

  • How to Set Up a Tekla API Project (Tekla API Application)

    Work faster with the Tekla API

    The object of a Tekla Application is to ensure that things go smoothly on the construction site. You can see the organised chaos that is here. Avoid the real chaos. Plan ahead. 

    For the newbie this post shows how to set up a Tekla Project.

    Let us assume that you are creating a WPF desktop Application. You could also just as easily create a console application – I often do this if I simply want a quick and dirty way to test code.

    1. Go to Visual Studio.
    2. Create a new WPF project.

    Follow this gif:

    Setting up a Tekla Project
    How to Set up a Tekla WPF Application
    1. Next you need to add references to Tekla DLLs. They are contained at this location on my PC. C:\Program Files\Tekla Structures\19.1\nt\bin\plugins\ .They may be in a different version on yours. You can also download these dlls using Nuget in your Visual Studio.
    2. If you are using 19.1i version – then you can download Trimble’s nuget package named thus: 2019.1.50434

    Follow this Gif:

    Adding Tekla References

    Shows how to add references to a Tekla API WPF Project.

    1. The fourth and final step is to add directives and to then get coding.

    Some common directives and aliases that I use:

    I hope this post helps you!

  • Showing an Assembly in the Model via a Tekla Drawing (Part II) Tekla Open API + Code snippets

    We are revisiting a post I made earlier.

    Here’s the problem. You are viewing a Tekla drawing. But you have no idea what you are looking at, or where it is. This macro will take you to that very assembly in the model. It’s actually quite handy. And here is the previous post where I made allusion to the facility (you’ll find a video demonstrating its use):

    http://www.tek1.com.au/tekla-plug-in-2-viewing-an-assembly-in-the-model-from-an-assembly-drawing/

    This post marks the release of the code which does the job! Enjoy!