src/jmLightToolkit.py
def displayRadius(self):
        """ Create 'aiRadius' display from lights selected. """
        save_selected = pm.selected()
        # Get lights
        lights = self._onlyLightsFromSelection()
        if not lights:
            return None

        # Create mtoa utils grp
        utils_grp = self._eitherCreateGetNode("grp", self.mtoa_utils_grp)
        display_radius_grp = self._eitherCreateGetNode("grp", self.display_radius_grp)
        pm.parent(display_radius_grp, utils_grp)

        # Create shader
        if not pm.objExists("displayRadius_SHAD"):
            shader = pm.shadingNode("lambert", n="displayRadius_SHAD", asShader=True)
            shading_group= pm.sets(renderable=True, n="displayRadius_SDEG", noSurfaceShader=True, empty=True)
            pm.connectAttr('%s.outColor' % shader, '%s.surfaceShader' % shading_group)
            shader.color.set(0.0, 0.6, 0.7)
            shader.transparency.set(0.9, 0.9, 0.9)
            shader.translucence.set(1)
        else:
            shader = pm.PyNode("displayRadius_SHAD")

        # Process
        pm.select(save_selected)
        out = []
        for light in lights:
            attr_radius = "%s.aiRadius" % light
            # reloop if aiRaius not exist
            if not pm.objExists(attr_radius):
                continue

            # Reloop if display alradeay exist
            if pm.PyNode(attr_radius).inputs(type="expression"):
                continue

            # Create Display
            display_mesh_name = re.sub(
                r"^(?P<lightname>[A-Za-z0-9]+)(?P<under>[_])(?P<utility>[a-zA-Z]*)(?P<left>[A-Za-z0-9_]+)$",
                r"\g<lightname>\g<under>displayRadius\g<left>",
                light.name())

            display_mesh = pm.polySphere(n=display_mesh_name, subdivisionsAxis=36, subdivisionsHeight=36)[0]

            # assign shader
            pm.select(display_mesh)
            pm.hyperShade(assign=shader)

            # set attr
            display_mesh_shape = display_mesh.getShape()
            display_mesh_shape.attr("castsShadows").set(0)
            display_mesh_shape.attr("receiveShadows").set(0)
            display_mesh_shape.attr("motionBlur").set(0)
            display_mesh_shape.attr("primaryVisibility").set(0)
            display_mesh_shape.attr("smoothShading").set(0)
            display_mesh_shape.attr("visibleInReflections").set(0)
            display_mesh_shape.attr("visibleInRefractions").set(0)
            display_mesh_shape.attr("doubleSided").set(0)
            display_mesh_shape.attr("aiOpaque").set(0)
            display_mesh_shape.attr("aiVisibleInDiffuseReflection").set(0)
            display_mesh_shape.attr("aiVisibleInSpecularReflection").set(0)
            display_mesh_shape.attr("aiVisibleInDiffuseTransmission").set(0)
            display_mesh_shape.attr("aiVisibleInSpecularTransmission").set(0)
            display_mesh_shape.attr("aiSelfShadows").set(0)

            # Rotate
            display_mesh.rotateX.set(90)
            pm.select(display_mesh)
            pm.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1)
            display_mesh.rotateOrder.set(2)

            # Align mesh to light
            pm.pointConstraint(light, display_mesh)
            pm.pointConstraint(light, display_mesh, rm=True)
            pm.orientConstraint(light, display_mesh)
            pm.orientConstraint(light, display_mesh, rm=True)

            # Create new local space
            local_space_name = re.sub(
                r"^(?P<lightname>[A-Za-z0-9]+)(?P<under>[_])(?P<utility>[a-zA-Z]*)(?P<left>[A-Za-z0-9_]+)$",
                r"\g<lightname>\g<under>localSpaceRadius\g<left>",
                light.name())

            local_space_group = pm.group(em=True, n=local_space_name)
            pm.matchTransform(local_space_group, display_mesh)
            pm.parent(display_mesh, local_space_group)
            pm.parent(local_space_group, display_radius_grp)

            pm.pointConstraint(light, local_space_group)
            pm.orientConstraint(light, local_space_group)

            local_space_group.translate.lock()
            local_space_group.rotate.lock()
            local_space_group.scale.lock()

            # Constraint
            radius_value = pm.getAttr(attr_radius)
            display_mesh.scaleZ.set(radius_value)
            pm.expression(n="%s_radiusScaleZ_displayRadius" % light.name() ,s="{MESH_NAME}.scaleZ = {LIGHT}".format(
                LIGHT=attr_radius,
                MESH_NAME=display_mesh.name()) )

            pm.expression(n="%s_radiusScaleX_displayRadius" % light.name() ,s="{MESH_NAME}.scaleX = {LIGHT}".format(
                LIGHT=attr_radius,
                MESH_NAME=display_mesh.name()) )

            pm.expression(n="%s_radiusScaleY_displayRadius" % light.name() ,s="{MESH_NAME}.scaleY = {LIGHT}".format(
                LIGHT=attr_radius,
                MESH_NAME=display_mesh.name()) )

            # lock mesh attribute dont needed
            pm.select(display_mesh)
            pm.transformLimits(esz=(True, False), sz=(0, 999999))
            display_mesh.rotate.lock()
            display_mesh.translate.lock()
            display_mesh.scaleX.lock()
            display_mesh.scaleY.lock()

            display_mesh.overrideEnabled.set(1)
            display_mesh.overrideDisplayType.set(2)

            out.append(light)

        if out:
            _logger.info("Display Radius success" % ([lgt.name() for lgt in out]))
        else:
            _logger.info("No 'aiRadius' display created")

        pm.select(save_selected)
        self.__displayRadiusCSS()
        return out
 Create 'aiRadius' display from lights selected. 
