How do I use unknown structures of TagGroup
s in dm-script in python?
TagGroup
s are widely used in DigitalMicrograph. But how do I travel through them in python? How do I get all available tag names?
In normal dm-script
there are functions like TagGroupGetTagLabel()
and TagGroupGetTagType()
. One can use a for
-loop to check the structure. But there is not a single function in the python wrapper class Py_TagGroup
to get information about the labels. Also the examples never deal with unknown TagGroup
s.
I have a very simple problem: I want to use (show, modify, check, save, ...) the tags from an image. But I don't know the tag names.
img = camera.AcquireImage()
tg = img.GetTagGroup()
But now what? I don't know anything about this TagGroup
. TagGroup
s are not iterable so I cannot use them in for
-loops. I can get their length but I can only access data at indices. And that only if I know the datatype. Neither can I get the type nor the label.
So again: How can I travel through TagGroup
s in python in dm-script? How can I get the structure?
The Python module
execdmscript
on GitHUB with (version ≥ 1.1.4) supports convertingPy_TagGroup
s to pythondict
s orlist
s. So the following code works for me:1
execdmscript.convert_from_taggroup()
uses the persistent tags anddm-script
code for this. It involves saving thePy_TagGroup
to the global tags. Sincedm-script
code can travel throughTagGroup
s, the strucutre of theTagGroup
is analyzed by executingdm-script
code from the python interpreter. The results are saved to the persistent tags again. Then the structure is read from the global tags with python and adict
orlist
can be created from it.