butzen hat geschrieben:
I need a script to insert a POU below of Application object.
The Scripting API was extended with the necessary features with CODESYS V3.5 SP9. Look for IScriptIecLanguageObjectContainer and IScriptIecLanguageMemberContainer in the Scripting documentation.
butzen hat geschrieben:
I need too a script to edit a specific POU (MainPrg, for example), i.e., add new variables and modify code of POU.
We can only edit Structure Text directly. For the graphical languages you have to import the POU from PLCopenXML or our native format. See IScriptTextualObjectMarker, IScriptObjectWithTextualDeclaration, IScriptObjectWithTextualImplementation and IScriptTextDocument for the textual language and the methods import_xml() and import_native() from IScriptObject2 and IScriptProject2 for the import.
butzen hat geschrieben:
Finally is necessary deletar a specific POU.
Find the Scripting object, for example with find(), and use the method remove() to delete the object.
Here some example:
proj=projects.primaryfound=proj.find("Application", True)app=found[0]
\# CreateFBmypou=app.create_pou("MyPou")
\# ChangedeclarationoftheFBimplementation=mypou.textual_declaration.replace("""FUNCTION_BLOCK MyPouVAR_INPUT
  iValue : INT;END_VARVAR_OUTPUTEND_VARVAREND_VAR""")
\# ChangeimplementationoftheFBmypou.textual_implementation.replace("""iValue := iValue + 1;""")
\# AddmethodtoFBdosomething=mypou.create_method("DoSomething", "INT")
\# Changedeclarationofthemethoddosomething.textual_declaration.replace("""METHOD DoSomething : INTVAR_INPUT
  iVal1 : INT;
  iVal2 : INT;END_VAR""")
\# Changeimplementationofthemethoddosomething.textual_implementation.replace("""DoSomething := iVal1 + iVal2;""")
\# Findthepouanddeleteitfound=app.find("MyPou")iffoundandlen(found)==1:
  found[0].remove()else:
  print("POU 'MyPou' was not found"
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello team.
I need a script to insert a POU below of Application object.
I need too a script to edit a specific POU (MainPrg, for example), i.e., add new variables and modify code of POU.
Finally is necessary deletar a specific POU.
Thanks.
Émerson Butzen
Software Developer
Unisinos/Altus
Hi butzen.
The Scripting API was extended with the necessary features with CODESYS V3.5 SP9. Look for IScriptIecLanguageObjectContainer and IScriptIecLanguageMemberContainer in the Scripting documentation.
We can only edit Structure Text directly. For the graphical languages you have to import the POU from PLCopenXML or our native format. See IScriptTextualObjectMarker, IScriptObjectWithTextualDeclaration, IScriptObjectWithTextualImplementation and IScriptTextDocument for the textual language and the methods import_xml() and import_native() from IScriptObject2 and IScriptProject2 for the import.
Find the Scripting object, for example with find(), and use the method remove() to delete the object.
Here some example:
BR
Martin