Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Last active October 9, 2023 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkoshy/bcef5f34c8dd3503eb77eb2fcef88814 to your computer and use it in GitHub Desktop.
Save benkoshy/bcef5f34c8dd3503eb77eb2fcef88814 to your computer and use it in GitHub Desktop.
Get Revision Number of Drawings - Tekla Open API

The Tekla API is not very open - one of my peeves is that you cannot access a drawing's revision number, because it is not exposed. Not to worry, you can access it with a hack:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Tekla.Structures.Drawing;
using Tekla.Structures.Model;

namespace BensExtensions
{
    public static class DrawingExtensions
    {
        // Use it like this:
        // drawing.RevisionNo(); where drawing is of type Drawing
        public static string RevisionNo(this Drawing drawing)
        {
            PropertyInfo PI = drawing.GetType().GetProperty("Identifier", BindingFlags.Instance | BindingFlags.NonPublic);
            object value = PI.GetValue(drawing, null);
            Tekla.Structures.Identifier Identifier = (Tekla.Structures.Identifier)value;

            Beam b = new Beam();
            b.Identifier = Identifier;
            string revisionMark = String.Empty;

            b.GetReportProperty("REVISION.MARK", ref revisionMark);

            return revisionMark;
        }
    }
}

// and use it like this
drawing.RevisionNo(); // where drawing is of type Drawing
// Unfortunately, AFAIK, c# does not permit property extensions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment