2

In a mos script, I want to save the current directory (i.e. the directory where the mos script is) to a string variable. In a second step, I want to open a library that is located in a directory net to the mos file.

I tried it like this:

myCWD = Modelica.Utilities.System.getWorkDirectory();

but this will always have the value C:\USERNAME\Documents\Dymola.

Is there a way to get the path of the mos file itself, from within the mos script? Or are there better ways to use relative paths, or construct absolute paths from a relative path (but always relative to the mos file)?

Priyanka
  • 559
  • 3
  • 13
  • related: https://stackoverflow.com/questions/41832589/how-to-add-load-libraries-change-directory-etc-on-startup – Priyanka Nov 21 '19 at 09:28

1 Answers1

2

cdreturns Dymolas working directory, so it works as expected. I don't know how to solve your problem with mos scripts, but in a Modelica function the Dymola built in function classDirectory() does what you want.

Here is a minimal example:

function myScript
algorithm 
  Modelica.Utilities.Streams.print(classDirectory());
end myScript;

Note that in Dymola functions can replace mos scripts in most cases. Usually you can simply copy your mos script content to the algorithm section of a function and call the function.

marco
  • 5,944
  • 10
  • 22
  • 1
    Maybe my approach was to complicated: What I want to achieve is to load a library from a relative path, so that I can put the load.mos file next to the library on SVN or git, and everybody checking out the repo can just double-click the load.mos file. Any ideas how that can be done? – Priyanka Nov 25 '19 at 07:13
  • 1
    I use this approach: https://stackoverflow.com/a/58378134/8725275 (one of the answers in the question you marked as related). The only trouble with that is, that all users have to define an environment variable. – marco Nov 25 '19 at 07:21