Script String Transform

I am trying to do a simple transform script, but never used one before. I would like to do a string.title() and cannot get the syntax to work. I have a label that I have added a binding tag to. I saw that there is a add transform button with script as an option. What comes up is:

def transform(self, value, quality, timestamp):
return value

I have tried

def transform(self, value, quality, timestamp):
value = string.title()
return value

But it keeps erroring out.

def transform(self, value, quality, timestamp):
    return value.title()

Tip: see Wiki - how to post code on this forum.

It errors out because string doesn't exist. See how value is declared in the parameters ? That's why you can use value. It's the result of the previous "operation", in this case the binding. If you add a second transform after the first one, its value parameter will be whatever the first transform returned.
string, on the other hand, was never declared. So you can't use it.

Some tips:

  • errors message are important. They give information about what's wrong. Saying "there's an error" is rarely enough, you need to provide the error message, and maybe even the stack trace.
  • Jython is still jython, even inside of ignition. Ignition "only" provides functions for you to use, but you need to use them following the rules of jython. System Functions | Ignition User Manual
  • if you can, use expressions instead of scripts. expressions DO NOT use jython. They're not a programming language, but you can do many things with them without the overhead of a python interpreter. In this particular case, the built-in expressions are not enough, so you'll need to use a script transform... or use @pturmel 's integration toolkit (Automation Professionals' Integration Toolkit Module). It's a module that adds a bunch of functions, both to scripting and expressions. It makes a lot of things possible to do directly in expressions, that would otherwise require scripting.
  • go through the inductive university. It will teach you the basics of using ignition. https://www.inductiveuniversity.com/
3 Likes