Script tag path problem

Hello, short question; i have a script which checks a tag folder, it works great on my testing folder but when i change the tag path to be my actual folder with more tags in it most of (but not all weirdly) the script stops working but it does not produce any errors so im confused as to why this is.
image
by hashing out the first tagPath and unhashing the second one everything works good.
My best guess is it doesnt like the spaces in my tag path(edit: spaces have nothing to do with this i put a space in my testing folder and it still works). Does anybody have any ideas?

Perhaps try using recursion? See the bottom example from the docs, system.tag.browse - Ignition User Manual 8.1 - Ignition Documentation

results = system.tag.browse("[default]", {"tagType":"UdtInstance", "recursive":True}).results
for result in results:
        print str(result['fullPath'])
1 Like

Well this didnt cause any errors but its just reading from the entire [default] and not the specific folder i want

Sorry, I just copied their example as-is, you will need to edit for your use, something like,

tagPath = "[default]DTL_Ramp/Ramp PLC Connection Tags/Ramp1/Event"
results = system.tag.browse(tagPath, {"tagType":"AtomicTag", "recursive":True}).results
for result in results:
        print str(result['fullPath'])
1 Like

It actually works with any folder path except the one i need it to work with… am i going insane it makes no sense

Thank you for the response but this also did not work, its still returning values from the whole [default] for some reason, regardless i dont think recursion is the problem because it works with other folders without needing to do that

If you copy and paste the script I did into the script console and hit execute, what do you get?

1 Like


Nothing actually

remove the filter for AtomicTag and see if it returns something then?

1 Like

No idea, short of you have the wrong path or on a version with bugs. Maybe try different variations, but I don’t know what is going on. I can’t say that I have ever had a problem like you describe.

1 Like

This is actually based off your code from another post (you used tooltip as a holding place to put in previous value which was genius by the way) do you happen to know if maybe the script breaks if there are too many tags in the folder or something? it actually is looking in the right folder all along because if i change the OPC server name of some tags to something else the script will return them, again very weird.

import system
import numbers
import datetime
import system
import sys

def grouper(n, iterable): #ignition bug need to import and all that in the function you are using below
    return zip(*[iter(iterable)] * n)
    
def logDB_new(tags):
    tagReadList = []
    import system
    def grouper(n, iterable):
        return zip(*[iter(iterable)] * n)

    for tag in tags:
        tagReadList.append(str(tag['fullPath']))
        tagReadList.append(str(tag['fullPath']) + '.Tooltip')

    qValues = system.tag.readBlocking(tagReadList)

    writeList = []
    writeValues = []

    query = "INSERT INTO tL_EventNew (Name,TagValue,t_stamp) VALUES " 
    queryVals = []

    for currentValues, prevValues in grouper(2,zip(tagReadList, qValues)):
        name, curQValue = currentValues  
        prevName, prevQValue = prevValues 

        prevValueString = prevQValue.value    
        curValue = curQValue.value
        t_stamp = curQValue.timestamp
        writeList.append(prevName)
        writeValues.append(curQValue.value)
        if prevValueString == 'false':
        	prevValue = False
        else:
        	prevValue = True

        if (curValue != prevValue):
        
			
			KepTagName = name.replace("/",".")
			#KepTagName = KepTagName.replace("[default]TestingTags","OMRON_FINS.Ramp1_PLC.Event")
			KepTagName = KepTagName.replace("[default]DTL_Ramps.Ramp PLC Connection Tags.Ramp1","OMRON_FINS.Ramp1_PLC.Event") 
			param = {"KepTagName":KepTagName}
			
			queryVals += [KepTagName,curValue,system.date.now()]
			print KepTagName, curValue, prevValue
			
			EventID =-1
			data = system.dataset.toPyDataSet(system.db.runNamedQuery("EventsLog/ScriptNameExtraction", param))
			if data:
				EventID = data[0][0]
			print "EventID = " + str(EventID)

			state = bool(curValue)
			print "state = " + str(state)
			
			param2 = {"TagName":KepTagName, "curValue":state}
			system.db.runNamedQuery("EventsLog/UpdateTPEvents", param2)
			

			if curValue == 1:
				OperatorPath = ["[default]DTL_Ramps/LoggedInOp/Ramp1"]
				OpID = system.tag.readBlocking(["[default]DTL_Ramps/LoggedInOp/Ramp1"])[0]
				print "Op ID = " + str(OpID.value)
				param3 = {"EventID":EventID, "State":state, "OpID":OpID.value}
				if EventID > -1:
					print "running insert"
					system.db.runNamedQuery("EventsLog/UpdateTLEvents", param3)
			else:
				param5 = {"EventID":EventID}
				system.db.runNamedQuery("EventsLog/DatetimeReset", param5)
				 
    query += ','.join(['(?,?,?)'] * (len(queryVals) / 3))
    system.tag.writeBlocking(writeList,writeValues)

    if queryVals:
        print "writing to database"
        system.db.runSFPrepUpdate(query,queryVals,datasources=['Ignition_Dean'])

tagPath = "[default]DTL_Ramps/Ramp PLC Connection Tags/Ramp1/Event"
#tagPath = "[default]DTL_Ramps/Ramp PLC Connection Tags/Ramp1/Operators"
#tagPath2 = "[default]DTL_Ramps/Ramp PLC Connection Tags/Ramp1/Event"
#tagPath = "[default]Testing Tags/New Folder"
#tagPath = system.tag.browse(tagPath2, {"tagType":"UdtInstance", "recursive":True}).results
#tagPath = "[default]Testing Tags"
tags = system.tag.browse(tagPath,{'tagType' : 'AtomicTag'}).getResults()
logDB_new(tags)

I would love to take credit for that, but it wasn’t my Idea it was something the original poster was already doing.

There shouldn’t be any limit on the tags. The only thing that should be limiting the number of results returned is the filter.

If you change the browse operation code to this: Do you get results printed out?

tags = system.tag.browse(tagPath).getResults()
print tags

Perhaps @JordanCClark sees/knows something I don’t?

1 Like

Stupid question, but I didn’t see it asked above so I have to ask it: if you right click on the folder you are trying to browse tags from in the Tag Browser, and select “Copy Path” is it exactly the same as the path you included in your system.tag.browse() call? I can’t tell you how many times I have accidentally messed up something simple like this with a minor typo. :slight_smile:

Edit: Your original post shows:

tagPath = "[default]DTL_Ramp/Ramp PLC Connection Tags/Ramp1/Event"

And your last follow up post lists the first folder name as plural:

tagPath = "[default]DTL_Ramps/Ramp PLC Connection Tags/Ramp1/Event"

If I was a gambling man, that’d be what I place my money on as the culprit, but let us know either way!

2 Likes

Yes unfortunately this is not the problem, ive been using copy path the whole time but thanks for the response

I know this seems unlikely but im fairly sure my events folder is haunted by satan himself, i made another folder exactly the same called Events2 beside Event with a copy of all the tags in it and it works???

im just using the second folder and calling it a day, im no match for satan, if this causes problems later for me oh well

1 Like