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

后端 未结 5 1854
遥遥无期
遥遥无期 2020-12-21 17:53

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

5条回答
  •  一向
    一向 (楼主)
    2020-12-21 18:30

    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.

提交回复
热议问题