Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Python: GetTags() returning non-existent tags

    Cinema 4D SDK
    python
    3
    9
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • .
      .del
      last edited by .del

      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>]

      bacaB i_mazlovI 2 Replies Last reply Reply Quote 0
      • bacaB
        baca @.del
        last edited by

        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.

        1 Reply Last reply Reply Quote 2
        • i_mazlovI
          i_mazlov @.del
          last edited by

          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,
          Ilia

          import 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()
          

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • .
            .del
            last edited by

            Thank you. I'll have to remember TAG_VISIBLE for future scripts.

            1 Reply Last reply Reply Quote 0
            • .
              .del
              last edited by

              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.

              i_mazlovI 1 Reply Last reply Reply Quote 0
              • i_mazlovI
                i_mazlov @.del
                last edited by

                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

                MAXON SDK Specialist
                developers.maxon.net

                1 Reply Last reply Reply Quote 0
                • .
                  .del
                  last edited by

                  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."

                  i_mazlovI 1 Reply Last reply Reply Quote 0
                  • i_mazlovI
                    i_mazlov @.del
                    last edited by i_mazlov

                    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

                    MAXON SDK Specialist
                    developers.maxon.net

                    1 Reply Last reply Reply Quote 1
                    • .
                      .del
                      last edited by

                      thanks @i_mazlov

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post