[Python4Capella] - Create child for an enumeration literal

Hi everyone,
I am currently trying to create a child for an enumeration literal in PVMT from Python4Capella. The goal would be to create a background color for a certain enumeration literal.


To be clearer I’d like to do that manipulation but from a script and not manually.
I did not find any information related to this or if this is even possible.
Any answer would be helpful,
Thank you very much,
Maëva Murat

There is no Python API to work directly with the .vpd model but you can use Java API:

uri = org.eclipse.emf.common.util.URI.createFileURI('path_to_model.vpd')
rs = org.eclipse.emf.ecore.resource.impl.ResourceSetImpl()
r = rs.getResource(uri, True)
for myVdpRoot in r.getContents():
    print("VdpRoot", myVdpRoot.getName())
    for myEnumerationDefinition in myVdpRoot.getEnumerations():
        print("  ","EnumerationDefinition", myEnumerationDefinition.getName())
        for myEnumerationLiteral in myEnumerationDefinition.getLiterals():
            print("    ","EnumerationLiteral", myEnumerationLiteral.getName(), myEnumerationLiteral.getColor(), myEnumerationLiteral.getLabelColor())

To create a Color and set it to the EnumerationLiteral:

color_e_class = get_e_classifier("http://www.thalesgroup.com/vpd", "Color")
myColor = create_e_object_from_e_classifier(color_e_class)
myColor.setRed(100)
myColor.setGreen(100)
myColor.setBlue(100)
myColor.setAlpha(0)

myEnumerationLiteral.setColor(myColor) # or myEnumerationLiteral.setLabelColor(myColor)

You can finally save the resource:

r.save(java.util.HashMap())

Thank you very much for your answer, it worked perfectly !

1 Like