You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to plot results using the ModelicaSystem API, but the plot window is not shown.
This is on Windows, using OMPython master and a recent OM nightly(OpenModelica v1.18.0-dev.beta1 (64-bit)).
Based on examples from the documentation, using the omc API works, it shows a plot window (the sleep is just there so that the window does not immediately disappear when the script is finished):
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
cmds = [
'loadFile(getInstallationDirectoryPath() + "/share/doc/omc/testmodels/BouncingBall.mo")',
"simulate(BouncingBall)",
"plot(h)"
]
for cmd in cmds:
answer = omc.sendExpression(cmd)
print("\n{}:\n{}".format(cmd, answer))
from time import sleep
sleep(5)
Doing the same thing (I hope?!) with the ModelicaSystem API does not show a window:
from time import sleep
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
model_path=omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
from OMPython import ModelicaSystem
mod=ModelicaSystem(model_path + "BouncingBall.mo","BouncingBall")
mod.simulate()
print('now plot ')
mod.sendExpression('plot(h)')
print(mod.requestApi('getErrorString'))
print('done, now sleep')
sleep(5)
output (notice: nothing in the error string):
LOG_SUCCESS | info | The initialization finished successfully without homotopy method.
LOG_SUCCESS | info | The simulation finished successfully.
now plot
done, now sleep
I tried to find out what's going wrong, but couldn't find anything.
@bilderbuchi the ModelicaSystem() API uses a different approach to produce the simulation results, it basically builds the model first and then simulate() API uses the simulation executable to produce the result file and the result file is not stored insendExpression() when using ModelicaSystem() API, so inorder to use the plot() API with ModelicaSystem() we have to explicitly specify the result file to the plot() API some thing like below
mod=ModelicaSystem(model_path + "BouncingBall.mo","BouncingBall")
mod.simulate()
print('now plot ')
mod.resultfile ### this will show you the resultfile location
mod.sendExpression("plot(h, fileName=\"BouncingBall_res.mat\")")
The above will work
And We can also add a new API, plot() to ModelicaSystem() API which automatically loads the the result file and plots the result in OMPlot and you can directly call mod.plot() something like below
ah, so there is some hidden state created when using the omc simulate() function, that plot() needs? I did not know that.
In any case, I find it useful that ModelicaSystem uses the exe, this way one can easily re-simulate/override without rebuilding.
Thank you for your suggestion, this works! Sorry, this was not obvious to me.
By the way, you can mix ' and " in Python strings which is useful in case you need to have strings with quotations marks, you don't need escapes:
Yeah, a new method plot() that mirrors the OMC plot signature for flexibility, and just uses the resultfile if no fileName argument is given, could be useful.
Same actually for a getError() method -- that would be quite useful because you have to do that sooo often when interacting with omc. 😀
This also could reduce a lot of duplication in the OMPython ModelicaSystem code, there's lots of ..."getErrorString"... strewn around...
@bilderbuchi would you like to test out the new plot interface? Please check and close the issue.
Yeah, I would. However, I found that the current version on pypi (4.0.1) does not have this fix, yet (as could be expected a posterior :-P).
Then I tried to install the version from my OM installation, but was unable to locate it.
@bilderbuchi would you like to test out the new plot interface? Please check and close the issue.
Yeah, I would. However, I found that the current version on pypi (4.0.1) does not have this fix, yet (as could be expected a posterior :-P). Then I tried to install the version from my OM installation, but was unable to locate it.
Activity
arun3688 commentedon Aug 16, 2021
@bilderbuchi the
ModelicaSystem()API uses a different approach to produce the simulation results, it basically builds the model first and thensimulate()API uses the simulation executable to produce the result file and the result file is not stored insendExpression()when usingModelicaSystem()API, so inorder to use theplot()API withModelicaSystem()we have to explicitly specify the result file to theplot()API some thing like belowThe above will work
And We can also add a new API,
plot()to ModelicaSystem() API which automatically loads the the result file and plots the result in OMPlot and you can directly callmod.plot()something like belowbilderbuchi commentedon Aug 16, 2021
ah, so there is some hidden state created when using the omc
simulate()function, thatplot()needs? I did not know that.In any case, I find it useful that ModelicaSystem uses the exe, this way one can easily re-simulate/override without rebuilding.
Thank you for your suggestion, this works! Sorry, this was not obvious to me.
By the way, you can mix
'and"in Python strings which is useful in case you need to have strings with quotations marks, you don't need escapes:Yeah, a new method
plot()that mirrors the OMC plot signature for flexibility, and just uses the resultfile if nofileNameargument is given, could be useful.Same actually for a
getError()method -- that would be quite useful because you have to do that sooo often when interacting with omc. 😀This also could reduce a lot of duplication in the OMPython ModelicaSystem code, there's lots of
..."getErrorString"...strewn around...[ModelicaSystem] add plot() function; see OpenModelica#144
[ModelicaSystem] add plot() function; see OpenModelica#144
[ModelicaSystem] add plot() function; see OpenModelica#144
[ModelicaSystem] add plot() function; see OpenModelica#144
[ModelicaSystem] add plot() function; see OpenModelica#144
[ModelicaSystem] add plot() function (#352)
syntron commentedon Jan 29, 2026
@adeas31 based on PR #352, I think this issue can be closed
adeas31 commentedon Jan 30, 2026
@syntron I will let @bilderbuchi test this and then we can close this issue.
@bilderbuchi would you like to test out the new plot interface? Please check and close the issue.
bilderbuchi commentedon Apr 23, 2026
Yeah, I would. However, I found that the current version on pypi (4.0.1) does not have this fix, yet (as could be expected a posterior :-P).
Then I tried to install the version from my OM installation, but was unable to locate it.
but frustratingly do not tell you what
OMPythonPathis..bilderbuchi commentedon Apr 23, 2026
OK, this fails, apparently the API of ModelicaSystem has changed in the meantime. A lot.
Anyway, I managed to create a plot:
This can be closed, thank you for the fix!
adeas31 commentedon Apr 24, 2026
Yeah OMPython is not part of OM since a long time now. You need to clone the repo and
OMPythonPathmeans path where you cloned the repo.Perhaps you can propose what we can change in the README from a user's perspective.
cbu-hw commentedon Apr 24, 2026
Probably it's fine, and this is only a problem of an
oldexperienced user...new people won't remember to search within OM. ;-)