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
  • Index
  • » Users
  • » Stefanache
  • » Profile

Posts

Posts

Jul-21-17 16:10:02
Questions about using the scripting API via OMPython

as example you can see this sample for Windows

-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!

must apear the plotted result window

  • Index
  • » Users
  • » Stefanache
  • » Profile
You are here: