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

mos file commands

mos file commands

Hello,

I am trying to translate or instantiate models using a .mos file.

The file is the following
loadModel(Modelica);

translateModel(DM_CIVAU7CIVAU1_NGU_SM); getErrorString();

I would like to retrieve all logs messages generated during this process as a string. I tried getMessagesString() but did not get any message. How could I do this ?

Besides, I would like to save the instantied model as a .mo file. The instantiateModel function generates a string, is there a way to generate a native .mo file ?

Thank you,

Re: mos file commands

Maybe you are looking for

Code:

.OpenModelica.Scripting.reopenStandardStream

. Therewith, you can redirect a certain standard stream to a file.

reopenStandardStream

Re: mos file commands

Ther getErrorString(); command should do what you want.
Please mind that the string that you get from this command refers to the last command you gave, thus it has to be run right after the translateModel command.


This works for sure


Code:

  simRes := translateModel(myModelTypeName);

  simulateMsg := getErrorString();
  print(simulateMsg); getErrorString();

you might also want to try

Code:

simRes := translateModel(myModelTypeName);

  errors:=getMessagesStringInternal();
 
  print("getMessagesStringInternal() returned \n"); getErrorString();
  print("Errors size is "+String(size(errors,1))); getErrorString();
  for err_sel in 1:size(errors,1) loop
    curErr := errors[err_sel];
    curErrMess := curErr.message;
    print(curErrMess); getErrorString();
  end for;

You can get myModelTypeName with searchClassNames(myModelName)

There are 0 guests and 0 other users also viewing this topic