Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Recent
    • Tags
    • Users
    • Login
    The Maxon SDK Team is currently short staffed due to the winter holidays. No forum support is being provided between 15/12/2025 and 5/1/2026. For details see Maxon SDK 2025 Winter Holidays.

    Change tags order on a specific object

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 1.5k Views
    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.
    • H Offline
      Helper
      last edited by

      On 10/05/2018 at 08:11, xxxxxxxx wrote:

      Hi, thanks to MaximeA i've been able to achieve the first part of a little script i wanted to make to generate an UVW tag and rename it with a specific name. Now i would like to change the order of the different tags that my object contains.
      Let's say i have a polygon object with an UVW and a material tag, then i create the second UVW tag with my script. C4D adds this third tag on the left position of the list. I would like to recover the first original uvw tag and place it after my material on the list (originally, it is just before, on its left).
      And as for the first part of this project, i can't find anything on the documentation about such an action. So, is it possible and which way should i take to achieve this?
      Thanxs a lot
      Nico

      My original code

      import c4d
      from c4d import documents, plugins
      from c4d import gui
      #Welcome to the world of Python
        
      def main() :
          doc = c4d.documents.GetActiveDocument()
          obj = doc.GetActiveObject()
          
          if obj is None:
              gui.MessageDialog('Select an object first') 
              return
          
          tags = obj.GetTags()
          
          matTag = obj.GetTag(c4d.Ttexture)
          if matTag is None:
              gui.MessageDialog('Insert a material first')
        
          matTag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_CUBIC
        
          uvwTag = c4d.utils.GenerateUVW(obj, obj.GetMg(), matTag, obj.GetMg())
          uvwTag.SetName("CUBIC")
          newName = uvwTag.GetName()
          finalName = gui.RenameDialog(newName)
          uvwTag.SetName(finalName)
          
          obj.InsertTag(uvwTag)
        
          matTag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
          
          c4d.EventAdd();
        
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 10/05/2018 at 09:12, xxxxxxxx wrote:

        Just to be sure I've understood your request correctly ...
        You start with following situation:

        <object> | <script- generated uvw> <original uvw> <material>

        and you want to be able to modify it to the following:

        <object> | <script- generated uvw> <material> < original uvw>

        I know you can specify the location of a tag when you perform the InsertTag(), as such you would be able to control where your script-generated tag will be put. But not sure you can alter the list afterwards.
        The only thing that comes to mind is clone the original UVW tag and insert it at the end of the list then remove the original one.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 11/05/2018 at 02:43, xxxxxxxx wrote:

          Hi Nicolelectro,

          Keep in mind tag/object inherit from BaseList2D which inherit from GeListNode.
          That means you can use InsertAfter/Before in order to change the order of your tag

          Cheers,
          Maxime

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 20/05/2018 at 06:42, xxxxxxxx wrote:

            Hi and thank you both. I was away for a few days and I'll look into it. Have a great day.
            Nico

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 21/05/2018 at 02:31, xxxxxxxx wrote:

              Thanks, guys. It works perfectly. Is there anything I could improve in this code. Is everything all right? The SDK documentation and web examples are really hard to understand (even finding them is a headache). Without basic knowledge, it's very complicated to progress Confused

              import c4d
              from c4d import documents, plugins
              from c4d import gui
              #Welcome to the world of Python
                
              def main() :
                  doc = c4d.documents.GetActiveDocument()
                  obj = doc.GetActiveObject()
                  
                  #SELECTION OBJET
                  if obj is None:
                      gui.MessageDialog('Select an object first') 
                      return
                  
                  tags = obj.GetTags()
                  
                  matTag = obj.GetTag(c4d.Ttexture)
                
                  baseUV = obj.GetTag(c4d.Tuvw)
                  #print baseUV
                
                  baseProjection = matTag[c4d.TEXTURETAG_PROJECTION] #Stocke la projection initiale
                  #print baseProjection
                  
                  if matTag is None:
                      gui.MessageDialog('Insert a material first')
                
                  
                  matTag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_CUBIC
                  
                  uvwTag = c4d.utils.GenerateUVW(obj, obj.GetMg(), matTag, obj.GetMg())
                  uvwTag.SetName("CUBIC")
                  newName = uvwTag.GetName() # Récupère le nom du tag
                  #print newName
                  finalName = gui.RenameDialog(newName) #fenêtre dialogue
                  uvwTag.SetName(finalName) #Renomme le tag définitivement
                  #print finalName
                  
                  errorName = uvwTag.GetName() #Si on annule la fenêtre de nommage
                  if errorName == "None":
                      uvwTag.SetName("CUBIC")
                  
                  obj.InsertTag(uvwTag)
                  
                  matTag[c4d.TEXTURETAG_PROJECTION] = baseProjection #redonne la projection initiale
                  
                  #CHANGEMENT DE POSITION DU TAG INITIAL
                  lastUV = baseUV.GetClone()
                  lastUV.InsertAfter(matTag)
                  baseUV.Remove()
                      
                  c4d.EventAdd();
                 
              if __name__=='__main__':
                  main()
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post