Hi, I wanted to write something small and quite useful. I have been pretty steady using ngSkinTools v1, but it is already a discontinued version.
I'm going to share a small script to convert all the .ma files that are in the first version to the second version. This works for folders and subfolders. According to the internal docs, this only works if you have both versions installed. For this example I will use Maya 2020, which was the last version.
The code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import maya.cmds as mc | |
import utilities.wrFunctions as wrFunc | |
from ngSkinTools2 import api, signal | |
def convert_v1_2_v2(transforms): | |
for transform in transforms: | |
shapes = wrFunc.getShape(transform) | |
if shapes != None: | |
validShape = mc.ls(shapes,type='mesh') | |
if validShape != []: | |
skin = wrFunc.getSkinCluster(transform) | |
if skin != None: | |
layers = mc.ngSkinLayer(transform,q=True,lda=True) | |
if layers == True: | |
api.import_v1.import_layers(transform) | |
api.import_v1.cleanup([transform]) | |
#Iter | |
ROOT_PATH_CONVERTION = '' #e.x D:/PRJ | |
for root, dirs, files in os.walk(ROOT_PATH_CONVERTION): | |
for file in files: | |
if file.endswith('.ma'): | |
#Open file | |
filePath = os.path.join(root, file) | |
mc.file(filePath,o=True,f=1,typ='mayaAscii') | |
#Eval if has ngSkinTools | |
ngData = mc.ls(type='ngSkinLayerData') | |
if ngData == []: | |
mc.file(new=1,force=1) | |
continue | |
#Create new folder | |
newFilePath = os.path.join(root + '\__newLayers', file) | |
if os.path.exists(root + '\__newLayers') == False: | |
os.makedirs(root + '\__newLayers') | |
#Convert | |
transforms = mc.ls(type='transform') | |
convert_v1_2_v2(transforms) | |
#Save | |
mc.file(rename=newFilePath) | |
mc.file(s=1,f=1,typ='mayaAscii') | |
#Close | |
mc.file(new=1,force=1) |
This won't override the files, it will create a folder where the conversion will be saved in another .ma file. I hope you find this useful!
No comments:
Post a Comment