Skip to content

Instantly share code, notes, and snippets.

@sjoelund
Created May 27, 2019 18:51
Show Gist options
  • Save sjoelund/7df830e1ea8be4b3032023518cf9542d to your computer and use it in GitHub Desktop.
Save sjoelund/7df830e1ea8be4b3032023518cf9542d to your computer and use it in GitHub Desktop.
import OMPython
omc = OMPython.OMCSessionZMQ()
assert(omc.sendExpression("loadModel(ModelicaTest)"))
assert(omc.sendExpression('setCommandLineOptions("-g=MetaModelica")'))
experiments = omc.sendExpression("list(cl for cl guard isExperiment(cl) in getClassNames(recursive=true))")
assert(omc.sendExpression('setCommandLineOptions("-g=Modelica -d=newInst")'))
s = ""
i = 1
for e in experiments:
s = s + (" %s class%d;\n" % (e,i))
i = i + 1
model = """model M
%s
end M;""" % s
assert(omc.sendExpression('loadString("%s")' % model))
assert(omc.sendExpression('saveTotalModel("total.mo", M)'))
clBefore = set(omc.sendExpression('getClassNames(recursive=true)'))
omc.sendExpression('clear()')
assert(omc.sendExpression('loadFile("total.mo")'))
clAfter = set(omc.sendExpression('getClassNames(recursive=true)'))
print("Classes not tested")
print("==================")
for cl in clBefore.difference(clAfter):
print(cl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment