Python: GetTags() returning non-existent tags
-
Why does op.GetTags() return a polygon tag and point tag even if there are not any on the object?
[<c4d.BaseTag object called Phong/Phong with ID 5612 at 1906901951872>, <c4d.PolygonTag object called with ID 5604 at 1906901936256>, <c4d.PointTag object called with ID 5600 at 1906901964288>]
-
Hi @del ,
Those are invisible tags.
You don't need to work with them directly, and also you shouldn't delete these tags.Technically all points and polygons information contained in these tags.
SplineObject has their own set of invisible tags. -
Hi @del ,
Yes, @baca is completely correct with the answer. I just wanted to add that you can filter these tags out for example by using the GetInfo() function with the c4d.TAG_VISIBLE flag as shown below.
Cheers,
Iliaimport c4d op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: tags: list[c4d.BaseTag] = op.GetTags() print("All tags:") for t in tags: print(t) print("All visible tags:") for t in tags: if t.GetInfo() & c4d.TAG_VISIBLE: print(t) if __name__ == '__main__': main()
-
Thank you. I'll have to remember TAG_VISIBLE for future scripts.
-
Do these tags always occupy the same position?
I'm trying things like MakeTag and KillTag that require an indexed position and having two invisible tags is kind of throwing things off. Right now I'm subtracting 2 from the position that I'm targeting but this feels ripe for a script error down the road.
-
Hi @del ,
No, the position of tag in the tags list doesn't sound to me as a reliable index in this case.
What is the problem you're trying to solve here? Neither MakeTag() nor KillTag() select the tag by its index.
The nr argument in the KillTag() is the position where cinema starts searching for the tag of the provided type. In other words, there's presumably not much efficiency you're loosing without specifying this argument.
If you like to remove some specific tag, I think it's easier for you to use Remove() function on the tag itself.
Cheers,
Ilia -
HI @i_mazlov - I have a script that cycles through polygon selection tags on an object and I'm inserting materials tags next to the associated polygon selection tag that it's matched to.
As far as KIllTag() goes, sometimes I have multiple tags of the same type. I don't necessarily want to remove all of them so starting at a specific index to just remove the tag I wanted made sense. I don't mind using Remove(). It's just that KillTag() is right there in the sdk with all of the other tag related things so that's where I started. I also think that the definition of it made me think that it removed a single tag versus all of the tags of that type "Removes a tag from the object and free its resources."
-
Hi @del,
KillTag() removes a single tag of the specified type, the first occurrence after the specified index.
The hidden tags are just ordinary tags that can be affected by the KillTag() function. Generally your approach with keeping in mind these tags would work. However, I'd personally stick to some more robust way of handling this case, as there might be some other plugin that doesn't care about these hidden tags and would mess up the order you're relying on. I don't think you lose too much of efficiency here when using Remove() instead of KillTag().
Cheers,
Ilia -
thanks @i_mazlov