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!