0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python maya reference set namespace and transform

Last updated at Posted at 2023-03-30

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

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

assXYZ = {}
missing = []
lightRoot = "J:/xkx/work/lib/lig_set/PR/"
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()

    filename = standin.dso.get().split("/")[-1]
    if 'MA' in filename:
        index = filename.find('MA') + 2  # Find the index of the 'MA' substring and add 2 to skip over it
        digits = filename[index:index+3]  # Extract the 3 digits starting at the index
        if digits.isdigit():  # Check if the extracted substring consists only of digits
            print(digits)
        else: continue
    else: continue
    assName = "MA"+digits+"Night"

    nodeName = transform.name().split("_")[-1].split("|")[-1]
    new_name = str(ass_name + "_" + node_name).replace(":", "")

    lightFolder = lightRoot+assName
    if not os.path.isdir(lightFolder): continue
    maFile = lightFolder+"/"+assName+"_light.ma"
    refNode = pm.createReference(maFile,  namespace=new_name)
    lightGrp = pm.ls(new_name+":*",assemblies=True)[0]
    lightGrp.setTranslation([xformDict['tx'], xformDict['ty'], xformDict['tz']])
    lightGrp.setRotation([xformDict['rx'], xformDict['ry'], xformDict['rz']])
    lightGrp.setScale([xformDict['sx'], xformDict['sy'], xformDict['sz']])
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?