You have to use textual_implementation and textual_declaration properties of IScriptTextDocument.
There are few methods like replace, insert, append and so on (see ScriptEngine.chm for more information).
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"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
Is it possible to write a simple Codefragment, something like "count := count + 1; etc.. " including creating the variable count over a Python Script?
I already have written a script which creates a POU (ST), but i can not find any topics about writing an application over a script.
Regards!
You have to use textual_implementation and textual_declaration properties of IScriptTextDocument.
There are few methods like replace, insert, append and so on (see ScriptEngine.chm for more information).