OpenModelica


Forgot password? | Forgot username? | Register

OMPython.run()

OMPython.run()

Dears,

I would like to find out how OMPython works since I am running test example I got this 

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win 32
Type "help", "copyright", "credits" or "license" for more information.
>>> import OMPython
>>> OMPython.run()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'run'
>>>


and by



from OMPython import OMCSession

OMPython = OMCSession()
2015-02-21 14:25:18,296 - OMCSession - INFO - OMC Server is up and running at file:///c:\users\r59400\appdata\local\temp\openmodelica.objid.3227f5e8bc9f47df965e415f12a08a2a
INFO:OMCSession:OMC Server is up and running at file:///c:\users\r59400\appdata\local\temp\openmodelica.objid.3227f5e8bc9f47df965e415f12a08a2a

OMPython.execute('getVersion()')
Out[6]: '"1.9.1 (r22929) (RML version)"\n'

OMPython.execute("loadModel(Modelica)")
Out[7]: True


but I can't run examples:


OMPython.execute("loadFile(\"C:\OpenModelica1.9.1\share\doc\omc\testmodels\BouncingBall.mo\")")
Out[10]: False

OMPython.execute("loadFile(\"C:\OpenModelica1.9.1\share\doc\omc\testmodels\dcmotor.mo\")")
Out[11]: False


any idea what's wrong or how OMPython to correctly use?


Thank you.

Best regards,
Peter

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OMPython.run()

You can always call

Code:

OMPython.execute('getErrorString()')

to check the error message.

I think your problem is the back slashes in the path. Either use double back slash (\\) or use forward slash (/).

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OMPython.run()

none of suggestions work.

OMPython.execute("loadFile(\\"C:\OpenModelica1.9.1\share\doc\omc\testmodels\BouncingBall.mo\\")")
  File "<ipython-input-46-83eba15eed46>", line 1
    OMPython.execute("loadFile(\\"C:\OpenModelica1.9.1\share\doc\omc\testmodels\BouncingBall.mo\\")")
                                  ^
SyntaxError: invalid syntax


OMPython.execute("loadFile(/"C:\OpenModelica1.9.1\share\doc\omc\testmodels\BouncingBall.mo/")")
  File "<ipython-input-47-bc6fc4e03811>", line 1
    OMPython.execute("loadFile(/"C:\OpenModelica1.9.1\share\doc\omc\testmodels\BouncingBall.mo/")")
                                 ^
SyntaxError: invalid syntax


and calling

OMPython.execute('getErrorString()')
Out[48]: '""\n'

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OMPython.run()

No. I said use slashes in the path not to escape quotes. Use this code below,

Code:

OMPython.execute('loadFile("C:/OpenModelica1.9.1/share/doc/omc/testmodels/BouncingBall.mo")') 

Adeel.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: OMPython.run()

running as a script
# test.py
import OMPython
cmds =
    ["loadModel(Modelica)",
    "model test end test;",
    "loadFile(\"C:/OpenModelica1.9.1/testmodels/BouncingBall.mo\")",
    "getIconAnnotation(Modelica.Electrical.Analog.Basic.Resistor)",
    "getElementsInfo(Modelica.Electrical.Analog.Basic.Resistor)",
    "simulate(BouncingBall)",
    "plot(h)"]
for cmd in cmds:
    answer = OMPython.execute(cmd)
    print "\nResult:\n%s"%answer


I was able to run it successfully

Thanks.

Peter

Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic