Question

I have a custom package that I find myself reusing repeatedly in Dymola models, and I'd like to put this package in a common directory that is automatically loaded whenever I start Dymola. My current strategy is to load the custom package when a model I'm working on is loaded and then save total. This is not elegant because the contents of the custom package end up saved in multiple locations across my hard drive, and if I change one of them, the changes are not reflected everywhere. I would like a more robust way of distributing this custom package to all of my models. Is there a way to tell Dymola to automatically load my custom packaged every time?

Was it helpful?

Solution

The trick is to add the following lines to settings.mos in c:/Users/USERNAME/AppData/Roaming/Dynasim:

Utilities.setenv("MODELICAPATH", "C:\Users\USERNAME\Documents\Dymola");
openModel("c:\Users\USERNAME\Documents\Dymola\UserDefined\package.mo")

The first line adds the directory to the path that Dymola uses to search for packages that have not been loaded prior to the first run of a model, and the second line loads the specified package. These two commands may be somewhat redundant, but I am doing both because I want to make sure my custom packages are on the path in addition to loading the UserDefined package.

OTHER TIPS

Two suggestions. First, you need to add your package to the MODELICAPATH. You'll have to consult the Dymola documentation to figure out exactly what you need to do. But normally, what this means is that you have to set an environment variable that gives a list of directories (; separated) to be searched for your package. Now that will put it in your path so it can find it automatically, but it won't load it until it needs it.

If you want it to always appear in the package browser, you'll probably need to set up a .mos file (script) to load it. Dymola has that capability, but you'll have to read the manual to figure out what that script has to be called and where Dymola expects to find it.

I hope that helps.

In the instalation folder of Dymola 2018 -> insert -> dymola.mos I've added the lines:

Utilities.setenv("MODELICAPATH", "C:\Users\XXXX\Documents\Dymola");
openModel("C:\Users\XXXX\Documents\Dymola\DCOL\package.mo");
openModel(“C:\Users\XXXX\Documents\Dymola\Annex60 1.0.0\package.mo”);

Now I don't get the utilities sentence, as the DCOL package loads fine without it and the added 'utilities' package in the package menu is useless. But it does not open the Annex60 package.

I've tried a lot of different combinations and can't get multiple packages to load. I doubt that "cd" and "Advanced.ParallelizeCode", which are also added in the text work.

The accepted answer does not work since Dymola 2017 FD01, as the file settings.mos is not used anymore. User settings are stored in the setup.dymx file instead, located in

C:\Users\USERNAME\AppData\Roaming\DassaultSystemes\Dymola

In contrast to the setup.mos file you can not include custom lines with modelica script in setup.dymx.

The answer using dymola.mos still works, but you need admin privileges to modify this file.

Here is a simple solution which works with all Dyomola versions: You can pass a .mos-script as first parameter to the dymola.exe.

This can e.g. be done like this:

  • Create a .mos script somewhere with commands like openModel(), etc.
  • Create a desktop shortcut to Dymola.exe
  • Open the properties of the shortcut and add the path to the .mos script in the Target text field. It will then look something like this:

"C:\Program Files\Dymola 2018 FD01\bin64\Dymola.exe" "C:\<some-path>\startup.mos"

  • Start Dymola with the desktop shortcut. The script will be executed and eventual errors or messages are displayed in the Commands window

Another suggestion where you don't need to hardcode your package into an environment variable of your operating system (and maybe more safe for inexperienced programmers):

  1. Go to the folder where Dymola is installed (e.g. C:\Program Files\Dymola 2020).
  2. Search for the Dymola.mos file in the insert-folder. 'insert' folder
  3. Open the script (e.g., in notepad++)
  4. Add the link(s) to your Dymola-library-package.mo file(s) here with the openModel statement e.g., openModel("C:/IDEAS/package.mo"); Dymola.mos script
  5. Save the script. Now, every time you open Dymola, your libraries will be loaded automatically.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top