OpenSite/Concepts/Documents and identity

From BathAfrica Documentation
Revision as of 14:01, 29 October 2026 by BathAfrica (talk | contribs) (Publish professional OpenSite help structure and learning paths)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
OpenSite 0.0.1 · DevelopmentSource scope and availability

Use the right identity for the operation you are performing.

Four identities

Value Purpose Lifetime
Persistent document ID Identifies saved model content Survives save/reopen
Session handle Addresses an open document instance Valid only for that live session
Object ID Identifies an object inside a document Retained by document persistence
Name and label Unique lookup name and human-readable display label Different from the object ID

Read identity explicitly

import opensite

doc = opensite.execute("document.new", {})["document"]
created = opensite.material_create_user(doc, {
    "name": "Practice steel", "family": "steel", "role": "structural_steel",
    "has_elastic": True, "elastic_pa": 210.0e9,
    "has_poisson": True, "poisson": 0.28,
    "has_mass_density": True, "mass_density": 7850.0,
    "has_thermal": True, "thermal_per_k": 1.2e-5,
})
item = doc.get_object(created["id"])
print("Persistent document:", doc.identity())
print("Session handle:", doc.session)
print("Object ID:", item.id)
print("Internal name:", item.name)
print("Display label:", item.label)
assert doc.get_object(item.name).id == item.id
opensite.material_renumber(doc, item.id, 12)
assert doc.get_object(item.id).id == item.id

Transactions and files

An accepted edit publishes a consistent revision. Undo/redo are session history. Saving writes document data, not the undo stack. Reopening returns a new live handle; do not keep using a closed one.

Next lesson

Practise edit, undo, redo, save and reopen.