Deleting a function block

aoj
2011-10-25
2011-10-28
  • aoj

    aoj - 2011-10-25

    Hi hi,

    if I have a CoDeSys-Project with many function blocks, is it possible to delete 1 function block with a python-command?

    Thank you

     
  • Anonymous - 2011-10-27

    Originally created by: M.Schaber

    Hi, it is.

    You search the function block by its name, via the find() method of the project.

    Then you call the remove() method on the object.

    HTH,
    Markus.

    PS: Remind that find() returns a list of objects, not a single object, as there may be several objects with the same name in the tree.

     
  • aoj

    aoj - 2011-10-27

    Hi,

    thank you for the answer. I have tried this but it is not working. What I exactly want to do is deletding the POU(FB).

    Does that work with the same command?

    IMG: Unbenannt.JPG

     
  • Anonymous - 2011-10-27

    Originally created by: M.Schaber

    Hi,

    What exactly means "not working"? Do you get an error message? Or is the POU simply not deleted?

    I just tried a minimal version which works for me: It removes the first object with the name PLC_PRG.

    projects.primary.find("PLC_PRG", True)[0].remove()
    

    Please keep in mind that the text decorations displayed in the trees are not part of the name. So if the object is displayed as "POU (FB)" in the tree, the real name of the object is "POU". You have several ways to display the real name: If you click on the name of the object to rename it, you see "POU", the real name. Or if you open the "POU" in an editor, the editor tab displays the real name "POU". Or if you view the object properties (via context menu), or dump the object tree with an python script.

     
  • aoj

    aoj - 2011-10-27

    Hi,

    now it works. My mistake was, that I hade ('DeviceName', False).
    What do those False and True exactly mean or how do they influence the script?

     
  • Anonymous - 2011-10-27

    Originally created by: M.Schaber

    Hi,

    The second parameter indicates whether the search is recursive or not. Thus, project.find("foo", False) only finds top-level objects, whereas find("foo", True) searches deeper in the hierarchy.

    There's a second variant of the find() method which takes the path as list of strings. So you can find a specific application via a command like: ```

    proj.find('Foobar_Device', 'Plc Logic', 'Application')[0]

    ```

    Note that also objects have a find() method, so you can search inside a folder or an application by calling the find method on that object.

     
  • aoj

    aoj - 2011-10-28

    Hallo,

    I have a problem with starting CoDeSys from Python.

    I was trying to start CoDeSys with the following command:

    os.system(r'C:\3S CoDeSys\CoDeSys\Common\CoDeSys.exe --Profile="CoDeSys V3.4 SP4 Patch 1"')
    
    ``` but it did not work. So I found a solution and I started to use this command:
    

    os.system(r'C:\3S" CoDeSys\CoDeSys\Common\CoDeSys.exe --Profile="CoDeSys V3.4 SP4 Patch 1"')

    After downloading CoDeSys on a new PC, I changed the path of CoDeSys. So the Command looks now like that:
    

    os.system(r'C:\Program Files (x86)\3S CoDeSys\CoDeSys\Common\CoDeSys.exe --Profile="CoDeSys V3.4 SP4 Patch 1"')

    ```

    I have the same problem again. CoDeSys does not start! What could be the solution?

    Thank you and wishe u a nice weekend.

     
  • Anonymous - 2011-10-28

    Originally created by: M.Schaber

    Hi,

    The problem is that the path to the executable contains spaces. Simply adding double quotes around the command path seems not to work. This seems to be a problem in the windows implemenation of os.system or the underlying windows function.

    The solution is to add an additional pair of double quotes around the whole command string.

    os.system(r'""C:\Program Files (x86)\3S CoDeSys\CoDeSys\Common\CoDeSys.exe" --Profile="CoDeSys V3.4 SP4 Patch 1""')
    

    This looks weird, but it worked in my tests on Windows 7.

    Btw, I found the solutions at: http://stackoverflow.com/questions/2040 ... es-in-path m

     

Log in to post a comment.