add library to library manager

Nina
2017-10-16
2017-10-23
  • Nina - 2017-10-16

    This example shows how to add a library to the library repository (even if the object is called "librarymanager") :
    https://help.codesys.com/api-content/1/codesys/3.5.11.0/de/cds-access-cds-func-in-python-scripts/

    repo = librarymanager.repositories[0]
    librarymanager.install_library(proj.path, repo, True)
    

    I want to add a library avalible in my librarymanager to the "real" library manager of the project. Also i need to access propertys of the librarys in my primary project e.g. last change, licence required, released.

    I would assume to have a list of librarys under projects.primary, but nothing.

     
  • mkeller - 2017-10-16

    Hi Nina.

    Nina hat geschrieben:
    I want to add a library avalible in my librarymanager to the "real" library manager of the project. Also i need to access propertys of the librarys in my primary project e.g. last change, licence required, released.
    I would assume to have a list of librarys under projects.primary, but nothing.

    It is the same as in the Navigator. You have to look for the objects which are Library Manager Objects short LibManObject. The Scripting objects, which are LibManObjects, return True for the property .

    Here some example code which prints the list of referenced libraries:

    proj = projects.primary
    objects = proj.get_children(recursive=True)
    for candidate in objects:
       if candidate.is_libman:
          for libref in iter(candidate):
             if libref.is_placeholder:
                print "placeholder: %s: %s => %s" % (libref.name, libref.default_resolution, libref.effective_resolution)
                params = libref.parameters
                for name in params:
                   print "   param: %s => %s" % (name, params[name])
             elif libref.is_managed:               
                print "library: %s: %s" % (libref.name, libref.managed_library.version)
             else:               
                print "library: " + libref.name
    

    BR
    Martin

     
  • Nina - 2017-10-17

    Thanks Martin for your quick replay.

    Actually this wasn't working for me as candidate.is_libman returns the library manager in POU but not the one in Device/Application/library manager.
    However, I tried to take you example and get it working, but Libref still does not provide me the properties I would expect:

    from __future__ import print_function
    Objects=projects.primary.get_children()
    for Device in Objects:
       if Device.is_device:
          for PlcLogic in Device.get_children():
             if PlcLogic.get_name() == 'Plc Logic':
                for App in PlcLogic.get_children():
                   if App.is_application:
                      LibMan=App.get_library_manager()                     
                      for Libref in LibMan.references:
                         if Libref.is_placeholder:
                            print("placeholder: %s: %s => %s" % (Libref.name, Libref.default_resolution, Libref.effective_resolution))
                            params = Libref.parameters
                            for name in params:
                               print("   param: %s => %s" % (name, params[name]))
                         elif Libref.is_managed:               
                            print("library: %s: %s" % (Libref.name, Libref.managed_library.version))
                         else:               
                            print("library: " + Libref.name)
    

    Nina hat geschrieben:
    Also i need to access propertys of the librarys in my primary project e.g. last change, licence required, released.

    Nina

    IMG: 1.JPG

     
  • mkeller - 2017-10-17

    Hi Nina.

    Nina hat geschrieben:
    Actually this wasn't working for me as candidate.is_libman returns the library manager in POU but not the one in Device/Application/library manager.

    My example works but it does not say which part of the output belongs to which LibManObject.

    Nina hat geschrieben:
    Also i need to access propertys of the librarys in my primary project e.g. last change, licence required, released.

    The information from your screenshot is in the "Project Information" object of the library itself.

    See the chapter "Example: Manipulation of the object Project information" in our documetation if the library/project is loaded and you want to access the project information.

    The libraries, which are referenced by the LibManObjects, are automatically loaded after the primary project is loaded. So you can go through the list of loaded projects and look for the projects which are a library.

    Here my example for printing the paths of the loaded projects:

    for proj in projects.all:
       print("Project Handle: {} IsLib: {} Path: {}".format(proj.handle, proj.library, proj.path))
    

    BR
    Martin

     
  • Nina - 2017-10-20

    Thanks, that's working!

    Just a comment to the referred documentation: The impotent link "API Reference Documentation for the ScriptEngine" isn't working.

    Nina

     
  • mkeller - 2017-10-23

    Hi Nina.

    Nina hat geschrieben:
    Just a comment to the referred documentation: The impotent link "API Reference Documentation for the ScriptEngine" isn't working.

    We know and have an entry in our bug tracking but you can use the CHM file "ScriptEingine.chm" in the sub directory "Online Help" or in the language specific sub directory below it.

    BR
    Martin

     

Log in to post a comment.