Skip to content

Can you extract all tags names down to their atomic form? #278

Answered by ottowayi
TheWicklowWolf asked this question in Q&A
Discussion options

You must be logged in to vote

get_tag_list() returns a dictionary of all the top-level tags, so that's why you're not seeing all of the sub-tags. You can write a small function to recursively walk all of the structs to get a flattened list:

from pycomm3 import LogixDriver
from rich import print


def flatten_tags(tags):
    def flatten_struct(struct):
        for attr in struct['attributes']:
            yield attr
            if struct['internal_tags'][attr]['tag_type'] == 'struct':
                yield from (f'{attr}.{x}' for x in flatten_struct(struct['internal_tags'][attr]['data_type']))
                
    
    for tag, _def in tags.items():
        yield tag
        if _def['tag_type'] == 'struct':
           …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TheWicklowWolf
Comment options

Answer selected by TheWicklowWolf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants