Is there a way to automatically load libraries, change to a certain working directory, etc. when launching Dymola?
This method has been tested for Dymola 2017FD01. Prior versions used a different method via a setup.mos
script that is no longer available. As of this posting, there is no option to perform this actions via the Dymola GUI.
It can be easily accomplished via a .mos file with the steps shown below:
C:\Users\USERNAME\Documents\Dymola\startup.mos
.mos
file. For example, to load a library add openModel("C:\\Users\\USERNAME\\Documents\\ModelicaLibrary\\package.mo");
.mos
file change the current directory: cd("C:\\Users\\USERNAME\\Documents\\Dymola");
Properties
. Under Shortcut>Target
append "C:\Users\USERNAME\Documents\Dymola\startup.mos"
at the end. The contents of that cell should now look something like this: "C:\Program Files (x86)\Dymola 2017 FD01\bin64\Dymola.exe" "C:\Users\vmg\Documents\Dymola\startup.mos"
.mos
file should be carried out.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):
The question is slightly ambiguous - the other answer is quite good for one scenario. (The openModel call in Step 2 can be modified.)
However, if you always want to launch Dymola in a specific directory etc it is possible using the GUI in Dymola 2017 FD01 (and slightly differently from Dymola 2016 FD01):
If you want to "preload" libraries there are some options:
In a startup script you can use import MyPackage;
or openModel("...\\MyPackage.mo");
alternatively if you are administrator you could modify Dymola/insert/dymodraw.ini and add a line: Dymola5LibraryMenu "MyPackage"
(technically it doesn't "load" - it just shows the library in the package browser).
An important difference is that changing dymodraw.ini keeps the library "loaded" even after "Clear All".
In recent years there are two options that might help you.
File>Library Management>Install This dialog allows you to open a zip-file or something similar of a distributed library, install it, update MODELICAPATH to find it again, and even update the File>Libraries menu to include it for future use. All in one operation.
Simulation>Edit startup.mos If you prefer to edit the startup script, this is the convenient way to find it end open it for editing.
Here is a procedure which allows to load a set of libraries with one click.
It makes use of the fact that the dymola.exe
can be started with a .mos script as first argument.
It is designed for situations such as
The setup is a bit of work the first time, but very quickly done for further projects. You need:
start.mos
file in your libraryDYMOLA_WD
and MODELICA_LIBS
This is how start.mos
looks like for a specific project (usually you only change the first two lines):
// user setup
libs = {"Buildings 6.0.0", "PhotoVoltaics", "MyProject"}
wd = "myproject"
// open all libs
lib_dir = Modelica.Utilities.System.getEnvironmentVariable("MODELICA_LIBS");
lib_dir = Modelica.Utilities.Strings.replace(lib_dir, "\\", "/")
for l in libs loop
openModel(lib_dir + "/" + l + "/package.mo");
end for;
// change to wd
wd = Modelica.Utilities.System.getEnvironmentVariable("DYMOLA_WD") + "/" + wd;
wd = Modelica.Utilities.Strings.replace(wd, "\\", "/")
Modelica.Utilities.Files.createDirectory(wd)
cd(wd)
Now you create a shortcut to dymola.exe in the windows file explorer. In the field Target
you set
"C:\Program Files\Dymola 2020\bin64\Dymola.exe" "%MODELICA_LIBS%\MyProject\Resources\scripts\start.mos"
Assuming a user has set the environment variables
MODELICA_LIBS = E:\modelica
DYMOLA_WD = E:\dymola_wds
the folder structure on the users hard disk must look as follows for the script above to work:
E:\modelica
|- Buildings 6.0.0
|- package.mo
|- ...
|- PhotoVoltaics
|- package.mo
|- ...
|- MyProject
|- package.mo
|- ...
|- Resources
| |- scripts
| |- start.mos
|- ...
Now the dymola.exe-shortcut is used to start Dymola, which will automatically load the required libraries for the project and change the working directory.
For another project a new shortcut is required, along with a new start.mos
script.