In precast, once an element is released to production, its geometry is a promise. The mould gets set up, the reinforcement gets bent. If the element moves in the model after that, the model and the factory no longer agree.
Tekla has a Locked checkbox for exactly this. Ticking it by hand on a whole release is slow, and the one element you miss is the one that moves. So you look for part.Lock() in the Open API.
It isn’t there. Locking is a user-defined attribute.
OBJECT_LOCKED: an integer UDA with a special meaning
The Locked checkbox is stored in a UDA called OBJECT_LOCKED. Write it and Tekla treats the object exactly as if someone ticked the box.
| Value | Meaning |
|---|---|
1 | Locked. Tekla blocks modification. |
0 | Unlocked. |
| not set | Unlocked. This is the normal state of most objects. |
Lock the selected objects
using Tekla.Structures.Model;
using TSMUI = Tekla.Structures.Model.UI;
var model = new Model();
var selected = new TSMUI.ModelObjectSelector().GetSelectedObjects();
while (selected.MoveNext())
{
ModelObject obj = selected.Current;
obj.SetUserProperty("OBJECT_LOCKED", 1); // int, not "1" and not 1.0
obj.Modify(); // required for OBJECT_LOCKED
}
model.CommitChanges();
Unlocking is the same loop with 0.
It needs Modify(), unlike every other UDA
Ordinary UDAs don’t. You set them, you call CommitChanges(), done (see Tekla UDAs from C#). OBJECT_LOCKED is the exception: without Modify() the value is written but the lock doesn’t take effect. If your lock tool runs without errors and the parts are still editable, look here first.
It’s an int, and a wrong type reads as “unlocked”
Write it as 1, read it with the int overload. Read it into a string or a double and GetUserProperty returns false. And since “not set” also returns false, a wrong type quietly looks like “unlocked”. That’s the worst way for a lock check to fail.
int locked = 0;
obj.GetUserProperty("OBJECT_LOCKED", ref locked); // false when never set: stays 0
bool isLocked = locked == 1;
The report property with the same name can’t lock anything
Template Editor offers a content attribute called OBJECT_LOCKED too. That one is a read-only report property, a string, meant for reports and drawing tables. It’s handy for a “locked parts” report. It can’t change anything. To lock or unlock, you write the UDA.
Where it pays off
Lock everything that’s been released. Select it with a selection filter (by phase, or by a status UDA your team already uses), run the loop, done. Write two more UDAs next to the lock, who and when, and you’ve got a small audit trail. The next time someone asks why they can’t move a column, the model answers for you.
The whole recipe
- There’s no
Lock()method. Write theOBJECT_LOCKEDUDA. 1= locked,0or not set = unlocked.SetUserProperty, thenModify(), thenCommitChanges().- Use the
intoverload for both reading and writing. - The
OBJECT_LOCKEDreport property is read-only. Use it in templates, not to change state.
The AI part. Ask an AI agent to lock parts and it’ll happily invent a Lock() method. It compiles in the agent’s head, not in Visual Studio. OBJECT_LOCKED is one of the small rules in the Tekla Open API skill my course members get, so the agent writes the lock right the first time. In the course you build tools that change the model, and you learn to check every change before you trust it.
Tekla Open API Course: build real Tekla tools with an AI agent →
Related: GetReportProperty: types, units and the silent false · Tekla UDAs from C#: why GetUserProperty returns false
