Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

How to edit parameters of modelica model with OMPython

How to edit parameters of modelica model with OMPython

I want to edit modelica model parameters in Python CLI interface, But don't know how to find the correct method to make it.

Modelica model code :

model Syslam_Q5
  HePackage.Components.Hlam hlam(
    UCfile=
        "C:/Users/Pikachu/Docs/i_v2/H50.txt",
         A_HS_mod1 = 0.0786,
         CSize_flag=false,
         A_HS_mod2 = 0.0914,
         A_HS_mod3 = 0.0223,
         A_HS_mod4 = 0.0245)

Python code :

from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
cmds = [
    'loadFile("HePackage.mo")',   
    #'removeElementModifiers(HePackage.Systems.Syslam_Q5, "component", false)',
    'setElementModifierValue(HePackage.Systems.Syslam_Q5, HePackage.Components.Hlam, hlam.UCfile = C:/Users/Pikachu/Docs/i_v2/H100.txt)',
    #'setParameterValue(HePackage.Systems.Syslam_Q5, hlam.UCfile, $Code(=C:/Users/Pikachu/Docs/i_v2/H100.txt))',
    'saveModel("example_edit.mo", Example)',
    ]
for cmd in cmds:
    answer = omc.sendExpression(cmd)
    print(cmd, ':', answer)

In a folder i have around 10 text files, I want to run the modelica model for all the text files.
How to do that with Python interface.
Thanks

Edited by: Thamizh - Dec-28-21 09:09:23
There are 0 guests and 0 other users also viewing this topic
You are here: