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']])