OMPython icon indicating copy to clipboard operation
OMPython copied to clipboard

create a model with OMPython

Open albert-mathews opened this issue 1 year ago • 1 comments

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 avatar Mar 29 '23 20:03 albert-mathews

@albert-mathews I guess it is not possible to incrementally build a model in OMPython

arun3688 avatar Aug 17 '23 18:08 arun3688