Tekla UDAs from C#: why GetUserProperty returns false (it’s not objects.inp)

Confession first: the myth this post is about was in my own course material.

The myth goes like this. You write a user-defined attribute from C#, you read it back, GetUserProperty returns false. Why? “The UDA isn’t declared in objects.inp.” It sounds right. I had it in one of my debugging episode scripts, it got copied into my notes from there, and my AI agent repeated it back to me twice before I traced it to the source.

objects.inp has nothing to do with it. Here’s what does.

objects.inp is for the dialog, not for the API

The Tekla Open API reads and writes any UDA by name. No declaration needed. objects.inp only controls the Tekla UI: which tab the attribute appears on, its label, its type in the dialog, its default value. It decides what people see. The API doesn’t care.

// No objects.inp entry anywhere. This works.
beam.SetUserProperty("MY_TOOL_CHECKED", "yes");
model.CommitChanges();

string value = "";
beam.GetUserProperty("MY_TOOL_CHECKED", ref value);   // true, value == "yes"

Declare it in objects.inp when people need to see or edit it in Tekla. Not because you think the API needs it.

The real reason: the type is whatever was written last

UDAs come in three types: string, double, int. No bool, no DateTime. A UDA’s stored type is simply the type of the last value written to it. Read it with a different overload and you get false, the same silent no that GetReportProperty gives you.

beam.SetUserProperty("WEIGHT_CHECK", 42.5);          // stored as double
model.CommitChanges();

string asText = "";
beam.GetUserProperty("WEIGHT_CHECK", ref asText);    // false: it's a double now

double asNumber = 0;
beam.GetUserProperty("WEIGHT_CHECK", ref asNumber);  // true, 42.5

This bites hardest when two tools share an attribute: one writes it, another reads it for a report or a drawing. Tool A writes "42.5" as a string, tool B reads it as a double and decides the attribute is missing. Nobody gets an error. Pick one type per UDA and stick to it. If it’s declared in objects.inp, use the type declared there.

One more reason for false, and a normal one: the UDA was never set on that object. A UDA that was never set doesn’t exist. It isn’t zero. So false means “not set, or wrong type”. Always check the bool.

Writing: CommitChanges, no Modify

Ordinary UDA writes don’t need Modify(). SetUserProperty writes straight to the object; model.CommitChanges() makes it stick. Calling Modify() on hundreds of parts just to save a UDA costs time and buys you nothing.

The one exception is OBJECT_LOCKED, which only takes effect after Modify(). More on that in Lock and unlock Tekla objects with OBJECT_LOCKED.

Reading many UDAs at once

When you need several attributes from each part, one call is faster than ten. GetAllUserProperties fills a Hashtable with every UDA, each boxed as its stored type. Check the key before you cast: a missing key gives null, and casting null to double throws.

var all = new Hashtable();
beam.GetAllUserProperties(ref all);

double check = all.Contains("WEIGHT_CHECK") ? (double)all["WEIGHT_CHECK"] : 0;
string fab   = all.Contains("FABRICATOR")   ? (string)all["FABRICATOR"]   : "";

Writing many UDAs at once

The getter gives you a Hashtable. The setter doesn’t take one. It takes six parallel lists: names and values for strings, doubles and ints. Pass empty lists for the types you don’t use.

beam.SetUserProperties(
    new List<string> { "FABRICATOR" },   new List<string> { "ACME" },   // strings
    new List<string> { "WEIGHT_CHECK" }, new List<double> { 42.5 },     // doubles
    new List<string>(),                  new List<int>());             // ints: none

model.CommitChanges();

The short version

  1. No objects.inp entry is needed for the API. It’s for the dialog.
  2. false means “not set on this object” or “wrong type”. Check the bool.
  3. One type per UDA, across every tool that touches it.
  4. Writes need CommitChanges(), not Modify(). Except OBJECT_LOCKED.
  5. Batch reads: check Contains before casting.

What I changed after finding it. A wrong rule in your notes gets copied once. A wrong rule in an AI agent’s instructions gets copied every time it writes code. So the UDA rules in the Tekla Open API skill my course members get are now checked against the API, not against my own scripts. In the course you write UDAs on real parts and verify every change before it reaches the model.

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

Related: GetReportProperty: types, units and the silent false · Lock and unlock Tekla objects with OBJECT_LOCKED

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 ›