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

Codesys Tools>Scripting> Excute script file

Rahied
2015-01-28
2015-01-28
  • Rahied - 2015-01-28

    is somting like this possible

    #!/usr/bin/env python
    # Years till 100
    import sys

    name = sys.argv[1]
    age = int(sys.argv[2])
    diff = 100 - age

    print 'Hello', name + ', you will be 100 in', diff, 'years!'

    Give this program a name of years.py, be sure to give it execute permission and then run it with the following command:

    ./years.py Joe 25

    Maybe this is a beter exsample what i try to build.

    import sys

    ProjectName = sys.argv[0]
    ProjectNumber = sys.argv[1]

    #ProjectName ="Frukar, Barendrecht"
    #ProjectNumber ="121079"

    #Vanaf deze regel hoef er niks meer worden aangepast of veranderd worden.
    #########################################################################################################################################################################################################
    #########################################################################################################################################################################################################
    #########################################################################################################################################################################################################
    # Clean up any open project:
    if projects.primary:
    projects.primary.close()
    print("--- CleanUp finished. ---")
    #########################################################################################################################################################################################################
    #########################################################################################################################################################################################################
    #########################################################################################################################################################################################################
    #Make the directory for the Automation department.
    ProjectPathAutomation ='4. Automation\2. PLC\1. CoDeSys\2. Project\'
    NewProjectName = ProjectName.replace(',', '')
    CreateProjectName = "%s
    %s" % (NewProjectName, ProjectNumber)
    AutomationPath = "L:\" + ProjectName + "\" + ProjectNumber + "\" + ProjectPathAutomation + CreateProjectName + ".project"
    PROJECT = r"" + AutomationPath
    print("--- The project create en save it on the next location : " + PROJECT + ".---")
    #Make the directory for the Electro department.
    ProjectPathElectro = '3. Elektro\2. PLC IO\'
    ElectroPath = "L:\" + ProjectName + "\" + ProjectNumber + "\" + ProjectPathElectro + "Import.txt"
    print("--- The next import location are by use :" + ElectroPath + ".---")
    #########################################################################################################################################################################################################
    #########################################################################################################################################################################################################
    #########################################################################################################################################################################################################
    # Import Path
    F = open(r"" + ElectroPath , "r")
    # Library Path
    L = open(r"C:\Codesys Python Script\Library Import.txt", "r")
    # Symbols Name Path
    S = open(r"C:\Codesys Python Script\Library Import.txt", "r")

     

    Related

    Talk.ru: 1
    Talk.ru: 2

  • Anonymous - 2015-01-28

    Originally created by: M.Schaber

    Currently, it is not possible to give parameters to scripts which are executed during the UI.

    We have an improvement CDS-42003 in our tracker to improve this (but it is not yet scheduled).

    However, it is possible to pass arguments to scripts which are executed via the codesys command line interface, see the online help for a description.

    Additionally, the script itsself can use system.ui methods to ask the user interactively for values like project names. I did attach a test script which shows the possible dialogs.

    System_UI_Test.py [2.75 KiB]

     

Log in to post a comment.