Skip to content

OMPython using getParameterValue with sendExpression in a python script #54

Open

Description

@Laxaeus

I tried every command listed in the scripting API, everyone works except for getParameterValue:

when I type omc.sendExpression("setParameterValue(MyModel, param1, 2)") it replies: OK
(I already loaded the MyModel model first using loadModel with sendExpression)

when I type omc.sendExpression("getParameterValue(MyModel, param1)") it should reply "2" but instead it gives me a huge error:

File "", line 1, in
File "/home/user/.local/lib/python2.7/site-packages/OMPython/init.py", line 484, in sendExpression
answer = OMTypedParser.parseString(result)
File "/home/user/.local/lib/python2.7/site-packages/OMPython/OMTypedParser.py", line 109, in parseString
return omcGrammar.parseString(string)[0]
File "/home/user/.local/lib/python2.7/site-packages/pyparsing.py", line 1632, 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)

Am I doing something wrong or is my installation corrupted? Because any other command from the scripting API works just fine.

Thank you.

Activity

  1. thorade commented on Nov 22, 2017

    @thorade
    Contributor

    From the error message it seems you are using Python 2 on Linux!?
    Corba Session or ZMQ session? What OMC version?

    Could you also try the commands listed here?
    https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html#import-as-library
    These also results in an error for me.

    If you give the full script to reproduce your error then that script could be used for testing later.

    And a minor sidenote: your text will be more readable if you mark the error messages as code:
    https://guides.github.com/features/mastering-markdown/

  2. sjoelund commented on Nov 22, 2017

    @sjoelund
    Member

    You can also try with parsed=False to see what the raw string is. Usually this message appears when trying to parse an empty string (I think we should catch that and either return None or a better exception).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions