Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Modify GVL constant variable

dam
2016-03-14
2016-03-14
  • dam

    dam - 2016-03-14

    Hi,

    I would like to know if it is possible to modify a GVL constant variable via a python script?
    If true how can I achieve this?
    If false what should I use?

    In the meantime, is there a list of all available global variables in python like projects, online... ?

    Regards

     
  • mkeller

    mkeller - 2016-03-14

    Hi dam.

    dam hat geschrieben:
    I would like to know if it is possible to modify a GVL constant variable via a python script?

    You have to find the GVL object, which contains the variable(s) you want to change, and then you can either export, edit the XML and re-import the object or you can use the interface to modify the structured text (ST) of the declaration directly.

    The interface is documented in the CHM of the ScriptEngine, which you can find the OnlineHelp directory in the CODESYS base directory. All object which containt an ST based declaration and/or implementation, support the interface so you can check for it.

    BR
    Martin

     
  • dam

    dam - 2016-03-14

    I tried to do:

    ...
    gvl = project.find('GVL', True)[0]
    print(gvl.has_textual_declaration())
    

    but it failed as gvl is a ScriptObject.
    Any hint?

    Regards

     
  • dam

    dam - 2016-03-14

    To add more informations if I do:

    gvl.export_native("my_file", True)
    

    I got all the values of GVL but:

    gvl.get_children(True)
    

    returns an empty list.

    Regards

     
  • mkeller

    mkeller - 2016-03-14

    Hi dam.

    From your second post in this thread:

    print(gvl.has_textual_declaration())
    

    Please remove the brackets after because it is a property and not a method. This property is only to check if the object has an ST based declaration. You get the text with the property , e.g. gvl.text, and modify it with one of the methods, e.g. gvl.replace(modifiedDeclaration).

    From your third post:

    gvl.get_children(True)
    

    With you can only get the children of the object in the project structure. But variables are not children of the GVL object. You can only read or modify the ST based declaration.

    BR
    Martin

     
  • dam

    dam - 2016-03-14

    Indeed gvl.has_textual_declaration returns True but I do not have the text property.
    I am using SoMachine 4.1 so maybe the version of Codesys is too old?

    Regards

     
  • mkeller

    mkeller - 2016-03-14

    Hi dam

    Sorry, my fault.

    dam hat geschrieben:
    Indeed gvl.has_textual_declaration returns True but I do not have the text property.

    First you have to get the IScriptTextDocument object through the property (see interface IScriptObjectWithTextualDeclaration ) and than you can use or on that object.

    BR
    Martin

     
  • dam

    dam - 2016-03-14

    Thank you for the information and I confirm that it works with Codesys 3.5.7 but it does not work with SoMachine 4.1

    dam hat geschrieben:
    Indeed gvl.has_textual_declaration returns True but I do not have the text property.
    I am using SoMachine 4.1 so maybe the version of Codesys is too old?

    In fact, I was confused and I tested on Codesys 3.5.7 not on SoMachine 4.1. With SoMachine I do not have has_textual_declaration (it usesScriptEngine v3.5.3).
    Is it possible to update ScriptEngine to a newer version in SoMachine or use a different API?

    Regards

     
  • Anonymous - 2016-03-14

    Originally created by: M.Schaber

    Hi, Dam,

    dam hat geschrieben:
    Thank you for the information and I confirm that it works with Codesys 3.5.7 but it does not work with SoMachine 4.1
    In fact, I was confused and I tested on Codesys 3.5.7 on SoMachine 4.1. With SoMachine I do not have has_textual_declaration (it usesScriptEngine v3.5.3).
    Is it possible to update ScriptEngine to a newer version in SoMachine or use a different API?
    Regards

    Updating the ScriptEngine to a newer version cannot be done by a SoMachine enduser, this must be done by Schneider Electric.

    As far as I remember, Schneider also added some of their own extensions to the ScriptEngine, but I'm not sure whether that was for SoMachine or SoMachine Motion, and which version. I guess you need to ask the Schneider Support contact...

     
  • dam

    dam - 2016-03-14

    Ok thank you M.Schaber and M.Keller.

    Regards

     

Log in to post a comment.