I want to be able to read out the MSL version number from an FMU using PyFMI. (The "description-strings" are comments but is part of the Modelica language see specification 3.5 section 2.2). The MSL version is found in the "description-string" for the package and the code is:
MSL/Modelica/package
package
within;
package Modelica "Modelica Standard Library - version 3.2.2"
extends Modelica.Icons.Package;
In PyFMi there is a way to read out "description-string" for variables using model.get_variable_description()
But this function is limited to variables and does not read documentation strings for packages, models, or blocks. There are many "get" functions but none seems appropriate, or is there?
An alternative solutions would be to in the user Modelica code be able to at import read out the "description-string" for the package and store that in a string constant (or parameter) and then just read that out from the FMU by the command model.get()
But how do you in Modelica read out a "description-string" from a package or model?
I think this information is not available in the FMU. At least Dymola does not write the MSL version to the modelDescription.xml
of an exported FMU. I suggest to check the modelDescription.xml
of your FMUs (the file is packed into the FMU; FMUs are zip files which can be extracted with archive programs like 7zip).
But it contains the field generationTool
:
generationTool="Dymola Version 2023 (64-bit), 2022-04-13"
Dymola ships always with a single MSL version, so you can guess the MSL version when you know the Dymola version.
Regarding your alternate solution: In Dymola class information can be retrieved with the ModelManagement library:
model GetMSLVersion
import ModelManagement.Structure.AST.Classes.{GetClassAttributes, ClassAttributes, GetAnnotationString};
import Modelica.Utilities.Streams.print;
// Get class description string
ClassAttributes atr = GetClassAttributes("Modelica");
String dscr = atr.description;
// Get version annotation
String version = GetAnnotationString("Modelica", "version");
initial equation
print(dscr);
print(version);
annotation(uses(ModelManagement(version="1.3")));
end GetMSLVersion;
The code above shows how to access the description string. Additionally, I obtained the version from the respective annotation, which is what I would recommend for your use case.