Initializing Memory Tag Dataset on View Startup

Hi Team,

I am trying to create a dataset as a Memory Tag when the view starts. The logic should be:

  • If the dataset already exists, do nothing.

  • Otherwise, create the dataset.

I have attempted the following code, but it is not working as expected. Could you please advise on the correct approach to achieve this?

def runAction(self):
	
	from datetime import datetime
	tagPath = "[default]ds_cutlist"
	
	ds = system.tag.readBlocking([tagPath])[0].value
	
	if ds is None or ds.getRowCount() == 0:
	
	    headers = [
	        "btns",
	        "orderid",
	        "bundleid",
	        "panel_qty",
	        "length",
	        "overlap_length",
	        "stopper1",
	        "stopper2",
	        "stopper3",
	        "stopper4",
	        "1st",
	        "last",
	        "mid",
	        "bundle_height"
	    ]
	
	    defaultRow = [
	        "", "", "",
	        0, 0, 0,
	        True, True, True, True,
	        "", "", "",
	        0.0
	    ]
	
	    system.tag.writeBlocking(
	        [tagPath],
	        [system.dataset.toDataSet(headers, [defaultRow])]
	    )

Thank you!

Well, that narrows it down to just about everything... :wink:

if you are looking to create the tag, then you need to use system.tag.configure() It will also work to set a default value.

def runAction(self):
	
	from datetime import datetime
	tagPath = "[default]ds_cutlist"
	logger = system.util.getLogger('tag')
	
	# if the tag exists and has rows in it, then exit the function.
	if system.tag.exists(tagPath)
        ds = system.tag.readBlocking([tagPath])[0].value
        if ds.rowCount > 0:
            return
	
	collisonPolicy = 'o'
	tagConfig = {u'dataType': DataSet, 
              u'path': '[default]ds_cutlist', 
              u'tagType': 'AtomicTag', 
              u'name': u'ds_cutlist', 
              u'valueSource': u'memory', 
              u'value': [[u'', u'', u'', 0, 0, 0, True, True, True, True, u'', u'', u'', 0.0]]
             }
    
    system.tag.configure('[default]', [tagConfig], collisonPolicy)
1 Like

Thanks a lot.