Creating expression tags with scripting console

Im trying to create a folder full of expression tags tags with the scripting console. each tag should have a different expression in it, one per hour 0-23. Chat GPT generated this for me, but it generates memory tags, not expression tags. Can someone see what I am doing wrong? Thanks.

# Define the folder where the tags will be created
tagFolder = "[default]Line 4 dashboard/ProductionCounters"  # Update with your actual tag path

# List to hold tag configurations
tags = []
for hour in range(24):
    tagName = "its_" + str(hour)  # Tag names: its_0, its_1, ..., its_23
    expression = "getHour(now()) = {}".format(hour)  # Expression logic

    tagConfig = {
        "name": tagName,
        "tagType": "AtomicTag",  # ✅ Must be "AtomicTag" for expression tags
        "dataType": "Boolean",
        "expression": expression,  # ✅ Correct placement for expressions
        "parameters": {  
            "Expression": expression  # ✅ This ensures the tag evaluates dynamically
        },
        "enabled": True
    }

    tags.append(tagConfig)

# Create the tags in Ignition
results = system.tag.configure(tagFolder, tags, "o")  # "o" to overwrite existing tags if they exist
print("Tag creation results:", results)

Try to add "valueSource": "expr" to your tagConfig
In addition to this change the expression to "getHour24(now()) = {}" in your example, and it should work

Generally chat gpt can help with python, but it's terrible at helping to write code that use ignition's libraries as it's too niche.

However, it did OK this time but it messed up some of the config. The best thing to do is to create one of your tags manually and then copy it's json. That will give you the exact template to use

2 Likes

Thank you. Appreciate the insight.