OpenSite/Guides/Edit duplicate and renumber materials

From BathAfrica Documentation
Revision as of 14:00, 29 October 2026 by BathAfrica (talk | contribs) (Add rewritten practical lesson with steps, code and expected results)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
OpenSite 0.0.1 · DevelopmentSource scope and availability


Practise material edits, duplication, numbering and deletion without confusing an object ID with a display number.

Stable identifier
opensite.help.edit-duplicate-and-renumber-materials

Prerequisites

A new practice document. Do not use this deletion exercise on a live project.

Steps

Create a practice record

The complete example creates its own user material, so it does not depend on an existing model.

Edit Poisson ratio

Change ν to 0.30 through material_edit. Recomputed G is 210 GPa / 2.6, approximately 80.76923 GPa.

Duplicate and renumber

A duplicate receives a different object ID. Renumbering the original to 12 changes its material number and preserves its object ID.

Inspect usage before deleting

Read material_usage. The script deletes only the unused duplicate it created. In the desktop, use the material context menu: Edit, Duplicate, Show Users or Renumber.

Expected result

The original retains its object ID and has number 12. The duplicate has a distinct ID; after its removal one material remains.

Limitations

Material number, unique internal name and object ID serve different purposes. Removing a record used by other objects requires resolving its references first.

Complete example

import opensite

doc = opensite.execute("document.new", {})["document"]
values = {
    "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,
}
created = opensite.material_create_user(doc, values)
original_id = created["id"]
values["poisson"] = 0.30
opensite.material_edit(doc, original_id, values)
copied = opensite.material_duplicate(doc, original_id)
opensite.material_renumber(doc, original_id, 12)
assert copied["id"] != original_id
row = next(m for m in opensite.material_list(doc) if m["id"] == original_id)
assert row["number"] == 12
print("Object ID unchanged:", row["id"] == original_id)
print("Usage:", opensite.material_usage(doc, original_id)["count"])
# Delete only the unused duplicate created in this lesson.
opensite.material_delete(doc, copied["id"])
assert len(opensite.material_list(doc)) == 1