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

Trying to Use Python Script to Exclude Certain Objects from Build

Anonymous
2019-08-16
2019-08-20
  • Anonymous - 2019-08-16

    Originally created by: KP_Henrob

    Hello all,
    My goal is to have the same project be able to automatically decide which objects to include in a build based on what device its going to run on, or at least have an easy way to switch between possibilities. My first thought was to make a Python script that includes/excludes a pre-set list of objects in a build. I've been trying to use the .exclude_from_build property, however every object I've tried it on results in an error about it not having this attribute. After some research online, I saw someone used .build_properties before using .exclude_from_build, however tying this yields the same exact error.
    Is there something I'm doing wrong/not doing? Is this the right way to go about my goal in the first place? Any ideas are greatly appreciated.

    Codesys V3.5 SP12 Patch 1

     
  • mkeller - 2019-08-20

    Hi KP_Henrob.

    KP_Henrob hat geschrieben:
    Hello all,
    My goal is to have the same project be able to automatically decide which objects to include in a build based on what device its going to run on, or at least have an easy way to switch between possibilities. My first thought was to make a Python script that includes/excludes a pre-set list of objects in a build. I've been trying to use the .exclude_from_build property, however every object I've tried it on results in an error about it not having this attribute. After some research online, I saw someone used .build_properties before using .exclude_from_build, however tying this yields the same exact error.
    Is there something I'm doing wrong/not doing? Is this the right way to go about my goal in the first place? Any ideas are greatly appreciated.
    Codesys V3.5 SP12 Patch 1

    Here is some example code:

    proj = projects.primary
    for obj in proj.get_children(True):
        if obj.build_properties and obj.build_properties.exclude_from_build_is_valid:
            name = obj.get_name()
            print("Object '{}' supports exclude from build".format(name))
            if name == "MyFB":
                obj.build_properties.exclude_from_build = True
    

    BR
    Martin

     

Log in to post a comment.