Mismatched input 'tagPathRead' expecting INDENT

I have created a script which is called when a button is pressed and creates tags dynamically.
I have included a tag event script in the form of a string.
I am receiving an error and the tags script does not do what is expected.
Issue:
Error compiling event script for event id ‘valueChanged’.
SyntaxError: (“mismatched input ‘tagPathRead’ expecting INDENT”, (‘tagevent:valueChanged’, 2, 0, ‘tagPathRead = [default]Counts/AU/QLD/1/PM 53/WashCount\n’))

When i go into the tag and press apply the error is removed and the tags script then functions as expected.
Any help would be appreciated.

Can you please post the code also? In this way it will be easier for us to troubleshoot your issue.
PS: Remember to put the code in Preformatted Text ( Ctrl + Shit + C )

That normally means you did something like

if condition == value:

othercodeHere

and python was expecting some indented code after if/for statement but didn’t see any.

PS: Remember to put the code in Preformatted Text ( Ctrl + Shit + C )

I tried that before but I ended up needing new pants :rofl:

7 Likes

AHAHAHAHAH LOL :rofl::rofl::rofl::rofl: missed an f :sweat_smile::sweat_smile:

Actually, don’t use Ctrl-Shift-C for code blocks. Use triple backquotes (these: ```) on a line above and a line below your pasted code.

This is the script i am placing inside the Tag

You’ve got some mismatched quoting going on in line 1.

How would can i change that first line?

Same issue when i remove the dynamic variable and simplify:

I Have this already, see code snippets below.

The triple quotes @pturmel was talking about are for posting code to the forum. Copy the text of your script and paste it in between triple quotes in the forum and the forum will format your code nicely. Do this instead of taking a screenshot of your code, it’s easier to read.

In addition to working in the forum, python uses triple quotes to begin and end a block comment. In your most recent screenshot, you have commented out almost all of your script. Right now, the computer is seeing AutoScript = and that’s it. Everything in purple is interpreted as a comment. You need to get rid of the triple quotes in your actual code.

I have the triple quotes as i am placing that text inside a tags script.
So i am using a script to create a tag, which needs the value change script ‘AutoScript’

@Brian
So the text inside the triple quotes (’’’) is being passed into the a tag to be used for a tags valuechanged event script

Oh, ok. I think the rest of us missed that. It’s not readily apparent that that is what you are doing from just looking at the code. I overlooked your description in the original post.

I’m guessing that what’s going on is related to the fact that when you define a tag through the editor and define a tag change script, there’s a little bit of code that ignition generates for you, and the code you write actually ends up indented one level. My guess is that if you are programmatically creating the tag, you need to include the code that ignition usually generates for you, and indent your normal code one level.

I’m guessing what is happening is that when you open the tag editor on one of your programmatically created tags, ignition notices that the code it generates is not there, generates it, and indents everything else in one level. By the time the window draws, it has fixed the problem and all you need to do is apply the changes.

It’s a complete shot in the dark on my end, but I’d start poking around there.

Thanks for the suggestion, but that wasn’t it.

def CreateTags(country, state, depotid, pmid, ewontype):

#Tag paths for the tag creation
ftpPath = "[default]FTP/"+str(country)+"/"+str(state)+"/"+str(depotid)+"/PM " + str(pmid)
mqttPath = "[MQTT Engine]"+str(country)+"/"+str(state)+"/"+str(depotid)+"/PM " + str(pmid)

#Tag paths for the Auto Start and Wash Start tags - For the script Counters
autoTagPath = "[default]Counts/PM " + str(pmid) + "/AutoCount"
washTagPath = "[default]Counts/PM " + str(pmid) + "/WashCount"
autoTagPathW = "[default]Counts/PM " + str(pmid)
washTagPathW = autoTagPathW

if ewontype == 0:
	baseTagPath = ftpPath
else:
	baseTagPath = mqttPath
	
#######################################################################################################################################################	
#Auto Count Script
AutoScript = '''tagPathRead = ''' +"'"+ autoTagPath +"'"+'''
tagPathWrite = ''' +"'"+ autoTagPathW +"'"+ '''
count = system.tag.read(tagPathRead).value

tagExist = system.tag.exists(tagPathRead)
if tagExist == False:
	auto = 0
else:
	if currentValue.value == 1:
		auto = count + 1
	else:
		auto = count
# Configure the tags. Manually doing this for the example, but a for-loop could simplify the process.
tagAuto = {
			'name': 'AutoCount',           
			'valueSource': 'memory',
			'value' : auto,
			'tagType' : 'AtomicTag',
			'dataType' : 'Int8'
		}
# Add the tags a list
tagList = [tagAuto]
 
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
 
# Edit the tags.
system.tag.configure(tagPathWrite, tagList, collisionPolicy)'''

#Create the tag ready for operation
tagAuto = {
			'name': 'AutoCount',           
			'valueSource': 'memory',
			'value' : 0,
			'tagType' : 'AtomicTag',
			'dataType' : 'Int8'
		}
# Add the tags a list
tagList = [tagAuto]
 
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
 
# Edit the tags.
system.tag.configure(autoTagPathW, tagList, collisionPolicy)


#######################################################################################################################################################
#Wash Count Script
WashScript = '''tagPathRead = ''' +"'"+ washTagPath +"'"+'''
tagPathWrite = ''' +"'"+ washTagPathW +"'"+ '''
count = system.tag.read(tagPathRead).value

tagExist = system.tag.exists(tagPathRead)
if tagExist == False:
	auto = 0
else:
	if currentValue.value == 1:
		auto = count + 1
	else:
		auto = count
# Configure the tags. Manually doing this for the example, but a for-loop could simplify the process.
tagWash = {
			'name': 'WashCount',           
			'valueSource': 'memory',
			'value' : auto,
			'tagType' : 'AtomicTag',
			'dataType' : 'Int8'
		}
# Add the tags a list
tagList = [tagWash]
 
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
 
# Edit the tags.
system.tag.configure(tagPathWrite, tagList, collisionPolicy)'''

#Create the tag ready for operation
tagWash = {
			'name': 'WashCount',           
			'valueSource': 'memory',
			'value' : 0,
			'tagType' : 'AtomicTag',
			'dataType' : 'Int8'
		}
# Add the tags a list
tagList = [tagWash]
 
# Set the collision policy. If editing existing tags, then we'll use 'o' to overwrite...
#collisionPolicy = 'o'
#...however, in this example, we'll just abort
collisionPolicy = 'o'
 
# Edit the tags.
system.tag.configure(washTagPathW, tagList, collisionPolicy)
	
#######################################################################################################################################################

tagNames = [ "AI 0 Fault",
	"AI 1 Fault",
	"Goliath Comms Fault",
	"Goliath Drive Fault",
	"Goliath Lifter Hyd OL",
	"Goliath Pump OL",
	"Goliath Pump Overheat",
	"Goliath Sheer Pin Jam",
	"Grinder Drive Fault",
	"Lid Has Not Closed",
	"Lid Open Fault",
	"Overfill Alarm",
	"Pulpmaster Sheer Pin Jam",
	"Pump Outfeed Blocked",
	"Pump Overload",
	"Safety Relay Fault",
	"Tank Full",
	"Tank is Full",
	"Tank Three Qrt",
	"Water Pressure Low",
	"Tank 5 percent",
	"Tank Percentage",
	"HMI Reset",
	"Screw Speed",
	"Grinder Run Time"]
	
tagList = []

for tagName in tagNames:
	tag = { "name":tagName,"valueSource": "memory", "value" : 0}
	tagList.append(tag)
        
# Set the collision policy. If editing existing tags, then we'll use "o" to overwrite
collisionPolicy = "o"
 
# Edit the tags.
system.tag.configure(baseTagPath, tagList, collisionPolicy)

#Create the tag for Auto Start which has the script for the Auto Counter
tagList2 = []
tag2 = { "name":"Auto Start","valueSource": "memory", "value" : 0, "eventScripts":{"eventid":"valueChanged", "script":AutoScript}}
tagList2.append(tag2)
# Edit the tags.
system.tag.configure(baseTagPath, tagList2, collisionPolicy)

#Create the tag for Wash Start which has the script for the Wash Counter
tagList3 = []
tag3 = { "name":"Wash Start","valueSource": "memory", "value" : 0, "eventScripts":{"eventid":"valueChanged", "script":WashScript}}
tagList3.append(tag3)
# Edit the tags.
system.tag.configure(baseTagPath, tagList3, collisionPolicy)
	
	

for tagName in tagNames:
	if tagName == tagNames[16]: 
		system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})
	elif tagName == tagNames[17]: 
		system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})	
	elif tagName == tagNames[18]: 
		system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})	
	elif tagName == tagNames[20]: 
		system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Tank"]]})	
	else:	
		system.tag.editAlarmConfig([baseTagPath+"/"+tagName],{"":[["name","Value",tagName],["enabled","Value","1"],["priority","Value","High"],["label","Value",tagName],["mode","Value","10"],["activeCondition","Expression","{Value}=True"],["displayPath","Value","PM "+str(pmid)+" Fault"]]})	
			
system.tag.editTag(tagPath = baseTagPath+"/Tank Percentage", attributes={"HistoryEnabled":True})#, "PrimaryHistoryProvider":"Pulp_Master"})

I was looking around for more information, and I came across this post. If you notice, in the line where Kyle is defining the tag event script, he has a \n just before the print statement. This is putting a tab character at the beginning of the script. And, this is apparently a working configuration. I’m guessing you are missing the tab character, and that’s what ignition is complaining about.

You might try moving to a new line immediately after your triple quotes and indenting everything in one level.

Thanks Brian
‘\t’ just after the triple quotes (’’’) solved the problem
image