eclipse-basyx / basyx-python-sdk

MIT License
61 stars 28 forks source link

Adding a SubmodelElementCollection to multiple Shells #258

Closed Kuchsn closed 7 months ago

Kuchsn commented 7 months ago

Hi! I'd like to ask your input on how to handle a set of repetitive data when creating a series of shells.

We created the submodel element collection "contact information", which will stay the same for all our products. Since we can't add one SMC to multiple AASs we presumably need to add it as reference, which we were unable to do so far.

    contact_information = ContactInformation.create(
        street=os.getenv("AAS_STREET"),
        zip=os.getenv("AAS_ZIP"),
        city_town=os.getenv("AAS_CITY"),
        national_code=os.getenv("AAS_NATIONAL_CODE")
    )
    nameplate = DigitalNameplate.create(
            str(identifier),
            uri_of_the_product=str(uri),
            manufacturer_name=str(element.xpath(xpaths['ManufacturerName'])[0]),
            contact_information=contact_information,
            manufacturer_product_designation=str(manuproddesi),
            year_of_construction=str(element.xpath(xpaths['YearOfConstruction'])[0]),
            manufacturer_article_number=str("4242")
        )
        class DigitalNameplate:
            @classmethod
            def create(cls, identifier: str, uri_of_the_product: str, manufacturer_name: str,
                       contact_information: SubmodelElementCollection, manufacturer_product_designation: str,
                       year_of_construction: str, manufacturer_article_number: str) -> Submodel:

               #....

        submodel.submodel_element.add(contact_information)

        return submodel
    aas = model.AssetAdministrationShell(
            asset_information=asset_information,
            id_=str(aas_identifier),
            id_short=aasx.NameFriendlyfier().get_friendly_name(myAAS.get_submodel_property_value(nameplate, "ManufacturerProductDesignation")),
            submodel={model.ModelReference.from_referable(nameplate)},
        )

        object_store.add(aas)
        object_store.add(nameplate)
Kuchsn commented 7 months ago

Is the ContactInformation SubmodelElementCollection intended to be freshly instantiated and copied in each of the Submodels?

s-heppner commented 7 months ago

As far as I know, there is at the moment no way to globally reference a SubmodelElementCollection (as in across multiple Submodels) within the model itself.

I therefore see multiple options:

However, if you want to use and follow a standardized submodel template, I'm afraid instantiating the SubmodelElementCollection each time anew is the only way to be compliant to the template. Programmatically you may want to have the contact information in one point only (single source of truth), but when you offer the AASs to the outside, you must give a copy each time.

I hope that helps.