OpenSite/Guides/First document
Create a small rectangular-section document, change one dimension, undo and redo, then save and reopen it.
- Stable identifier
opensite.help.first-document
Prerequisites
A matching OpenSite development build. Run the complete example with the explicit development host because document.create_section uses document.edit. Use a practice document, not a live project.
Steps
Create the practice section
The example starts at 250 mm wide and 500 mm high. The stored lengths are 0.25 m and 0.50 m. This rectangle is a document-engine example, not a section-design or FEM workflow.
Change width and inspect the result
Change width to 300 mm using document.set_quantity. The height remains 500 mm and area changes from 0.125 to 0.15 m². Derived values are recomputed by the transaction.
Undo and redo
Undo restores the 250 mm width. Redo reapplies 300 mm. Compare values after each operation instead of relying on a visual redraw.
Save to a new location and reopen
The complete example creates a fresh temporary folder, prints its path, saves an .osdoc and opens it again. The filename extension is conventional; the writer format is version 4. Undo history is not stored.
Expected result
Area is 0.125 m² initially and 0.15 m² after the edit; undo restores width 0.25 m. The saved document reopens with area 0.15 m².
Limitations
This teaches document transactions and persistence. It does not validate a structural member or perform a design-code check.
Complete example
from pathlib import Path
from tempfile import mkdtemp
import opensite
created = opensite.execute("document.create_section", {
"label": "PracticeBeam",
"width": opensite.QuantityArgument(opensite.Q("250 mm"), "mm"),
"height": opensite.QuantityArgument(opensite.Q("500 mm"), "mm"),
})
doc, beam_id = created["document"], created["object"]
assert abs(doc.property(beam_id, "area").si_value - 0.125) < 1e-12
opensite.execute("document.set_quantity", {
"document": doc, "object": beam_id, "property": "width",
"value": opensite.QuantityArgument(opensite.Q("300 mm"), "mm"),
})
assert abs(doc.property(beam_id, "area").si_value - 0.15) < 1e-12
opensite.execute("document.undo", {"document": doc})
assert abs(doc.property(beam_id, "width").si_value - 0.25) < 1e-12
opensite.execute("document.redo", {"document": doc})
path = Path(mkdtemp(prefix="opensite-lesson-")) / "practice-beam.osdoc"
opensite.execute("document.save", {"document": doc, "path": str(path)})
reopened = opensite.execute("document.open", {"path": str(path)})["document"]
assert abs(reopened.property(beam_id, "area").si_value - 0.15) < 1e-12
print("Saved and reopened:", path)