Syside Class Names
This example shows how you can use sexp function to print
the symbolic expression of the document to see what elements it contains and, most
importantly, names of the Syside Python classes.
Example Model
package Car {
part def Wheel {
doc /* This is a wheel*/
}
part wheels: Wheel[4] ordered;
}
Example Script
import pathlib
import syside
EXAMPLE_DIR = pathlib.Path(__file__).parent
MODEL_FILE_PATH = EXAMPLE_DIR / "example_model.sysml"
def main() -> None:
(
model,
diagnostics,
) = syside.load_model(paths=[MODEL_FILE_PATH])
# Only errors cause an exception. Syside may also report warnings and
# informational messages, but not for this example.
assert not diagnostics.contains_errors(warnings_as_errors=True)
for doc in model.user_docs:
# Since Syside is a multi-threaded application, we need to lock the
# document to ensure that the document is not modified from another
# thread while we are accessing it.
with doc.lock() as locked:
print("Model sexp:")
print(syside.sexp(locked.root_node))
if __name__ == "__main__":
main()
Output
Model sexp:
(Namespace
(OwningMembership
(Package Car
(OwningMembership
(PartDefinition Wheel
(Subclassification)
(OwningMembership
(Documentation))))
(OwningMembership
(PartUsage wheels
(OwningMembership
(MultiplicityRange
(Subsetting)
(OwningMembership
(LiteralInteger
(Subsetting)))))
(FeatureTyping)
(Subsetting))))))
Download
Download this example here.