If you want to waste time on a poorly documented API (which doesn’t make any sense) I would highly recommend getting on Tekla. I’m documenting this so some poor soul doesn’t waste a day trying to debug this:
// what’s wrong with this?
Beam b = new Beam();
b.SetUserProperty("USER_FIELD_1", "your data");
b.Insert();
Do you see the problem? First insert the beam, and then apply the UDA and it should work:
// it only works AFTER you insert
Beam b = new Beam();
b.Insert();
b.SetUserProperty("USER_FIELD_1", "your data");
What glorious waste of time trying to work out why it failed!
But the problem is not with you – the problem is with the API. It fails silently, and the documentation is poor. Hopefully this note saves someone a lot of headaches.
Detailers copy / paste profiles from structural drawings into a CSV file.
This CSV file is then used to create a model.
It is essential that the profiles are recognisable by Tekla.
How can we check?
Through a data validation directly in Excel. Or
By validating the data directly in your code.
using Tekla.Structures.Catalogs;
// download this dll from Nuget
public bool CSVProfilesAreCorrect(List<CSVFieldsImplemented> dataRows)
{
HashSet<string> csvProfiles = dataRows.Select(row => row.Profile).ToHashSet<string>();
HashSet<string> teklaProfiles = getAllTeklaProfiles().ToHashSet<string>();
if (_areCSVProfilesCorrect())
{
return true;
}
else
{
throw new SystemException($"The CSV files have these profiles which don't exist in Tekla: {String.Join(", ", string.Join(", ", csvProfiles.Except(teklaProfiles)))}");
}
bool _areCSVProfilesCorrect()
{
// all the csv profiles
// must be contained in tekla profiles
return csvProfiles.All(profile => teklaProfiles.Contains(profile));
}
}
// and we call it like so:
CSVValidator validator = new CSVValidator(db);
if (validator.CSVProfilesAreCorrect(extractor.CSVRecords))
{
// do the modelling
}
Voila! Now it’s hard to make a mistake.
If you want to get all materials – it’s very similar to the above. Use the CatalogHandler.GetMaterialItems() method along with the materialItem.MaterialName property. The code to actually do that – I will leave as an exercise to the reader.
Go 10km forward, and then 5 km left, and then 2 km right.
Walk forward 10 steps, and now
dig.
This is great from my current location. But how will you get there from YOUR location? Without changing the location of the treasure, I can tell you how to get there, from your location by aligning coordinate systems.
But it can be confusing. Here’s how I think about it intuitively. Forget the maths, just think about it intuitively.
Consider both examples:
If you think about it that way, it will be much harder to get confused.
Suppose you have a Tekla model and you want to programmatically filter for parts with a revision mark of abc/1. How would you do that?
One way would be to iterate through the entire model, check for items which match your condition (perhaps via a LINQ query).
The second would be to use Tekla’s native filtering metchnicsms, which seem to be FAST:
When I originally tried the code, I had a single Binary Filter expression for just the part Position Number. I made a fatal mistake – I had assumed that Tekla would be smart enough to release that given I want a part position number, I also wanted a part. The API returned almost everything under the sun. And I have no idea why. So then I added a second Binary filter expression – this time one for parts.
Given we have two “filters”, we need to add them into a filter collection, and then finally, when we search, we search by .GetObjectsByFilter(filterCollection).
Add “set XS_PLUGIN_DEVELOPER_MODE=true” to the teklastructures.ini file and open Tekla Structures. – Trimble Documentation
In order to add the flag above, you need to locate the ‘teklastructures.ini’ file: on my PC: it is here: `D:\Program Files\Tekla Structures\2019.1\nt\bin` (refer to the above URL) – it might be in the C: drive on your computer.
As you can see they are basically .bat files. Which means you can use “MS-DOS Batch File Language” or batch commands in there. The MSFT documentation suggests you can also use PowerShell (https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.4) script commands.
Here is the post build event I used:
The Tekla documentation is confused about where to paste the DLL – in some cases they say the ‘plugins’ folder, but in others, it is the ‘extensions’ folder. Yet elsewhere, different Tekla versions have different places where you can paste it. In my case, I have focused on the “extensions” directory.
Warning: If you paste it into multiple locations, you may find that you cannot hit break points! The above link suggests the files should be copied into the .environments/common/extensions folder. I am taking that to mean, in actuality: the `Environments/common/extensions` folder. I am not pasting it into the `plugins` folder, but have opted for the `extensions` folder.
If you want to use the plugins folder, follow these instructions: The dll containing the plug-in has to be copied into: \<Tekla Structures installation folder>\<version>\nt\bin\plugins. A sub-folder could also be created to store the dll. In my case, the plugin files are located here: D:\Program Files\Tekla Structures\2019.1\nt\bin\plugins\TestWPFBeamPlugin
Setting up a macro:
Run the UI macro (Reloadplugins.cs) in the Applications & Components catalog on the side pane. We must set it up. In my system, the location is at the following: