PVMT getting units

Is there any way to get the units of a property from the PVMT plugin in a way similar to how you would use get_p_v_value()?

I think you have NumericValue element you can get its Unit with:

myNumericValue.get_java_object().getUnit().getName()

Property value and PVMT definitions don’t have the concept of unit as far as I know.

image
image

So using P4C and PVMT we cannot obtain the assigned units to the property? We are only able to get the name of each property and the value of it when it is assigned to a certain component?

I don’t think this is what Yvan meant.

OK I see now :slight_smile:

There is no direct link between the PVMT definition (in the .vpd model) and the generated definition in the Capella model. The Capella model store the definition of property value in the PropertyValuePkg named EXTENSIONS under the Project (root element of the Capella model). The only way to match the PVMT definition and the EXTENSIONS definition is the naming of elements.
In your case under EXTENSIONS you will have:

  • PropertyValuePkg named PhysicalProperties
    • A PropertyValueGroup named Mass Extension
      • A FloatPropertyValue named Mass

This will match the structure in your .vpd model:

  • VpdRoot named PhysicalProperties
    • PropertyGroup named Mass Extension
      • FloatProperty named Mass

Then from the FloatProperty you can use the Java method getUnit() which returns a String:

myFloatProperty.getUnit()

I think the .vpd model should be loaded in the same resource set as the Capella model, you can check this with the following code:

for resource in se.get_java_object().eResource().getResourceSet().getResources():
    if resource.getURI().fileExtension() == 'vpd':
        print(resource.getURI())
        for root in resource.getContents():
            print('  - ' + root.toString())

If this output something, the root variable will reference the VpdRoot. Otherwise you will have to load the resource my yourself:

resource_set = org.eclipse.emf.ecore.resource.impl.ResourceSetImpl()
uri = org.eclipse.emf.common.util.URI.createFileURI("path_to_vpd_file")
resource = resource_set.getResource(uri, True)
root = resource.getContents().get(0)

Note you will have some error because PyDev don’t know about the Java world. You can ignore them or remove them form your editor. You can also use different kind of URI if needed (workspace, plugin, …) see the URI Java class for more details.