CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sat Feb 16, 2019 11:20 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Oct 25, 2011 10:36 am 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 27
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 :)


Top
   
PostPosted: Thu Oct 27, 2011 9:14 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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.

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

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


Top
   
PostPosted: Thu Oct 27, 2011 12:49 pm 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 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).
Attachment:
Unbenannt.JPG


Does that work with the same command?


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


Top
   
PostPosted: Thu Oct 27, 2011 12:57 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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.
Code:
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.

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

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


Top
   
PostPosted: Thu Oct 27, 2011 1:50 pm 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 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?


Top
   
PostPosted: Thu Oct 27, 2011 2:16 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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:
Code:
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.

_________________
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 28, 2011 2:29 pm 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 27
Hallo,

I have a problem with starting CoDeSys from Python.

I was trying to start CoDeSys with the following command:
Code:
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:
Code:
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:
Code:
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. :)


Top
   
PostPosted: Fri Oct 28, 2011 3:17 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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.
Code:
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

_________________
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  [ 8 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


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:  
Powered by phpBB® Forum Software © phpBB Limited