Hello,
Do you have a simple example of how one can programmatically extend the model?
My model currently has part definitions and I would like to add their corresponding requirements to the model:
- I could generate .sysml files via a template but is there a way to create elements in the model using the SysIDE python API?
- How do associate the created requirement elements with the existing part definitions in the model?
Thanks!
Tom
Hi,
For namespace body elements you would use .children, e.g. creating a new owned attribute
membership, attribute = part.children.append(syside.FeatureMembership, syside.AttributeUsage)
# modify `attribute` as needed
For references, you would need to pass an existing element
membership, attribute = part.children.append(syside.Membership, attribute)
Generally, there are 3 common cases:
.append(<owning membership type>, <child type>) will create empty membership and child elements
.append(<owning membership type>, child) will create an empty membership and take ownership of child
.append(<relationship type>, element) will create an empty non-owning relationship with a reference to element
Relationships are currently only allowed to be constructed automatically as they rarely need to be modified. With dependent generics, this also catches related element type mistmatches statically (sadly, not supported by Python).
cst.syside.app has recently been updated to match field names with the API, e.g.
(Note general purpose target and source fields, these will be automatically updated with a given element on construction, e.g. using .append).
Common accessors for modifying the model include:
All mutable accessors are children of ChildrenNodes (multiple) and MemberAccessor (single). See Used in at the bottom of each type page for places where they are used.
These are distinct types to improve static type checking and type inference because Python does not support generics of higher-kind.