Tekla custom property plug-in: part row or assembly row?

Your reinforcement ratio says 21 kg/m³ in the cast unit table and 0 in the part list underneath. Same CUSTOM. name, same DLL. The template asked about a different object, and the plug-in only knew how to answer for one.

One business rule, one report value

At work I use a custom property plug-in to wrap our reinforcement ratio rule: rebar weight over concrete volume, in kg/m³. The rule lives in one DLL. A drawing table shows it as one value field, CUSTOM.REINFORCEMENT_RATIO, like any built-in attribute. A UDA stores what someone typed. A custom property works the number out every time a table asks.

The plug-in is small: a class with a [CustomPropertyPlugin("CUSTOM.…")] attribute and three methods, GetDoubleProperty, GetIntegerProperty and GetStringProperty. Tekla calls the one that matches the field’s type, once per object per field. It passes you one thing: an int objectId.

The template picks the object. Your code gets an id.

That int is the whole contract. No row type, no “this is a cast unit”. A value field in an assembly row hands you the assembly’s id. Put the same field in a part row and you get the part’s id. A rebar row hands you a rebar. Write SelectModelObject(id) as Assembly, test it in the cast unit table, and the part list gets null, your catch returns 0, and nobody sees an error. The cast unit numbers don’t help either: read CAST_UNIT_REBAR_WEIGHT on the wall part itself and GetReportProperty returns false. It only answers on the assembly.

So decide the level before you write the formula. A reinforcement ratio describes a cast unit, not one of its parts. Whatever id arrives, turn it into the cast unit first:

// Level: CAST UNIT. A ratio, so every row of the cast unit answers with the same value.
[CustomPropertyPlugin("CUSTOM.REINFORCEMENT_RATIO")]
public class ReinforcementRatio : ICustomPropertyPlugin
{
    public double GetDoubleProperty(int objectId) => RatioWorker.KgPerM3(objectId);
    public int GetIntegerProperty(int objectId) => (int)Math.Round(RatioWorker.KgPerM3(objectId));
    public string GetStringProperty(int objectId) => RatioWorker.KgPerM3(objectId).ToString("0");
}

internal static class RatioWorker
{
    private static readonly Model Model = new Model();               // once, not once per row

    public static double KgPerM3(int objectId)
    {
        try
        {
            Assembly castUnit = ToCastUnit(Model.SelectModelObject(new Identifier(objectId)));
            if (castUnit == null) return 0.0;

            double rebarKg = 0.0, concreteMm3 = 0.0;
            castUnit.GetReportProperty("CAST_UNIT_REBAR_WEIGHT", ref rebarKg);
            castUnit.GetReportProperty("VOLUME_ONLY_CONCRETE_PARTS", ref concreteMm3);
            if (concreteMm3 <= 0.0) return 0.0;

            return rebarKg / (concreteMm3 / 1e9);                    // the API gives mm³, the ratio wants m³
        }
        catch
        {
            return 0.0;                                              // never throw into a drawing table
        }
    }

    private static Assembly ToCastUnit(ModelObject obj)
    {
        switch (obj)
        {
            case Assembly assembly: return assembly;                 // assembly or cast unit row
            case Part part: return part.GetAssembly();               // part row: climb one level
            case Reinforcement rebar:                                // rebar row: GetAssembly() is null,
                return (rebar.Father as Part)?.GetAssembly();        // so climb through the host part
            default: return null;                                    // bolt, weld, component
        }
    }
}

The rebar case is the one that looks wrong and isn’t. Reinforcement has a GetAssembly() of its own, and in a Tekla 2025 model it returned null for every rebar group cast into the wall. The rebar’s Father is the wall, and the wall knows its cast unit. The three entry points are thin and the logic sits in one worker, so the integer and the string can’t drift from the double. On Tekla 2024 and older the attribute doesn’t exist yet: register the same class with MEF, [Export(typeof(ICustomPropertyPlugin))] plus [ExportMetadata("CustomProperty", "CUSTOM.REINFORCEMENT_RATIO")].

Climbing is right for a ratio. For a quantity it counts twice.

Climbing means every part of a four-part sandwich wall answers with the cast unit’s value. For a ratio that’s what you want. Each row says 21, and nobody sums a ratio. Now do the same with an additive number, say CUSTOM.CAST_UNIT_STEEL_KG. Every part row prints the cast unit’s steel, and a sum row at the bottom of the part list adds it up four times.

So the level is a decision per property, not per DLL. A ratio climbs and answers the same on every row. A quantity answers only at its own level and returns 0 everywhere else, so a sum stays true. Write which one it is in the comment above the class. The template doesn’t show it, and the next person to put the field in a table won’t guess.

My agent wrote correct code with the wrong property

I built this exact property with my AI agent for the course. The plumbing was right first time: the attribute, the three methods, the CUSTOM. prefix, the deploy folder. It even caught on its own that volume comes back in mm³, not m³. A 6 m wall panel, 3600*160, reads 3,455,999,999.9999995. Divide kilograms by that and the ratio is nine zeros too small.

The engineering choices needed steering. Its first version looped over the cast unit’s parts, checked MATERIAL_TYPE for CONCRETE and added up VOLUME one part at a time. It works. It also rebuilds VOLUME_ONLY_CONCRETE_PARTS, which Tekla already works out for the whole cast unit in one call. Then it reached for WEIGHT_ONLY_REBARS. It sounds right. In the Tekla documentation it belongs to pour units, which are cast in place. A precast element is a cast unit, and its number is CAST_UNIT_REBAR_WEIGHT. On the wrong level a report property doesn’t throw. You get no value.

The agent writes correct code. You know which code shouldn’t exist.

Before CUSTOM.REINFORCEMENT_RATIO goes into a drawing table

  • Pick the level per property and turn every incoming id into it, in code.
  • Ratios climb, quantities don’t. A climbing quantity gets summed once per part.
  • Read Tekla’s own cast unit properties before you loop. Check which level each one belongs to.
  • Never throw, never show a dialog. It runs once per row. Return 0 and log to a file.
  • Deploy to extensions\custom\properties\, restart Tekla and look for the DLL in the session history log. Tekla locks it while it runs.

Lesson 12 builds this property on camera. You ask your agent for CUSTOM.REINFORCEMENT_RATIO, steer it off the volume loop and the pour unit weight, and write a deploy script so copying the DLL doesn’t cost tokens. The skill’s custom properties chapter carries the boilerplate for 2024 MEF and the 2025 attribute. Your attention goes on the level and the report properties.

Tekla Open API Course: build real Tekla tools with an AI agent →

Related: GetReportProperty in the Tekla Open API: types, units and the silent false · Tekla UDAs from C#: why GetUserProperty returns false (it’s not objects.inp) · Tekla TSEP packaging: build a .tsep with BatchBuilder

Tags

Greg Olszewski

Greg Olszewski builds Tekla Open API tools: Grasshopper Tekla Drawing Link, Smart Select, Tekla Lookup. Ten years of C# on Tekla Structures, day job in precast. Now he teaches engineers to build their own.

About Greg ›

COURSE

Build your own Tekla tools

Learn the Tekla Open API in C#, from your first plug-in to tools your team actually uses.

See the course ›