How can I call an OpenModelica model in Python with OMPython?

后端 未结 3 1822
逝去的感伤
逝去的感伤 2021-02-15 23:27

I have an OpenModelica model made with OMEdit. In order to get a concrete example I designed the following:

\"OpenMo

3条回答
  •  日久生厌
    2021-02-16 00:12

    • Create one new folder in windows

    • In this folder put/create 2 new files file1.py and file2.bat

    • The file1.py content is:


    import os
    import sys
    sys.path.insert(0, "C:\OpenModelica1.11.0-32bit\share\omc\scripts\PythonInterface")
    from OMPython import OMCSession
    sys.path.insert(0, "C:\OpenModelica1.11.0-32bit\lib\python")
    os.environ['USER'] = 'stefanache'
    omc = OMCSession()
    omc.sendExpression("loadModel(Modelica)")
    omc.sendExpression("loadFile(getInstallationDirectoryPath() + \"/share/doc/omc/testmodels/BouncingBall.mo\")")
    omc.sendExpression("instantiateModel(BouncingBall)")
    omc.sendExpression("simulate(BouncingBall)")
    omc.sendExpression("plot(h)")`
    
    • the file2.bat content is:

    @echo off
    python file1.py
    pause
    
    • then click on file2.bat... and please be patient!

    The plotted result window will appear.

提交回复
热议问题