Scott G
Scott G

Reputation: 2310

How to add load libraries, change directory, etc. on startup?

Is there a way to automatically load libraries, change to a certain working directory, etc. when launching Dymola?

Upvotes: 3

Views: 4872

Answers (5)

Hans Olsson
Hans Olsson

Reputation: 12507

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. How depends on version.

Dymola 2020 x (and later) Allows changing start-up directory through File>Working Directory

And has Tools>Library Management>Modelica Path where you can add the directory containing your external libraries.

To make libraries appear preloaded you have to add a libraryInfo.mos script in the corresponding library; you can look at Modelica Standard Library in the Dymola installation for inspiration.

The latter is described in more detail in the section "More about libraries and the building of menus of libraries and demo" (somewhere in the User Manual).

Dymola 2017 FD01 (and slightly differently from Dymola 2016 FD01):

  1. Change Directory (File>Change Directory)
  2. Add to Modelica Path (File>Modelica Path)
  3. Save those settings (Edit>Options>Settings: Select Startup and Modelica Path)

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".

Upvotes: 4

marco
marco

Reputation: 6655

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

  • You are using Windows
  • You are working on one or more projects
  • Where every project requires a set of libraries to be loaded
  • Every project uses it's own working directory
  • Other users might collaborate, so they need the very same setup

Requirements

The setup is a bit of work the first time, but very quickly done for further projects. You need:

  • a start.mos file in your library
  • the environment variables DYMOLA_WD and MODELICA_LIBS
    (This is only required to allow other users to use different paths for their libraries and working directories)
  • a file short-cut to dymola.exe

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"

Example

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.

Upvotes: 2

Dag B
Dag B

Reputation: 759

In recent years there are two options that might help you.

  1. 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.

  2. 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.

Upvotes: 2

Matthi9000
Matthi9000

Reputation: 1227

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.

Upvotes: 1

Scott G
Scott G

Reputation: 2310

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:

  1. Create a .mos file in a location that makes sense. For example, C:\Users\USERNAME\Documents\Dymola\startup.mos
  2. Add the actions desired to .mos file. For example, to load a library add openModel("C:\\Users\\USERNAME\\Documents\\ModelicaLibrary\\package.mo");
  3. Dymola always puts its auto-generated files in the current working directory. It's often a good idea to have that location be the same location so there is no need to hunt down the location of output files. Therefore, at the end of the .mos file change the current directory: cd("C:\\Users\\USERNAME\\Documents\\Dymola");
  4. If no shortcut exists to the Dymola.exe file, then create one.
  5. Right click the shortcut and go to 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"
  6. That's it. When Dymola is launched from that shortcut the actions specified in the .mos file should be carried out.

Upvotes: 1

Related Questions