Griffin Bajor

Update References

 

Update Character References

Crucial in the deployment of Xgen hair on Miles while we were still using it, this deletes all character references and adds them back in in every shot, building the .xgen data files allowing for xgen to load the next time the scene is loaded. This saves about 15-20 minutes for every shot due to the load times involved. Instead we could run this script overnight with no human intervention.

 
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
import maya.cmds as mc
import pymel.core as pm
import os

"""
Builds .xgen files by re importing character rigs

"""

pathToLighting = '\\\zod\\ProjectX\\Rendering\\mcappiello_ProjectX_SP18\\Project_Miles\\scenes\\lighting\\temp\\'
pathToAnimation = '\\\zod\\ProjectX\\Rendering\\mcappiello_ProjectX_SP18\\Project_Miles\\scenes\\'
lightingPrefix = 'Lighting_'

animation_path = '\\\zod\\ProjectX\\Rendering\\mcappiello_ProjectX_SP18\\Project_Miles\\scenes\\'

def update_reference(animation_path):
    """
     Build xgen files along lighting file by removing all references with clean up
     and re adding characters

     Parameters:
         <string>animation_path     path to animation files
     """

    ref_list = mc.ls(type='reference')


    # Begin loop to remove all references
    for i in ref_list:
        if i.startswith('Scene_'):
            ref_file_name = ref_list[ref_list.index(i)][:-2]
            print 'Removing reference %s' % ref_file_name

            path_to_reference = mc.referenceQuery(i, filename = True)

            mc.file(path_to_reference, rr=True)

            break



    # Delete all namespaces
    # Gathering and deleting all namespaces
    name_space = [item for item in pm.namespaceInfo(lon=True, recurse=True) if item not in ["UI", "shared"]]

    # Sort them from child to parent, That's order we need to delete
    sorted_ns_namespace = sorted(name_space, key=lambda ns: ns.count(':'), reverse=True)

    for ns in sorted_ns_namespace:
        pm.namespace(removeNamespace=ns, mergeNamespaceWithParent=True)

    print '## Removed all references'

    # Delete excess xgen
    xgen_descriptions = mc.ls(type='xgmPalette')
    mc.delete(xgen_descriptions)

    print '## Removed excess xgen nodes'

    # Add back rig references
    sherri_path = '\\\zod\\ProjectX\\Rendering\\mcappiello_ProjectX_SP18\\Project_Miles\\assets\\Characters\\Sherri\\scenes\\Sherri_Rig.ma'
    mc.file(sherri_path, r=True, namespace='Sherri_Rig')

    kevin_path = '\\\zod\\ProjectX\\Rendering\\mcappiello_ProjectX_SP18\\Project_Miles\\assets\\Characters\\Kevin\\scenes\\Kevin_Rig.ma'
    mc.file(kevin_path, r=True, namespace='Kevin_Rig')

    print '## Added back character rigs'

    print 'File complete'


def operate_on_files(path_lighting, prefix):
    """
    Get xgen almost working on all lighting files

    Parameters:
    <string>path_lighting       path to lighting files
    <string>prefix              prefix of all files to work on
    """

    # Build list of lighting scenes
    shot_scenes = []
    for x in os.listdir(path_lighting):
        if x.startswith(prefix):
            shot_scenes.append(x)
    print 'Working on: %s' % shot_scenes

    for i in shot_scenes:
        # Open each file
        print '##########################'
        print 'Working on %s' % i
        mc.file(os.path.join(path_lighting, i), o=True, f=True)

        # Run fixup
        update_reference(pathToAnimation)

    print '######################'
    print '######################'
    print 'All tasks complete'


operate_on_files(pathToLighting, lightingPrefix)