Create tag with valueChange event logic in it through scripting

I would like to create a memory tag which has some code in valueChanged event through scripting. I know we can use system.tag.addTag function to create a tag automatically. But I was not able to figure out if we can use same function to add code in tag events. Creating UDT instance could be one possibility but I want to check this possibility.

  • Does anyone tried this before or has any idea, please share.
  • Also can we create UDT definition through function?

I am using Ignition v7.9.16.
Thanks in advance.

This is possible, though poorly documented.

You will need to do something like this:

from com.inductiveautomation.ignition.common.sqltags.model import TagProp
from com.inductiveautomation.ignition.common.sqltags.model.scripts import BasicTagEventScripts

newProp = BasicTagEventScripts()
newProp.set('valueChanged',"	x=1 \n	if x==1:\n		print 'This Worked'",True)

Thanks a lot @lrose. This is very helpful.

@lrose Can we also create UDT through scripting?

I believe that you can use addTag to create a UDT instance tag, but I don’t believe you can use it to build a UDT definition. I haven’t tried to create a UDT from scripting.

Ok. Thanks for you reply.