You can find a UUID of an element using Syside Automator: Element SysML
However, I’d like to stress that textual notation has no standardized way to assign stable UUIDs to elements. Syside handles this with the same mechanism that the standard library uses: the UUID is generated at parse time and, for stability reasons, the fully qualified name (and its path) is used as a “seed”. This means that if you rename the element, or move it into another package, the UUID will change.
If you really care about each element having a stable ID, we’d recommend using metadata annotations in that case. That’s exactly what we do in our ReqIF implementation: each element that is supposed to be exchanged over ReqIF carries a @reqif tag with an id attribute inside of it. Our ReqIF CLI also has a lock command that finds all @reqif tags without set IDs and generates a random UUID for it, so that humans don’t need to write out IDs manually. You could implement something similar trivially.
Not something out-of-the-box, and this is more of a process question. You could set up a rule in your company that says “any modifications to UUIDs means that the merge request will not be merged”. You could also write some Python scripts that check if any such “identifier” field changes appear in your git diff and automatically fail your CI/CD pipelines.
No, for performance reasons they are computed lazily since they are very rarely needed.
In addition, to prevent poor performance scaling from computing IDs lazily for a bunch of elements, they can be precomputed using precompute_element_ids linearly in the number of elements. Compared to computing each element separately which needs to collect all ancestors and potentially perform a search for its index.
With how this is written now, child is not one element, but a tuple of [MembershipImport | NamespaceImport | Membership, Element]. If you only care about the element, you should instead do
for child in element.children.elements:
We strongly recommend using some static type-checker when writing Python code. I use Pylance (on “strict” mode), and VSCode shows me the following error on your code when trying to access cst_node on the tuple, showing that I might be doing something wrong. After adding the .elements in the for loop, the error goes away.
Cannot access attribute "cst_node" for class "Tuple[MembershipImport | NamespaceImport | Membership, Element]"
Attribute "cst_node" is unknown
Using cst_node in general should be avoided. While this works for models that are parsed from .sysml files, the script would fail if you were to use it against a model that was loaded from SysMLv2 JSON (e.g. from a model server over the REST API).
Instead, you should use try_cast(), like so:
if child.try_cast(syside.MetadataUsage):
print(f"{child}")
As Daumantas mentioned, there is also a metadata method to make it easier/cheaper to extract only metadata. In your case, code would simplify to:
for metadata_child in element.metadata.collect():
print(f"{metadata_child}")