1
votes

checkmodel([Some Model]) opens the GUI "Dymola Messages", tab "Translation" and displays Errors, Warnings, and Messages.

Does anyone know how to write these infos to a logfile or get them as kind of return value of checkModel(). All I've found in the documentation was, that checkModel() only returns a success-boolean. Are these infos saved temporarily somewhere?

Note, that I only want to apply checkModel() but not actually translating the code.

2

2 Answers

2
votes

I finally found a solution at least for Dymola 2016 and newer, so if someone is interested - here it is (it is not very user-friendly, but it works):

The key-command is getLastError() which not only returns the last error (as one could think...), but all errors that are detected by checkModel() as well as the overall statistics.

All informations are sampled in one string, in which the last lines looks like:

"[...]
Local classes checked, checking <[Some Path]>
ERROR: 2 errors were found
WARNING: 13 warnings were issued
= false
"

Following operations will return the number of actual errors (for warnings it is more or less the same):

b = checkmodel([Some Model])
s = getLastError()
ind1 = Modelica.Utilities.Strings.findLast(s,"ERROR:")
ind2 = Modelica.Utilities.Strings.findLast(s," errors were found")
nErrors = Modelica.Utilities.Strings.substring(s,ind1+6,ind2) //6 = len(ERROR:)
nErrors = Modelica.Utilities.Strings.replace(nErrors," ","")
nErrors
  = "2"

Note:

  1. I used findLast as I know, that the lines of interest are at the very end of the string. So this is significantly faster than using find
  2. This only works, if the line "ERROR: ...." actually exists. Otherwise, the substring call will throw an error.
  3. Of course this could be done in less lines, but maybe this version is easier to read.

NOTE: This will only works with Dymola 2016 and newer. The return-string of getLastError is of a different structure in Dymola 2015 and older.

1
votes

The following should handle it: clearlog(); // To start fresh
Advanced.TranslationInCommandLog=true; checkModel(...); savelog(...);

This is mentioned in the Dymola User Manual Volume 1, section "Parameter studies by running Dymola a number of time in “batch mode”" on pg 630 or so.