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:
# Raises if Syside reports errors, or with this flag warnings too.
# Syside may also report informational messages, but not for this
# example.
model = syside.load_model(paths=[MODEL_FILE_PATH], warnings_as_errors=True)
# The model holds its documents locked, so that no other thread
# modifies them while we are accessing them.
for doc in model.documents:
print("Model sexp:")
print(syside.sexp(doc.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 as class_names.zip.