How to check if you have a legitimate Tekla Profile using the Tekla Open API

Our use case?

  1. Detailers copy / paste profiles from structural drawings into a CSV file.
  2. This CSV file is then used to create a model.
  3. 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.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *