CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sat Nov 18, 2017 3:48 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Oct 16, 2017 3:35 pm 
Offline

Joined: Wed Dec 10, 2014 12:57 pm
Posts: 19
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/

Code:
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.


Top
   
PostPosted: Mon Oct 16, 2017 5:26 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 220
Hi Nina.

Nina wrote:
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 is_libman.

Here some example code which prints the list of referenced libraries:
Code:
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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Tue Oct 17, 2017 3:56 pm 
Offline

Joined: Wed Dec 10, 2014 12:57 pm
Posts: 19
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:

Code:
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 wrote:
Also i need to access propertys of the librarys in my primary project e.g. last change, licence required, released.

Attachment:
1.JPG


Nina


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Tue Oct 17, 2017 5:11 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 220
Hi Nina.

Nina wrote:
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 wrote:
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:
Code:
for proj in projects.all:
   print("Project Handle: {} IsLib: {} Path: {}".format(proj.handle, proj.library, proj.path))


BR
Martin

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Fri Oct 20, 2017 9:30 am 
Offline

Joined: Wed Dec 10, 2014 12:57 pm
Posts: 19
Thanks, that's working!

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

Nina


Top
   
PostPosted: Mon Oct 23, 2017 7:54 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 220
Hi Nina.

Nina wrote:
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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited