Multiselect dropdown writing to multiple tags

I have a dropdown that is multiselectable and I have a UDT that has multiple tags that I want to write to.

How do I structure my writeBlock to write to multiple tags in that UDT?

Write blocking receive a list of tag, and a list of value.

If you want to set the selected tags to 1

if !isinstance(Pos, list):
    Pos = [Pos]

Val = [1 for x in Pos]
system.tag.writeBlocking(Pos, Val)

Unlike pretty much every other language, which use !, Python uses not for negation:

if not isinstance():

I like [1] * len(Pos)

You will also need to generate a list of tag paths to write to.

So, something like:

tagValues = self.getSibling("Dropdown").props.value
if tagValues:
    parentPath = '[default]_types_/'
    members = ['Test 1','Test 2','Test 3']

    tagPaths = [parentPath + member for member in members]

    system.tag.writeBlocking(tagPaths,tagValues)

However, there are some fundamental problems here, like how do you know which value works with which tag?

What is the ultimate goal, why does this selection need to be a tag?

Here is more of what im doing.

	BadgeNum = self.getSibling("Table").props.selection.data[0].EmployeeID
	Name = self.getSibling("Table").props.selection.data[0].Name
	Line = self.getSibling("Line_Dropdown").props.value
	Pos = self.getSibling("Pos_Dropdown").props.value
	
	
	
	system.tag.writeBlocking('[default]Phase 1 Extrusion/'+str(Line)+'/'+str(Line)+'_'+str(Pos)+'/Assigned Operator BadgeNum',BadgeNum)
	system.tag.writeBlocking('[default]Phase 1 Extrusion/'+str(Line)+'/'+str(Line)+'_'+str(Pos)+'/Assigned Operator Name',Name)

I am trying to use this so supervisors can assign an operator multiple positions to work at with the dropdown like this:

image

I believe they need to be tags because I have a UDT that has several instances made from it; i.e, L41,L42,L51...etc and each one of those will have multiple positions that can be assigned to an operator.

Okay, so the drop down is actually to build the tag paths, that clears things up.

BadgeNum = self.getSibling("Table").props.selection.data[0].EmployeeID
Name = self.getSibling("Table").props.selection.data[0].Name
Line = self.getSibling("Line_Dropdown").props.value
Pos = self.getSibling("Pos_Dropdown").props.value

if Line and Pos:
	parentPath = '[default]Phase 1 Extrusion/{0}/{0}_{1}/Assigned Operator '.format(Line,Pos)
	tags = ['BadgeNum','Name']
	
	tagPaths = [parentPath + tag for tag in tags]
	tagValues = [BadgeNum, Name]
	
system.tag.writeBlocking(tagPaths, tagValues)

I get this error:

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:runAction", line 22, in runAction
ValueError: Invalid path element '[default]Phase 1 Extrusion/L41/L41_: [u'Pos1', u'Pos2']/Assigned Operator BadgeNum': Illegal character '<' (Line 1 , Char 36)

caused by org.python.core.PyException

Traceback (most recent call last):
File "function:runAction", line 22, in runAction
ValueError: Invalid path element '[default]Phase 1 Extrusion/L41/L41_: [u'Pos1', u'Pos2']/Assigned Operator BadgeNum': Illegal character '<' (Line 1 , Char 36)

You apparently have multi-selected two positions, and the code is trying to stick both into a single tagpath. You will have to iterate, or disallow multi-select.

oops, sorry missed the important part. :man_facepalming:t2:

BadgeNum = self.getSibling("Table").props.selection.data[0].EmployeeID
Name = self.getSibling("Table").props.selection.data[0].Name
Line = self.getSibling("Line_Dropdown").props.value
Pos = self.getSibling("Pos_Dropdown").props.value

if Line and Pos:
	parentPaths = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/Assigned Operator '.format(Line,p) for p in Pos]
	tags = ['BadgeNum','Name']
	
	tagPaths = [parentPath + tag for parentPath in parentPaths for tag in tags]
	tagValues = [BadgeNum, Name] * len(Pos)
	
	system.tag.writeBlocking(tagPaths, tagValues)
1 Like

Thanks. I am getting same error still, i am looking into.

Can you show an example BadgeNum?

A badgeNum looks like this: 0038014279

The error is this:
Invalid path element '[default]Phase 1 Extrusion/L41/L41_: [u'Pos1', u'Pos2']/Assigned Operator BadgeNum': Illegal character '<' (Line 1 , Char 36)

That's the same error you had previously. Are you sure you used the new code and saved everything ?

I see now what it was, pos was lower case so it didnt see Pos/ when I changed it to Pos It seems to be doing ok

Thank you

Fixed it in the original script.

Thanks alot guys, Big Help!

How could I add Shift into this scripted you help me with? I needed to add shift memory tags. When the system.tag.writeBlocking executes I need it to go to where it orignially was and this new path. Im just not sure how to add Shift to the parentPaths list

BadgeNum = self.getSibling("Operator_Table").props.selection.data[0].EmployeeID
	Name = self.getSibling("Operator_Table").props.selection.data[0].Name
	Line = self.getSibling("Line_Dropdown").props.value
	Pos = self.getSibling("Pos_Dropdown").props.value
	Shift = self.session.custom.Shift
		
	if Line and Pos:
		parentPaths = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/Assigned Operator '.format(Line,p) for p in Pos]
		tags = ['BadgeNum','Name']
			
		tagPaths = [parentPath + tag for parentPath in parentPaths for tag in tags]
		tagValues = [BadgeNum, Name] * len(Pos)
		
		system.tag.writeBlocking(tagPaths, tagValues)
		
		'''parentPaths = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/{2} Shift Operator Name '.format(Line,p) for p in Pos]
		tags = ['BadgeNum','Name']
					
		tagPaths = [parentPath + tag for parentPath in parentPaths for tag in tags]
		tagValues = [BadgeNum, Name] * len(Pos)
				
		system.tag.writeBlocking(tagPaths, tagValues)'''

If I'm understanding what you're trying to accomplish, I believe it would be this:

parentPaths = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/{2} Shift Operator Name '.format(Line,p,Shift) for p in Pos]

I would like for it to write in both locations, the assigned operator and the shift operator. Could it happen like this? When I run the script it doesnt return an error but it doesnt write to the tag address either:

	BadgeNum = self.getSibling("Operator_Table").props.selection.data[0].EmployeeID
	Name = self.getSibling("Operator_Table").props.selection.data[0].Name
	Line = self.getSibling("Line_Dropdown").props.value
	Pos = self.getSibling("Pos_Dropdown").props.value
	Shift = self.session.custom.Shift
		
	if Line and Pos:
		parentPaths = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/Assigned Operator '.format(Line,p) for p in Pos]
		tags = ['BadgeNum','Name']
			
		tagPaths = [parentPath + tag for parentPath in parentPaths for tag in tags]
		tagValues = [BadgeNum, Name] * len(Pos)
		
				
		system.tag.writeBlocking(tagPaths, tagValues)
		
		parentPaths1 = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/{2} Shift Operator Name '.format(Line,p,Shift) for p in Pos]
		tags1 = ['BadgeNum','Name']
					
		tagPaths1 = [parentPath + tag for parentPath in parentPaths1 for tag in tags1]
		tagValues1 = [BadgeNum, Name] * len(Pos)
				
		system.tag.writeBlocking(tagPaths1, tagValues1)

Assuming that the tag paths are correct, there is no reason doing it that way wouldn't work.

However, I would suggest that you can go a bit further. You'll need to make sure that the tag paths are correct.

	BadgeNum = self.getSibling("Operator_Table").props.selection.data[0].EmployeeID
	Name = self.getSibling("Operator_Table").props.selection.data[0].Name
	Line = self.getSibling("Line_Dropdown").props.value
	Pos = self.getSibling("Pos_Dropdown").props.value
	Shift = self.session.custom.Shift
		
	if Line and Pos:
		parentPaths = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/Assigned Operator '.format(Line,p) for p in Pos]
		tags = ['BadgeNum','Name']
			
		tagPaths = [parentPath + tag for parentPath in parentPaths for tag in tags]
		tagValues = [BadgeNum, Name] * len(Pos)
		
		parentPaths1 = ['[default]Phase 1 Extrusion/{0}/{0}_{1}/{2} Shift Operator Name '.format(Line,p,Shift) for p in Pos]
		tags1 = ['BadgeNum','Name']
					
		tagPaths1 = [parentPath + tag for parentPath in parentPaths1 for tag in tags1]
		tagValues1 = [BadgeNum, Name] * len(Pos)
		
		system.tag.writeBlocking(tagPaths + tagPaths1,tagVaues + tagValues1)

You can use code like this to print the tag paths to the console and verify they are correctly formed

for path in tagPaths1:
	system.perspective.print(path)