Griffin Bajor

Inrease Samples

 

 Set Light Samples

Used for the production on Miles saving us needing to traverse every light of every shot to double check all of our sample values.

 
 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
"""
SetLightSamples.py

Update Lighting Samples

Traverse through each lighting shot and Set all light's samples to the desired amount

"""

import maya.cmds as mc
import os

# Define variables
PATH_TO_SCENES = '\\\zod\\Students\\gbajor\\Tools Programming\\Midterm\\scenes\\'

SHOT_PREFIX = 'Lighting_'
SAMPLES = 4

# Define functions

# Function to to complete sun replacement operation
def update_samples(path, samples):
    """
    Runs a series of commands to replace a sun group with an updated version from an imported file

    Parameters:
        <string>path		path to directory
        <string>samples		number of samples
    """

    # Create list of lights
    lights = mc.ls(type=mc.listNodeTypes("light"))
    print 'Operating on %s' % lights
    mc.setAttr('aiSkyDomeLight1Shape1', 'aiSkyDomeLightShape1.aiSamples', 2)

    # Set samples for each light
    for i in lights:
        objAttr = '%s.aiSamples' % i
        mc.setAttr('%s.aiSamples' % i, samples)

        print 'Set %s to %s samples' % (i, samples)


def update_all_shots(path, prefix, SAMPLES):

    """
    Runs operation function on all lighting files in a given directory

    Parameters:
        <string>path		Path to directory to process
        <string>prefix		Prefix of all lighting files to process
    """

    shot_scenes = []

    # Build list of shot files
    for x in os.listdir(path):
        if x.startswith(prefix):
            shot_scenes.append(x)
    print 'Operating on %s' % shot_scenes

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

        # Run operation and check for error
        try:
            update_samples(PATH_TO_SCENES, SAMPLES)
        except:
            print '#### ERROR with %s - Unable to complete operation' % i

        # Save and check for error
        try:
            mc.file(s=True)

        except:
            print '#### ERROR with %s - Unable to save, may be set to read only' % i

        print '%s complete' % i

    print '##########################'
    print '##########################'
    print 'All Operations Complete'
    print '##########################'
    print '##########################'


# Test
update_all_shots(PATH_TO_SCENES, SHOT_PREFIX)