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

Library Categories using scripts

esskaey
2016-06-14
2016-07-12
  • esskaey - 2016-06-14

    Hello all,

    We are currently building and deploying container libraries with the help of scripts. But when the libraries are installed, they always fall under the miscellaneous category in the selected repository.

    We have the library category information in a libcat.xml file and this can be normally loaded by projectinformation-> LibraryCategories Dialog -> Add from description file / from other library and then choose the description file (libcat.xml). Is it possible to perform the same operation using scripts? .

    Any code snippet to perform the same will help a lot!

    Thanks in advance

    Regards,

    SK

     
  • mkeller - 2016-06-15

    Hi codesys_sig_forum.

    codesys_sig_forum hat geschrieben:
    We have the library category information in a libcat.xml file and this can be normally loaded by projectinformation-> LibraryCategories Dialog -> Add from description file / from other library and then choose the description file (libcat.xml). Is it possible to perform the same operation using scripts?

    You can use the library manager to get a list of all available categories or get the category by its Guid. Look for ILibManager in the Scripting API documentation.

    from System import Guid
    for lib in librarymanager.categories:
    Β  Β print("Lib: {} V{} Guid {}".format(lib.name, lib.version, lib.guid))
    caaLibCat = librarymanager.get_category(Guid("d2c47c8c-760e-440c-9147-4468a3c03edb"))
    assert(caaLibCat is not None, 'No such category')
    print("Guid of CAA library category: " + str(caaLibCat.guid)
    

    BR
    Martin

     
  • esskaey - 2016-06-17

    Dear Martin,

    Thank you for your quick response. Can you provide a similar code snippet to "SET" a library category using py scripts?.

    Thanks in advance

    Regards,

    SK

     
  • mkeller - 2016-06-20

    Hi codesys_sig_forum.

    codesys_sig_forum hat geschrieben:
    Thank you for your quick response. Can you provide a similar code snippet to "SET" a library category using py scripts?.

    Here some example code:

    from System import Guid
    caaLibCat = librarymanager.get_category(Guid("d2c47c8c-760e-440c-9147-4468a3c03edb"))
    assert(caaLibCat is not None, 'No such category')
    print("Guid of CAA library category: " + str(caaLibCat.guid))
    info = projects.primary.get_project_info()
    assert(info is not None, 'No project info')
    cats = info.categories
    if caaLibCat not in cats:
    Β  Β cats.Add(caaLibCat)
    Β  Β print('Added library category')
    print("Found lib categories:")
    for cat in cats:
    Β  Β print(cat.name)
    

    BR
    Martin

     
  • esskaey - 2016-07-11

    Hi Martin,

    Thank you for the code snippet. I performed the following steps:

    I) created a new library project (The error seems to occur more frequently with newly created library projects)

    II)I tried using the snippet, but I got the following ErrorException:

    "At least one element in the source array could not be cast down to the destination array type"

    Would be interesting to know why the elements in the array object (LibCategory object) are not of the same type or are empty. I have herewith attached the py script and the error message as attachments.
    Looking forward to your reply.

    Best Regards,

    SK

    IMG: VMware Workstation Categories Error.png

    TestCategories.py [233 Bytes]

     
  • mkeller - 2016-07-11

    Hi SK.

    codesys_sig_forum hat geschrieben:
    II)I tried using the snippet, but I got the following ErrorException:
    "At least one element in the source array could not be cast down to the destination array type"

    In which line of your code snippet does the exception happen?

    BR
    Martin

     
  • esskaey - 2016-07-11

    Hi Martin,

    In the method call (last line)

    "cats.Add(libcat)"

    Best Regards,

    SK

     
  • mkeller - 2016-07-12

    Hi SK.

    I tried your python script with CODESYS but there was no exception. For the moment we can only guess that the content of the project information object contains values for the library categories which we don't expect.

    Does the button Details of the dialog in the screenshot provide a CallStack? If yes, please add it here.

    BR
    Martin

     
  • esskaey - 2016-07-12

    Hi Martin,

    I have herewith attached a screenshot of the traceback for the error. The errors are shown in the SoMM Logic Builder environment.

    I attempted the same with the CoDeSys v 3.5sp 9, there were no error messages, but the script also did not add the library category to the project information object.

    Best Regards,

    SK

    IMG: 2016

    IMG: trace_callback.png

    TestCategories.py [277 Bytes]

     
  • mkeller - 2016-07-12

    Hi SK.

    codesys_sig_forum hat geschrieben:
    I attempted the same with the CoDeSys v 3.5sp 9, there were no error messages, but the script also did not add the library category to the project information object.

    CDS-50292 to our bug tracking, so it will be fixed eventually.

    codesys_sig_forum hat geschrieben:
    I have herewith attached a screenshot of the traceback for the error. The errors are shown in the SoMM Logic Builder environment.

    The additional information does not give me any further hints for the reason. Please contact the Schneider support for further help.

    BR
    Martin

     

Log in to post a comment.