Fill dropdown list with folder of tags

Hi everyone,

I would like to know if it is possible to fill a dropdown list with a all the tags of a folder, I did not find the syntax of a loop to browse the tags of a folder

Thank you in advance for your help.

Théo.

Welcome to the forum.

This should help you, system.tag.browse - Ignition User Manual 8.1 - Ignition Documentation

Hello!

Thank you for your answer.

I found that function and tried to use it but maybe it’s not the right place or i executed it badly but it doesnt work

system.tag.browse(’[default]’,{“recursive”:True})
for result in results.getResults():
print result

Should I put it in a ‘For’ loop ? Does it have to be used inside a script or in an expression ?

Do you have any example ?

Théo.

You don’t seem to be storing the returned value from the function in a variable. Also - and this could just be a formatting issue - your print statement must be indented. I’m surprised this code is not throwing an error/exception when you try to execute it; I would expect a NameError since results does not exist as a variable by the time you reference it.

Try this:

results = system.tag.browse(’[default]’,{“recursive”:True})
for result in results.getResults():
    print result

Following up on this. Should this be applied with an expression binding to the options object? Getting errors when trying to populate the list.

Thanks

This is a script, not an expression.

To populate a dropdown from a tag browse, I would not expect there to be any binding at all, rather, on some type of event run this script and write the list to the options object at that time.

I suppose you could use a binding to some dummy value and then use a script transform to run the script.

The provided script does not build the required dictionary structure that the options property expects, so there will need to be some additional code.

1 Like

Approaching it from the project library scripts, could you tell me what I'm missing?

def tagNames():
	results = system.tag.browse(path = "[default]_AlignmentPress1/MOD0_GEN/CycleTime")
	for result in results.getResults():
	    tagPath = str(result['fullPath'])
	    tagName = tagPath.replace("[default]_AlignmentPress1/MOD0_GEN/CycleTime/","")
	    print tagName

def tagPaths():
	results = system.tag.browse(path = "[default]_AlignmentPress1/MOD0_GEN/CycleTime")
	for result in results.getResults():
		tagPath = str(result['fullPath'])
		tagName = tagPath.replace("[default]_AlignmentPress1/MOD0_GEN/CycleTime/","")
		print tagPath

Would I need to create a method that writes to "value" and "label" for the options object?

Yes

Rather than printing the tag name, you need to construce a List of Dictionary objects.

The value is how you determine what has been selected, often this is some type of index value, though it can be anything. Label is what the end user will actually see in the dropdown list.

I would do something like this:

def tagNames():
	parentPath = "[default]_AlignmentPress1/MOD0_GEN/CycleTime"
	results = system.tag.browse(path = parentPath)
	return [{'value':idx, 'label':tagPath.replace(parentPath,'')} for idx, result in enumerate(results.getResults())]

You can set the value to the full tag path, or you could use a call to readBlocking to get the actual value of the tag, or you could set the value and the label to the same thing. Just depends on how you plan to use the drop down.

Since this is in a script library, it is possible to use an expression binding with the runScript expression function, to run it.

1 Like

Super helpful, and appears to have solved the issue. Thank you

1 Like

Don't forget to hit the "Solution" link on the answer that worked!

Don't think that @andrewk is the OP.

1 Like