• Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login
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
  • Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login

Move Tag Position in the Stack?

Cinema 4D SDK
r21 python
3
5
517
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.
  • B
    bentraje
    last edited by Jan 27, 2020, 1:39 PM

    Hi,

    How do I move the tag position in stack? For instance, moving the python tag into the farther right.
    You can check an illustration of the problem here:
    https://www.dropbox.com/s/k9apte4whn7cqvh/c4d211_move_tag_position.jpg?dl=0

    Thank you

    1 Reply Last reply Reply Quote 0
    • L
      lasselauch
      last edited by lasselauch Jan 27, 2020, 3:00 PM Jan 27, 2020, 2:58 PM

      Hi @bentraje,

      I came across this problem some time ago.
      Have a look at: https://www.lasselauch.com/c4d-quicktip-shift-tags/

      2018-07-12_11-55-22.gif

      import c4d
       
      def main():
          doc.StartUndo()
          sel = doc.GetActiveTags()
       
          for tag in sel:
              obj = tag.GetMain()
              taglist = obj.GetTags()
       
              for i, t in enumerate(taglist):
                  if t in sel:
                      index = i+1
                      if index == len(taglist):
                          return
                      #print """Tag: %s || Index: %s""" % (t.GetName(), i)
                      doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
                      obj.InsertTag(t, taglist[index])
       
          doc.EndUndo()
          c4d.EventAdd()
       
      if __name__=='__main__':
          main()
      

      This was essentially my approach, it’s not bulletproof but it works if you want to send multiple tags from one index to the next.

      Cheers,
      Lasse

      1 Reply Last reply Reply Quote 1
      • B
        bentraje
        last edited by bentraje Jan 27, 2020, 5:18 PM Jan 27, 2020, 5:15 PM

        @lasselauch

        Thanks for the response. Gave me an idea what code to use.
        Here is my working code:

        import c4d
        from c4d import gui
        
        # Select an object. 
        # Hit Execute
        # Sets python tag in the right most place
        
        def main():
            tag_list = op.GetTags()
            for tag in tag_list:
                if tag.GetType() == c4d.Tpython: 
                    op.InsertTag(tag, tag_list[-1])
                    
        
        
            c4d.EventAdd()
        main()
        
        1 Reply Last reply Reply Quote 0
        • R
          r_gigante
          last edited by Jan 28, 2020, 12:42 PM

          Hi @bentraje, thanks for reaching out us.

          With regard to the solutions offered by @lasselauch - kudos Lasse - I have to remind that you're both benefiting of a automatism found in the Python implementation of the BaseObject::InsertTag(): when the method is called in Python, before inserting the tag, it first gets removed from the previous owner and then is inserted in the new one.
          This is very convenient and delivered for free in the Python implementation, in C++ this is not and this should be took in consideration.

          Finally, one note about the code design: it could lead to unpredictable results, especially on more complex scenarios, re-ordering a list while iterating on the same list. I would rather suggest iterating on list and operate the reorder on a copy of such list.

          Cheers, R

          1 Reply Last reply Reply Quote 2
          • B
            bentraje
            last edited by Jan 28, 2020, 2:19 PM

            @r_gigante

            Gotcha. Thanks for the warning.

            1 Reply Last reply Reply Quote 0
            4 out of 5
            • First post
              Last post