Change tags order on a specific object



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


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



  • 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



  • 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



  • 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 

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

Log in to reply