Using Dymola, I'm looking for a way to automatically execute a script when loading a library. The intention is to define additional displayUnits
using the defineUnitConversion()
command, which are specific to the library that is loaded. Still I think there are quite some other cases where this could be helpful.
What I figured out in this regard:
DymolaInstallDir/insert/displayUnits.mos
but this comes with the disadvantage that is has to be done again on every new computer or after an update of Dymola. I would like to avoid this.libraryinfo.mos
file, which seems to be read during the start-up of Dymola. Therefore I assume it is not the right place to put the conversions, as it contains general information about the library and should only contain the respective functions.Dymola 2022 has a new (tool-specific) feature that covers exactly this use-case. It is mentioned in the Dymola 2022 release notes in the section "Library startup script" on page 24.
It basically introduces the a new annotation, which allows to specify a path to a .mos
script, which is executed, when the respective library is loaded. Here is the example from the release notes:
package ThisPack
annotation(__Dymola_startup =
"modelica://ThisPack/Resources/Scripts/Dymola/startup.mos");
end ThisPack;
The annotation can also be set via the UI...