Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Collapse UV sets and rename to map1 [python]

Collapse UV sets and rename to map1 [python]

MayaNZ01
Enthusiast Enthusiast
1,526 Views
2 Replies
Message 1 of 3

Collapse UV sets and rename to map1 [python]

MayaNZ01
Enthusiast
Enthusiast

I saw a post that has some python code for UV set manipulation in Maya, I am wondering how I can get them working (I use Maya 2018)

 

Any help is greatly appreciated

 

I'm particularly interested in this part, to run on all selected meshes:

collapse UV sets and make sure that the surviving UV channel is named 'map1'

 

 

https://discourse.techart.online/t/how-does-maya-determine-the-primary-uv-set-and-the-uv-set-order/4... 

0 Likes
Accepted solutions (1)
1,527 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

this deletes all uvSets execpt from the default UV set and renames the default UV set to "map1". I'm not quite sure why you need this, also if you have multiple UVsets to begin with, someone probably put them there for a reason.

import maya.cmds as mc

def feedSelection():
    objects = mc.ls(sl= True)
    for object in objects:
        condenceUVMaps(object= object)
        

def condenceUVMaps(object = None):

    
    uvNames = mc.polyUVSet(object, q= True,auv = True )
    defaultUV = mc.getAttr(object + ".uvSet[0].uvSetName")
    uvNames.remove(defaultUV)
    
    
    for n in uvNames:
        mc.polyUVSet(object, uvs = n, d= True, e= True )
    if defaultUV != "map1":
        mc.polyUVSet(object, e= True, uvs = defaultUV, rn = True, nuv = "map1") 
    return

        
        
feedSelection()   

I hope it helps!

 

Message 3 of 3

MayaNZ01
Enthusiast
Enthusiast

Thanks for that, I did end up finding a really good Mel script that was quite complex and made sure no empty UV sets were there, and attempts to collapse everything into map1, and shows a message if there a meshes that end up with more than 1 UV sets with data

 

The reason for wanting it, is since I don't use UV sets for the most part, going between softwares creates new random ones and then I end up thinking my UV's are gone, but it just made new empty sets for many different meshes that are a pain to sort through with Maya's not so intuitive tools. It's especially strange that the UV Set Editor can't even change the order, there is a separate place to do that

 

Hopefully one day Autodesk will improve the UV set editor giving it full functionality 

0 Likes