Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Set dynamic model path in .mos file

Set dynamic model path in .mos file

Hello,

i want to generate an FMU file from a model.mo which is located in the same folder.

The folder is part of a git repository, which has many users, so the absolute path changes.

The .mos file works, but it draws the model.mo from the default path Openmodelica/lib/omlibrary

My File is

Code:


loadModel(grid); getErrorString();
setCommandLineOptions("-d=newInst"); getErrorString();
setCommandLineOptions("-d=initialization"); getErrorString();
setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
setCommandLineOptions("-d=-disableDirectionalDerivatives"); getErrorString();
translateModelFMU(grid.network); getErrorString();

According to https://openmodelica.org/forum/default- … ndline-use , i should be able to set an absolute model path directly as a string in the loadModel("C:\Users\myname\PycharmProjects\projectName/grid.mo"); but even this doess not work, i just receive the error (translated) Class loadModel could not be found in the aim area (global scope).


Can anyone give me the right command line to load the model directly from the current directory from where the .mos file is called? Would be awesome :-)

Best regards

Henrik

Re: Set dynamic model path in .mos file

If your model.mo is located in the same directory where the .mos file is then you can call,

Code:

loadFile("model.mo")

instead of

Code:

loadModel(grid)

Adeel.

Re: Set dynamic model path in .mos file

If you want to see slightly better error-messages, call

Code:

OpenModelica.Scripting.loadModel("xxx"); getErrorString()

Code:

[model.mos:1:1-1:39:writable] Error: Failed to elaborate "xxx" as a code expression of type OpenModelica.Code.TypeName.

Re: Set dynamic model path in .mos file

Works perfectly, thank you :-)

There are 0 guests and 0 other users also viewing this topic
You are here: