Python Script for Importing UDT Tags into Ignition!

If you’re an Integrator that has used Ignition, you’ll know what I’m talking about when I mention the powerful features that InductiveAutomation has done a superb job in implementing into their software. They continue to be the ‘disruptor’ of the HMI-and-all-things-automation market space.

However, if you’re an Integrator that has used Ignition, you may also have had some ‘headaches’ with the Tag Import feature, especially since they discontinued the csv export in the version 8.0 release. Ignition still supports csv import as a legacy feature, but their primary import file formats are JSON and XML.

Don’t get me wrong, I do NOT want IA to bring back the csv export, but I’ve tried to adapt to using JSON or XML for tag imports and I find that any time you introduce a multi-line text file format for tag creation, it becomes much more complicated when it comes to automated processes, and let’s face it, if you’re in Integrator, you’re all about automated processes!

My process to get here included:

  • Searching for a decent way to create a JSON file (Excel is working on supporting it in a future release) and found some Google Sheets scripts to help with that, to
  • Trying to create an XML template (creating a schema) to be able to export to xml but found that too arduous for this guy, to
  • Settling on diving in and building an Ignition script to let me do exactly what I want with a csv.

Here is an example of a Project Library script in Ignition that will take a simple, single-line-format csv file of tags including parameter values and UDT tag ‘overrides’ (setting a member tag’s value) and import it. It also checks to see if that tag already exists, and if it does, deletes it first.

(download the script file as text http://bit.ly/csvImportIgnition)

Now, the caveat with this is that, in this particular example, it’s assumed that there MUST already be a UDT in Ignition named ‘AIn’. This script is importing instances of that UDT, NOT the UDT structure itself.

The code (shown above) goes through the following steps:

  • By running the function ‘openFile()’, a file-picker window allows you to find the csv file to import.
  • It opens the file and loads it into the python library ‘csvDictReader’, a ‘Dictionary Reader’.
  • For each row of the file (now a python ‘dictionary’) it checks to see what UDT Type it is (under the csv column heading “UDTType”)
  • In this example, it then calls the function ‘addAIn()’, which, after checking to see if the tag exists (system.tag.exists), creates the tag using the ‘sytem.tag.addTag’ function and updates the values of the ‘parameters’ and ‘overrides’ (member tags) listed. It also lists the tags created in the Script Console output window.

I imported a csv with 351 tags of 9 different UDTs and only 16 headers (in total, that was around 2457 values updated) in approx 7 seconds. The csv itself took around 30 min of compiling information from project design spreadsheets. All that with 100% accuracy and no copy/paste errors.

The advantage of using UDTs in any system is that all the alarm configuration, parameters, etc are all done already. Simply by creating multiple instances, all that functionality is inherited.

If you’re an experienced coder with Python this should only take you around 20 minutes to build. However, my Python skills are not huge and I have to reference all the nuances and syntax to get things right, so I figured I would share in order to help anyone out there looking for a simple but VERY effective way to get the job done.

Share on LinkedIn

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.