OpenSite/Guides/Exchange materials
Export a material set and import it into another document.
- Stable identifier
opensite.help.exchange-materials
Prerequisites
Two practice documents and the material API. This lesson uses an in-memory exchange string rather than overwriting a file.
Steps
Build the source material set
Create a user-defined material with explicit SI inputs.
Export and identify the format
material_export returns text containing opensite-material-exchange. This is a material exchange payload, not the full opensite-document file.
Import into a fresh document
Pass the exported text to material_import with the destination handle.
Verify the imported properties
List the destination materials and read the imported object’s elastic modulus. Check values, not equality of source/destination object IDs.
Expected result
The destination has one material and its elastic modulus is 210 GPa.
Limitations
Exchange does not copy geometry, undo history or the entire model. Do not assume identity values or numbering are portable between documents.
Complete example
import opensite
source = 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,
}
opensite.material_create_user(source, values)
payload = opensite.material_export(source)["text"]
assert "opensite-material-exchange" in payload
destination = opensite.execute("document.new", {})["document"]
opensite.material_import(destination, payload)
rows = opensite.material_list(destination)
assert len(rows) == 1
item = destination.get_object(rows[0]["id"])
assert abs(item.elastic_modulus.si_value - 210e9) < 1.0
print("Imported materials:", len(rows))
# This is a material exchange, not a copy of the whole source document.