Browse tags printing folder

Well, the short answer is that I cheated a bit :slight_smile: It helps a lot to just know about this stuff already; discoverability isn't great.

But, starting from the top with changes I made:

TypeUtilities is a Java class we use everywhere in Ignition. Conveniently, Jython allows you to bring in Java classes just like they're Python code. Java uses reverse-domain-name addressing for packages (because class names must be globally unique) - the com.inductiveautomation isn't looking anything up over the internet or anything, it's basically just addressing the local dependency.
We publish a Javadoc for each new release - a bundled set of documentation explaining our (public) code: Javadocs & Notable API Changes · inductiveautomation/ignition-sdk-examples Wiki · GitHub

You can search for TypeUtilities in any of those: TypeUtilities
And find the getInitValueForClass method:
TypeUtilities

Note that this takes a single argument of type Class - Java's equivalent to Python's type(). More on that in a minute.

This line is adding a tuple (constructed with parentheses) to the existing paths list.
Another way to write it would be:
paths.append(tuple(tag.path, TypeUtilities.getInitValueForClass(tag.dataType.javaType)))
A tuple is an immutable sequence of values. In this case, we're using two elements, but a tuple can have any number of elements (including zero).
The first element is the tag's path. For the second, we're using the TypeUtilities method we found earlier to store the type-appropriate "initial" value. To get that initial value, we start from the tag object's dataType. I had initially thought the same as @lrose, that the dataType would be a string, but it turns out to be an instance of DataType - you can find this out by doing a print type(tag.dataType), which will give you something like this: <type 'com.inductiveautomation.ignition.common.sqltags.model.types.DataType'>
If you look at the DataType class (which you can find in the Javadocs linked above for ~most arbitrary classes you find in Ignition), you'll see it has a getJavaType() method. Java doesn't have properties, and instead generally uses "getter" and "setter" methods to retrieve or change a given object's properties. Jython conveniently unwraps these getX/setX methods into properties - so tag.dataType.javaType is actually calling tag.dataType.getJavaType() for you. This retrieves a Class instance for us, which we then pass to the TypeUtilities method.

So at this point your paths list is going to be a data structure that looks like this:

[
	("intPath", 0),
	("stringPath", "")
]

But system.tag.writeAll requires two lists - paths, and values. So we're going to use the builtin function zip to (confusingly) unzip the list we have, by spreading paths into it with the * operator. If it helps - this is not something I remember how to do offhand. Instead I googled for 'python list of tuples into two lists' and found this StackOverflow thread: python - How to convert list of tuples to multiple lists? - Stack Overflow

So list(zip(*paths)) unzips our list, which means our data will look like this:

[
	("intPath", "stringPath"),
	(0, "")
]

We can then use another Python function called unpacking to turn that new list into two new variables, which is what the paths, values = part is doing:

3 Likes

Just a note, at risk of resurrecting a dead topic, but in hopes of saving someone else some time-I could not get system.tag.browseTags to work inside of a UDT. At least on 8.1.29, it does not seem to get the correct tag scope for the browse. I believe you would need to construct the entire tag path to use this inside a UDT. Quite happy to be wrong!

system.tag.browseTags() is not an available system function in 8.1

It was available in 7.9, it has modified, and the named shortened to system.tag.browse() in 8.1

For what it's worth this post is tagged Ignition 7.8