Tag writeblocking multiple tags to one value

the guide says

# Create a list with the tag paths to be updated.
paths = ["[default]Folder/Tag_A","[default]Folder/Tag_B"]
 
# Create a list with the update values, one value for each path.
values = [1,2]
 
# Execute the write operation.
system.tag.writeBlocking(paths, values)

If you want to write a hundred tags to 0, do you need a values list with 100 comma separated zeroes?

You need a list with 100 elements in it… work smarter though.

One of infinite possibilities:

values = [0] * 100
3 Likes

@zacharyw.larson
check out the following link

List comprehensions are one of the nicest features of python and will save you a lot of time/lines of code.

You can incorporate if/else statements in them. Say I wanted all even numbers between 0 and 100 I could do it with just an if statement like

evens_only = [x for x in range(0,101) if x%2==0]

Now say I wanted to do a string ‘even’ for evens and ‘odd’ for odds I could do

labels = ['Even' if x%2==0 else 'Odd' for x in range(0,101)]

Take the time to learn about list comprehensions it will save you a ton of code and once you get used to it it is much more readable imo.

2 Likes

Thanks very much

Does that mean this works for spaces:
values =[" "]*14

A great way to learn and play with it to see what works is in your designer click on Tools and then click on Script console. You can type a few lines in the left hand side and click execute, or you can type directly into the REPL on the right hand side and execute statements one at time.

To your question

1 Like

thanks that helps a ton

1 Like

I tried to follow the example:

# Create a list with the tag paths to be updated.
paths = ["[default]Folder/Tag_A","[default]Folder/Tag_B"]
 
# Create a list with the update values, one value for each path.
values = [1,2]
 
# Execute the write operation.
system.tag.writeBlocking(paths, values)

I think the color changing is bad.
image

I don’t think your tag path is valid.

Also, as has already been said, work smarter not harder. Anytime you can make the code do the work for you, do it.

Try this:

numComments = 14
pathsComments = ["[Test]SomeTagPath/Comment{}".format(path) for path in range(1,numComments + 1)]
value14Spaces = ["space"]*numComments

for c in range(numComments):
    print "commentPath: ",pathsComments[c], " ","value:" , value14Spaces[c]

I used “space” because its not easy to see if you’ve actually printed a space or not.

1 Like

I was trying to take a shortcut to make my example like my problem.
Sorry about that, it wasn’t like comment 1-14 in the same folder.

I was deleting to make my folder paths more uniquely categorical.

Then I saw the culprit
image
I have some kind of impostor quotations in there.

Thanks for helping me.

That happens when posters here fail to use the pre-formatted text button for the code they paste, and then you copy from it. When the forum software sees quoted text that isn’t pre-formatted, it makes it “pretty” with curly quotes. Like around “pretty”.

Rule of thumb: Don’t copy from code that wasn’t formatted.

1 Like

I appreciate the rule of thumb and help.

This one was self inflicted I think.
I am sure this is a cardinal sin.
I used MS word instead of notepad to edit my text.

2 Likes

Notepad is only marginally better.

Get yourself a real text editor… Sublime Text, Nodepad++, VS Code, anything…

5 Likes

I used Notepad++ before. I will use that.

Thanks for encouragement and guidance

Thanks, I am soon going to be using something like you had posted

numComments = 14
pathsComments = ["[Test]SomeTagPath/Comment{}".format(path) for path in range(1,numComments + 1)]
value14Spaces = ["space"]*numComments

for c in range(numComments):
    print "commentPath: ",pathsComments[c], " ","value:" , value14Spaces[c]

a smattering of tags are arranged in a way that they have a number that increases to separate them