Create 'aiRadius' display from lights selected.
Create ' aiRadius ' display from lights selected .
def displayRadius(self):
        save_selected = pm.selected()
        lights = self._onlyLightsFromSelection()
        if not lights:
            return None
        utils_grp = self._eitherCreateGetNode("grp", self.mtoa_utils_grp)
        display_radius_grp = self._eitherCreateGetNode("grp", self.display_radius_grp)
        pm.parent(display_radius_grp, utils_grp)
        if not pm.objExists("displayRadius_SHAD"):
            shader = pm.shadingNode("lambert", n="displayRadius_SHAD", asShader=True)
            shading_group= pm.sets(renderable=True, n="displayRadius_SDEG", noSurfaceShader=True, empty=True)
            pm.connectAttr('%s.outColor' % shader, '%s.surfaceShader' % shading_group)
            shader.color.set(0.0, 0.6, 0.7)
            shader.transparency.set(0.9, 0.9, 0.9)
            shader.translucence.set(1)
        else:
            shader = pm.PyNode("displayRadius_SHAD")
        pm.select(save_selected)
        out = []
        for light in lights:
            attr_radius = "%s.aiRadius" % light
            if not pm.objExists(attr_radius):
                continue
            if pm.PyNode(attr_radius).inputs(type="expression"):
                continue
            display_mesh_name = re.sub(
                r"^(?P<lightname>[A-Za-z0-9]+)(?P<under>[_])(?P<utility>[a-zA-Z]*)(?P<left>[A-Za-z0-9_]+)$",
                r"\g<lightname>\g<under>displayRadius\g<left>",
                light.name())
            display_mesh = pm.polySphere(n=display_mesh_name, subdivisionsAxis=36, subdivisionsHeight=36)[0]
            pm.select(display_mesh)
            pm.hyperShade(assign=shader)
            display_mesh_shape = display_mesh.getShape()
            display_mesh_shape.attr("castsShadows").set(0)
            display_mesh_shape.attr("receiveShadows").set(0)
            display_mesh_shape.attr("motionBlur").set(0)
            display_mesh_shape.attr("primaryVisibility").set(0)
            display_mesh_shape.attr("smoothShading").set(0)
            display_mesh_shape.attr("visibleInReflections").set(0)
            display_mesh_shape.attr("visibleInRefractions").set(0)
            display_mesh_shape.attr("doubleSided").set(0)
            display_mesh_shape.attr("aiOpaque").set(0)
            display_mesh_shape.attr("aiVisibleInDiffuseReflection").set(0)
            display_mesh_shape.attr("aiVisibleInSpecularReflection").set(0)
            display_mesh_shape.attr("aiVisibleInDiffuseTransmission").set(0)
            display_mesh_shape.attr("aiVisibleInSpecularTransmission").set(0)
            display_mesh_shape.attr("aiSelfShadows").set(0)
            display_mesh.rotateX.set(90)
            pm.select(display_mesh)
            pm.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1)
            display_mesh.rotateOrder.set(2)
            pm.pointConstraint(light, display_mesh)
            pm.pointConstraint(light, display_mesh, rm=True)
            pm.orientConstraint(light, display_mesh)
            pm.orientConstraint(light, display_mesh, rm=True)
            local_space_name = re.sub(
                r"^(?P<lightname>[A-Za-z0-9]+)(?P<under>[_])(?P<utility>[a-zA-Z]*)(?P<left>[A-Za-z0-9_]+)$",
                r"\g<lightname>\g<under>localSpaceRadius\g<left>",
                light.name())
            local_space_group = pm.group(em=True, n=local_space_name)
            pm.matchTransform(local_space_group, display_mesh)
            pm.parent(display_mesh, local_space_group)
            pm.parent(local_space_group, display_radius_grp)
            pm.pointConstraint(light, local_space_group)
            pm.orientConstraint(light, local_space_group)
            local_space_group.translate.lock()
            local_space_group.rotate.lock()
            local_space_group.scale.lock()
            radius_value = pm.getAttr(attr_radius)
            display_mesh.scaleZ.set(radius_value)
            pm.expression(n="%s_radiusScaleZ_displayRadius" % light.name() ,s="{MESH_NAME}.scaleZ = {LIGHT}".format(
                LIGHT=attr_radius,
                MESH_NAME=display_mesh.name()) )
            pm.expression(n="%s_radiusScaleX_displayRadius" % light.name() ,s="{MESH_NAME}.scaleX = {LIGHT}".format(
                LIGHT=attr_radius,
                MESH_NAME=display_mesh.name()) )
            pm.expression(n="%s_radiusScaleY_displayRadius" % light.name() ,s="{MESH_NAME}.scaleY = {LIGHT}".format(
                LIGHT=attr_radius,
                MESH_NAME=display_mesh.name()) )
            pm.select(display_mesh)
            pm.transformLimits(esz=(True, False), sz=(0, 999999))
            display_mesh.rotate.lock()
            display_mesh.translate.lock()
            display_mesh.scaleX.lock()
            display_mesh.scaleY.lock()
            display_mesh.overrideEnabled.set(1)
            display_mesh.overrideDisplayType.set(2)
            out.append(light)
        if out:
            _logger.info("Display Radius success" % ([lgt.name() for lgt in out]))
        else:
            _logger.info("No 'aiRadius' display created")
        pm.select(save_selected)
        self.__displayRadiusCSS()
        return out
