Griffin Bajor

Light Link Visualizer

 

Light Link Visualizer

Developed to help minimize the tedium of working with light linking. This tool selects all lights that are lighting the selected object, or all objects that are lit by the selected light.

 

 
  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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import maya.cmds as mc
'''
    Light Link Visualizer by Griffin Bajor
    
    Select the light-linked objects or lights of whatever may be selected. 
    Default behavior is to determine if the selection is an object or light,
    and select the transforms of the linked opposite kinds of objects.


'''

class OptionsWindow(object):
    """Base Window Class"""

    def __init__(self):
        self.window = "optionsWindow"
        self.title = "OptionsWindow"
        self.size = (546, 350)

    def create(self):
        if mc.window(self.window, exists=True):
            mc.deleteUI(self.window, window=True)

        self.window = mc.window(self.window, title=self.title, widthHeight=self.size, menuBar=True)
        self.mainForm = mc.formLayout(nd=100)
        self.commandMenu()
        self.commonButtons()

        self.optionsForm = mc.formLayout(nd=100)
        self.displayOptions()
        mc.showWindow()

    def commandMenu(self):
        self.helpMenu = mc.menu(label="Help")
        self.helpMenuItem = mc.menuItem(label="Help on %s" % (self.title), command=self.helpMenuCmd)

    def helpMenuCmd(self, *args):
        mc.launch(web="http://maya-python.com")

    def actionCmd(self, *args):
        print "ACTION"

    def applyBtnCmd(self, *args):
        print "APPLY"

    def closeBtnCmd(self, *args):
        mc.deleteUI(self.window, window=True)

    def commonButtons(self):
        self.commonBtnSize = (self.size[0] - 18 / 3, 26)
        self.acctionBtn = mc.button(label="Action", height=self.commonBtnSize[1], command=self.actionCmd)
        self.applyBtn = mc.button(label="Apply", height=self.commonBtnSize[1], command=self.applyBtnCmd)
        self.closeBtn = mc.button(label="Close", height=self.commonBtnSize[1], command=self.closeBtnCmd)

        mc.formLayout(self.mainForm, e=True, attachForm=([self.acctionBtn, "left", 5],
                                                         [self.acctionBtn, "bottom", 5],
                                                         [self.applyBtn, "bottom", 5],
                                                         [self.closeBtn, "bottom", 5],
                                                         [self.closeBtn, "right", 5]),
                      attachPosition=([self.acctionBtn, "right", 1, 33],
                                      [self.closeBtn, "left", 0, 67]),
                      attachControl=([self.applyBtn, "left", 4, self.acctionBtn],
                                     [self.applyBtn, "right", 4, self.closeBtn]),
                      attachNone=([self.acctionBtn, "top"],
                                  [self.applyBtn, "top"],
                                  [self.closeBtn, "top"]))

    def displayOptions(self): pass

class MyOptionsWindow(OptionsWindow):

    def __init__(self):
        OptionsWindow.__init__(self)
        self.title = "Light Link Visualizer"
        self.size = (200, 150)


    def displayOptions(self):
    ############################################################################
    # Here insert custom controls

        self.col = mc.columnLayout(adjustableColumn=True, cal='center', cat=('both', 80), rs=10)

        mc.text(label='Select linked shape or lights of selection',h=50,ww=True)

        # Build radio buttons
        self.radioCollection = mc.radioCollection()
        self.radioAuto = mc.radioButton(label='Auto select based on type selected')
        self.radioLight = mc.radioButton(label='Select affected objects')
        self.radioObject = mc.radioButton(label='Select affected lights')

        # Have light centric selected by default
        mc.radioCollection(self.radioCollection, edit=True, select=self.radioAuto)

    def visLightLink(self,*args):

        # Build tool to select linked objects/lights if the opposite is selected

        mode = ''

        # Choose which mode to run
        if mc.radioButton(self.radioLight, query=True, select=True):
            mode = 'light'

        elif mc.radioButton(self.radioObject, query=True, select=True):
            mode = 'object'

        elif mc.radioButton(self.radioAuto, query=True, select=True):

            # If using auto, determine if selection is object or light
            selectionType = ()

            selection = mc.ls(selection=True)
            selection = mc.listRelatives(selection)
            selectionType = mc.nodeType(selection)

            if selectionType == 'mesh':
                mode = 'object'
                print 'Set mode to light'

            elif 'Light' in selectionType:
                mode = 'light'
                print 'Set mode to object'

            print 'Selection is a %s' % selectionType
            print mode


        # If light centric radio selected, run appropriate task
        if mode == 'light':
            print 'Selecting objects linked to selected light'

            # Get selected light
            selectedLight = mc.ls(selection=True)

            # Get objects linked to light(s) and filter to just the geometry
            linkedObjects = mc.lightlink(query=True, light=selectedLight)
            linkedObjects = mc.ls(linkedObjects, geometry=True)

            # Select linked objects
            mc.select(mc.listRelatives(linkedObjects, parent=True))

        # If object centric radio selected, run appropriate task
        elif mode == 'object':
            print 'Selecting lights linked to selected objects'

            # Get selected object
            selectedObject = mc.ls(selection=True)

            # Get lights linked to the object(s) and filter to just the lights
            linkedLights = mc.lightlink(query=True, object=selectedObject)
            linkedLights = mc.ls(linkedLights, lights=True)

            # Select linked lights
            mc.select(mc.listRelatives(linkedLights, parent=True))

        print 'Task complete'
        print '##################'


    def actionCmd(self, *args):
        self.visLightLink()
        mc.deleteUI(self.window, window=True)

    def applyBtnCmd(self, *args):
        self.visLightLink()



# Run GUI

def LightLinkVisualizer():
    win = MyOptionsWindow()
    win.create()


win = MyOptionsWindow()
win.create()