OMPython
OMPython copied to clipboard
create a model with OMPython
in OMEdit, I can create a blank model/class, then drag and drop blocks/components, and make connections between them, incrementally building a model. Can I use OMPython to similarly incrementally build a model from scratch by adding blocks/components and connections? something like
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
cmds = [
"newModel(getInstallationDirectoryPath() + "/share/doc/omc/testmodels/MyModel.mo")",
"addComponent(Modelica.Electrical.Analog.Basic.Resistor "R")",
"addComponent(Modelica.Electrical.Analog.Basic.Ground"gnd")",
"addConnection(R.n gnd.p)",
... until the model is complete
"translateModelFMU(MyModel)",
"simulate(MyModel)",
etc.
]
for cmd in cmds:
answer = omc.sendExpression(cmd)
print("\n{}:\n{}".format(cmd, answer))
i've read through
- https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/scripting_api.html
- https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html#enhanced-ompython-features
and nothing seemed to be obviously related to what i want to do.
using help(OMPython) i found this, is that related to what i want to do?
requestApi(self, apiName, entity=None, properties=None)
| # request to OMC
@albert-mathews I guess it is not possible to incrementally build a model in OMPython