There are SO many posts in here regarding tag imports, csv formats, xml schema, and the issues regarding them, so I figured I would post a very simple solution that was born out of my own issues with tag imports.
The problem with the legacy csv import is that it is quite un-intuitive when it comes to the format when you are trying to write parameter values and tag values (overrides) along with the tag. The format becomes multi-line and somewhat cryptic.
The issue with using xml is that unless you’re used to working with xml, or have a schema to work from, the xml file (even in excel as an editor) is multi-line and again, somewhat cryptic.
I finally settled on the fact that the only solution (for me) was to create a script (thanks to a quick post reply by @PGriffith ) that would use a SIMPLE, single-line-per-tag csv file to do the heavy lifting. Here is an example of what I’ve put together for anyone that wants to do the same (you can also read my blog post about it).
import csv #import the python csv library
# Script tools to open csv file and import tags of specified UDT Type
# Open csv file through file selector
def openFile():
filePath = system.file.openFile("csv","%user%")
csvFile = open(filePath, 'r')
reader = csv.DictReader(csvFile)
print reader.fieldnames
for row in reader:
# Call addUDT function based on UDTType
if row['UDTType'] == 'AIn': addAIn( row )
# add more conditions for more UDTTypes...
# Function to add instance tag of UDT type 'AIn'
def addAIn( csvRow ):
if csvRow['TagProvider'] == "": tagProv = '[default]'
else: tagProv = '[' + csvRow['TagProvider'] + ']'
tagPath = tagProv + csvRow['TagPath']
tagName = tagPath + '/' + csvRow['Name']
if system.tag.exists(tagName):
system.tag.removeTag(tagName)
print tagName + ' removed'
system.tag.addTag( parentPath = tagPath,
name = csvRow['Name'],
tagType = 'UDT_INST',
attributes={'UDTParentType':csvRow['UDTType']},
parameters={'Description':csvRow['Description'],
'EquipGp':csvRow['EquipGp'],
'ItemName':csvRow['ItemName'],
'RawLocation':csvRow['RawLocation'],
'EngUnits':csvRow['EngUnits']
},
overrides={
'PriorityHH':{'value':csvRow['PriorityHH']},
'PriorityH':{'value':csvRow['PriorityH']},
'PriorityL':{'value':csvRow['PriorityL']},
'PriorityLL':{'value':csvRow['PriorityLL']}
}
)
print 'AIn tag ' + tagName + ' added'
The advantage with this is that the csv is very simple. I imported a csv with 351 instances of 9 different UDTs, contained in 16 headers and in the process, updated 2457 values (parameters & member tag values).
It’s just a way to keep things simple, but doing it efficiently and accurately.
[Edit]: I put this in a Project Library script and run it from the Script Console.