- Index
- » Users
- » rJonatan
- » Profile
Posts
Posts
Hi again,
My new error comes when using the command translateModelFMU() via OMPython. Again this was something that ran succesfully before I updated the OpenModelica vesion. Now I get the following warning if I work through the OMShell:
translateModelFMU(x, fileNamePrefix="model")
"SimCode: The model x has been translated to FMU"
Warning: The initial conditions are not fully specified. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->OMCFlags, in OMNotebook call setCommandLineOptions("-d=initialization").
In this case the getErrorString() is empty. If I instead work through OMPython I get some information from getErrorString():
omc.sendExpression('translateModelFMU(x, fileNamePrefix="model")')
'SimCode: The model x has been translated to FMU'
>>> omc.sendExpression('countMessages()')
(4, 0, 4)
>>> omc.sendExpression('getErrorString()')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "OMPython\__init__.py", line 245, in sendExpression
answer = OMTypedParser.parseString(result)
File "OMPython\OMTypedParser.py", line 82, in parseString
return omcGrammar.parseString(string)[0]
File "C:\OCT-1.0rc1\Python27\lib\site-packages\pyparsing.py", line 1162, in parseString
raise exc
pyparsing.ParseException: Expected end of text (at char 192), (line:1, col:193)
Anyone who knows what may be causing this problem? And do you know why I get slightly different feedback depending on if I use OMPython or if I work directly in the OMShell? I've experienced this apparent inconsistency several times.
Best greetings!
Thank you very much for the feedback. I tried what you suggested and it worked as it should. I also got it to work in my script, perhaps I had to restart my IDE after doing setup.py in order for it to work.
Now I have another error though, so I may post again once I've looked into it.
Hi Adeel,
Thank you for the advice. I had tried installing OMPython via pip install, after the update of OpenModelica, but that didn't help me. I also now tried the setup.py install command that you suggested, but I still get the same error. The problem is not with creating an OMCSession object, the problem comes once I want to start executing commands. Any other ideas?
I updated to OpenModelica 1.11.0-32bit and now I have new problems with OMPython. First I got an ImportError: No module named omniORB. This I managed to bypass by adding to path "C:\OpenModelica1.11.0-32bit\lib\python". Now however I don't manage to run commands via OMCSession.sendExpression(). The example I run 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'] = 'jonatan'
omc = OMCSession()
answer = omc.sendExpression("loadModel(Modelica)")
print answer
The error I get is
File "C:/Users/jonat/workspace/sandbox/test_ompython.py", line 22, in <module>
answer = omc.sendExpression(cmd)
File "C:\OpenModelica1.11.0-32bit\share\omc\scripts\PythonInterface\OMPython\__init__.py", line 245, in sendExpression
answer = OMTypedParser.parseString(result)
File "C:\OpenModelica1.11.0-32bit\share\omc\scripts\PythonInterface\OMPython\OMTypedParser.py", line 82, in parseString
return omcGrammar.parseString(string)[0]
File "C:\OCT-1.0rc1\Python27\lib\site-packages\pyparsing.py", line 1162, in parseString
raise exc
pyparsing.ParseException: Expected {quoted string, starting with " ending with " | Combine:({["-"] {"0" | W:(1234...,0123...)} [{"." W:(0123...)}] [{W:(eE) W:(0123...,0123...)}]}) | Forward: ... | Group:({Suppress:("{") [Forward: ... [, Forward: ...]...] Suppress:("}")}) | Group:({Suppress:("(") [Forward: ... [, Forward: ...]...] Suppress:(")")}) | {Suppress:("SOME") Suppress:("(") Forward: ... Suppress:(")")} | "true" | "false" | {"NONE" Suppress:("(") Suppress:(")")} | Combine:(Forward: ...)} (at char 1), (line:2, col:1)
Before this command and similar was working fine, can someone help me with what changed?
By the way, I also saw that there are now new features of OMPython: https://openmodelica.org/doc/OpenModeli … interface. Does this perhaps mean that the old syntax is incompatible with new versions of OpenModelica?
Best regards,
Jonatan
OK, thank you ardpo!
I have another question about using OMPython. I use the command translateModelFMU, which according to the API returns the full path of the generated FMU. Does anyone know how I access this filename through OMPython? If I do
answer = omc.sendExpression('translateModelFMU(my_model)'),
I get a string:
SimCode: The model my_model has been translated to FMU.
But how do I get the path?
Ok, thank you sjoelund.se for the clarification!
Hi,
I'm trying to do scripting with OMPython, through the command OMCSession.sendExpression(). I wonder about the command getErrorString, see https://openmodelica.org/doc/OpenModeli … _api.html. According to the API this should return the error message and the user can choose whether or not to include warnings. However, what I get is all messages: Notifications, Errors and Warnings - even without setting warningsAsErrors = true. Have i misunderstood something or is this a bug?
What I am trying to achieve is to seperate warnings, errors and notifications - can someone advice me on how to accomplish this?
Best Regards!
- Index
- » Users
- » rJonatan
- » Profile