Closed JS-Aibel closed 5 months ago
smc.namespace_element_sets
refers to the list of NamespaceSets
within the current Namespace
, so you're modifying the order of NamespaceSets
in that list, which doesn't make any difference.
Unfortunately, the order of SubmodelElements
within a SubmodelElementCollection
cannot be changed, as the elements are stored in a NamespaceSet
, which internally uses a python set
. These are unordered by design, the order in which they are iterated or displayed is arbitrary and cannot be influenced without changing the item. This is an intentional implementation design in the basyx-python-sdk, as the order of elements in a SubmodelElementCollection
is semantically meaningless.
Theoretically you could create a custom SubmodelElementCollection
, that uses an OrderedNamespaceSet
instead, where the order can be changed, but I don't really see the point in this. The better solution would be using a SubmodelElementList
, where the order is relevant by design, and which also makes use of the OrderedNamespaceSet
internally.
I'll close this issue for now. Feel free to reopen, if you still have questions.
Is it possible to rearrange SubmodelElements within a SubmodelElementCollection? In the Package Explorer one can move a property up or down in the hierarchy. Is this function possible with Basyx?
I have tried to move a property element from last to first with the following code without any luck.
smc.namespace_element_sets.insert(0, smc.namespace_element_sets.pop())