LoginSignup
0
0

More than 1 year has passed since last update.

maya python dump ass transform

Last updated at Posted at 2023-03-30

import pymel.core as pm
import json
import sys
import os

def ReplaceAssPath(assPath):
    # Define the directory where the asset files are located
    asset_dir = "J:/xkx/work/lib/asset/PR/"
    if asset_dir in assPath: return assPath
    assName = standin.dso.get().split("/")[-1].split("_")[-1].split(".")[0]

    assDir = asset_dir + assName + "Night/shd/ass/"
    if not os.path.isdir(assDir): 
        assDir = asset_dir + assName + "/shd/ass/"
        if not os.path.isdir(assDir): 
            if assDir in missing: return assPath
            missing.append(assDir)
            return assPath
    else:
        # Find the latest version folder
        version = max([f for f in os.listdir(assDir) if f.startswith("v")])
    
        # Create the file path using the latest version
        assPath = "%s%sNight/shd/ass/%s/PR%sNight_shd_%s.ass" % (asset_dir, assName, version, assName, version)
        standin.dso.set(assPath)
    return assPath

standins = pm.ls(type='aiStandIn')
standinTransforms = [pm.listRelatives(standin, parent=True, f=True)[0] for standin in standins]

assXYZ = {}
missing = []
for standin, transform in zip(standins, standinTransforms):
    xformDict = {}
    xformDict['tx'] = transform.tx.get()
    xformDict['ty'] = transform.ty.get()
    xformDict['tz'] = transform.tz.get()
    xformDict['rx'] = transform.rx.get()
    xformDict['ry'] = transform.ry.get()
    xformDict['rz'] = transform.rz.get()
    xformDict['sx'] = transform.sx.get()
    xformDict['sy'] = transform.sy.get()
    xformDict['sz'] = transform.sz.get()

    # Get the asset name from the standin file path
    assPath = standin.dso.get()
    # assPath = ReplaceAssPath(standin.dso.get())
    nodeName = transform.name()
    if assPath not in assXYZ:
        assXYZ[assPath] = {}
    assXYZ[assPath][nodeName] = xformDict

json_str = json.dumps(assXYZ, indent=4)
with open('D:/assXYZ.json', 'w') as f:
    json.dump(assXYZ, f, indent=4)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0