How can we create a user defined function in Ignition
Inside a script library (most likely), add:
def hello():
print 'World'
If you want an answer that's more useful, you'll need to elaborate on your question.
As we have some in built script functions like Value changed, Quality changed, Alarm event etc in script editor, what we need to do to add a new function in scripting
You're describing event handlers. You can't add your own event handlers. What are you trying to do?
How can we access the script library..
I think you can find good explanation here in manual
Vision or Perspective?
You can find it in the project browser toward the top
How we need to use a created function inside a script..
Vision or Perspective?
...or something else?
Perspective
The script library is what you need to use.
Right click on Project Library and select new script. Give it a name that makes sense for all functions of a similar nature as the one being created. Then, create the function inside of it.
Example:
# Example function created in the libraryScripts script
def exampleFunction(exampleVariable, exampleOtherVariable):
# Do work here
exampleWork = sum(exampleVariable, exampleOtherVariable)
return exampleWork
Then, in Perspective, anytime this script is needed, it can be called in this way:
exampleVariable = # define this in some way
exampleOtherVariable = # define this in some other way
# Call the library script and the specific function within the script:
exampleResult = libraryScripts.exampleFunction(exampleVariable, exampleOtherVariable)
For more information on this topic, here is a link to the documentation:
Ignition Docs: Project Library