def displayRadius ( self ) : save_selected = pm . selected ( ) lights = self . _onlyLightsFromSelection ( ) if not lights : return None utils_grp = self . _eitherCreateGetNode ( "grp" , self . mtoa_utils_grp ) display_radius_grp = self . _eitherCreateGetNode ( "grp" , self . display_radius_grp ) pm . parent ( display_radius_grp , utils_grp ) if not pm . objExists ( "displayRadius_SHAD" ) : shader = pm . shadingNode ( "lambert" , n = "displayRadius_SHAD" , asShader = True ) shading_group = pm . sets ( renderable = True , n = "displayRadius_SDEG" , noSurfaceShader = True , empty = True ) pm . connectAttr ( '%s.outColor' % shader , '%s.surfaceShader' % shading_group ) shader . color . set ( 0.0 , 0.6 , 0.7 ) shader . transparency . set ( 0.9 , 0.9 , 0.9 ) shader . translucence . set ( 1 ) else : shader = pm . PyNode ( "displayRadius_SHAD" ) pm . select ( save_selected ) out = [ ] for light in lights : attr_radius = "%s.aiRadius" % light if not pm . objExists ( attr_radius ) : continue if pm . PyNode ( attr_radius ) . inputs ( type = "expression" ) : continue display_mesh_name = re . sub ( r"^(?P<lightname>[A-Za-z0-9]+)(?P<under>[_])(?P<utility>[a-zA-Z]*)(?P<left>[A-Za-z0-9_]+)$" , r"\g<lightname>\g<under>displayRadius\g<left>" , light . name ( ) ) display_mesh = pm . polySphere ( n = display_mesh_name , subdivisionsAxis = 36 , subdivisionsHeight = 36 ) [ 0 ] pm . select ( display_mesh ) pm . hyperShade ( assign = shader ) display_mesh_shape = display_mesh . getShape ( ) display_mesh_shape . attr ( "castsShadows" ) . set ( 0 ) display_mesh_shape . attr ( "receiveShadows" ) . set ( 0 ) display_mesh_shape . attr ( "motionBlur" ) . set ( 0 ) display_mesh_shape . attr ( "primaryVisibility" ) . set ( 0 ) display_mesh_shape . attr ( "smoothShading" ) . set ( 0 ) display_mesh_shape . attr ( "visibleInReflections" ) . set ( 0 ) display_mesh_shape . attr ( "visibleInRefractions" ) . set ( 0 ) display_mesh_shape . attr ( "doubleSided" ) . set ( 0 ) display_mesh_shape . attr ( "aiOpaque" ) . set ( 0 ) display_mesh_shape . attr ( "aiVisibleInDiffuseReflection" ) . set ( 0 ) display_mesh_shape . attr ( "aiVisibleInSpecularReflection" ) . set ( 0 ) display_mesh_shape . attr ( "aiVisibleInDiffuseTransmission" ) . set ( 0 ) display_mesh_shape . attr ( "aiVisibleInSpecularTransmission" ) . set ( 0 ) display_mesh_shape . attr ( "aiSelfShadows" ) . set ( 0 ) display_mesh . rotateX . set ( 90 ) pm . select ( display_mesh ) pm . makeIdentity ( apply = True , t = 1 , r = 1 , s = 1 , n = 0 , pn = 1 ) display_mesh . rotateOrder . set ( 2 ) pm . pointConstraint ( light , display_mesh ) pm . pointConstraint ( light , display_mesh , rm = True ) pm . orientConstraint ( light , display_mesh ) pm . orientConstraint ( light , display_mesh , rm = True ) local_space_name = re . sub ( r"^(?P<lightname>[A-Za-z0-9]+)(?P<under>[_])(?P<utility>[a-zA-Z]*)(?P<left>[A-Za-z0-9_]+)$" , r"\g<lightname>\g<under>localSpaceRadius\g<left>" , light . name ( ) ) local_space_group = pm . group ( em = True , n = local_space_name ) pm . matchTransform ( local_space_group , display_mesh ) pm . parent ( display_mesh , local_space_group ) pm . parent ( local_space_group , display_radius_grp ) pm . pointConstraint ( light , local_space_group ) pm . orientConstraint ( light , local_space_group ) local_space_group . translate . lock ( ) local_space_group . rotate . lock ( ) local_space_group . scale . lock ( ) radius_value = pm . getAttr ( attr_radius ) display_mesh . scaleZ . set ( radius_value ) pm . expression ( n = "%s_radiusScaleZ_displayRadius" % light . name ( ) , s = "{MESH_NAME}.scaleZ = {LIGHT}" . format ( LIGHT = attr_radius , MESH_NAME = display_mesh . name ( ) ) ) pm . expression ( n = "%s_radiusScaleX_displayRadius" % light . name ( ) , s = "{MESH_NAME}.scaleX = {LIGHT}" . format ( LIGHT = attr_radius , MESH_NAME = display_mesh . name ( ) ) ) pm . expression ( n = "%s_radiusScaleY_displayRadius" % light . name ( ) , s = "{MESH_NAME}.scaleY = {LIGHT}" . format ( LIGHT = attr_radius , MESH_NAME = display_mesh . name ( ) ) ) pm . select ( display_mesh ) pm . transformLimits ( esz = ( True , False ) , sz = ( 0 , 999999 ) ) display_mesh . rotate . lock ( ) display_mesh . translate . lock ( ) display_mesh . scaleX . lock ( ) display_mesh . scaleY . lock ( ) display_mesh . overrideEnabled . set ( 1 ) display_mesh . overrideDisplayType . set ( 2 ) out . append ( light ) if out : _logger . info ( "Display Radius success" % ( [ lgt . name ( ) for lgt in out ] ) ) else : _logger . info ( "No 'aiRadius' display created" ) pm . select ( save_selected ) self . __displayRadiusCSS ( ) return out
Create 'aiRadius' display from lights selected.
Create ' aiRadius ' display from lights selected .
""" Create 'aiRadius' display from lights selected. """ # Get lights # Create mtoa utils grp # Create shader # Process # reloop if aiRaius not exist # Reloop if display alradeay exist # Create Display # assign shader # set attr # Rotate # Align mesh to light # Create new local space # Constraint # lock mesh attribute dont needed
self