Hey ! 

I am making a script , where you can click 2 points on your mesh and it will 
make an Arealight between those 2 points and looks to my sphere.
But I have some flipping in my rotation when I add the light at the other side 
of my sphere. 


See video : https://www.youtube.com/watch?v=LGIE7hgg52I

If someone can help me would be amazing ! 



Here is my code : 

import maya.cmds as cmds






cmds.polySphere()
cmds.scale(5,5,5,)
cmds.rename('PainterObject')
    
draggerContextName = "myDragger"
lights=[]   






def dragger_onPress2():
    pos = cmds.draggerContext(draggerContextName, query = True, anchorPoint = 
True)
    
    
    
    #make locator for distance
    cmds.spaceLocator(name=('DistnaceLoc'))
    cmds.move(pos[0],pos[1],pos[2])
    
    if cmds.objExists('DistnaceLoc') and cmds.objExists('DistnaceLoc1'):
        posLoc1_X = cmds.getAttr('DistnaceLoc.translateX')
        posLoc1_Y = cmds.getAttr('DistnaceLoc.translateY')
        posLoc1_Z = cmds.getAttr('DistnaceLoc.translateZ')
        
        posLoc2_X = cmds.getAttr('DistnaceLoc1.translateX')
        posLoc2_Y = cmds.getAttr('DistnaceLoc1.translateY')
        posLoc2_Z = cmds.getAttr('DistnaceLoc1.translateZ')




        Distance = 
cmds.distanceDimension(startPoint=[posLoc1_X,posLoc1_Y,posLoc1_Z],endPoint=[posLoc2_X,posLoc2_Y,posLoc2_Z])
        #cmds.rename(Distance,'DistanceLocators')
        
        DistanceValue = cmds.getAttr(Distance + '.distance')
        print(DistanceValue)
        
        averagePosX = (posLoc1_X+posLoc2_X)/2
        averagePosY = (posLoc1_Y+posLoc2_Y)/2
        averagePosZ = (posLoc1_Z+posLoc2_Z)/2
       




          
        #create light
        lights.append(cmds.shadingNode('aiAreaLight', asLight=True))
        cmds.move(averagePosX,averagePosY,averagePosZ)
        cmds.scale((DistanceValue/2),0.1,1)
    
        cmds.rename(lights[len(lights)-1],'PainterLight_aiArealight'+'1')
    
        LastLight = len(lights) #hier returnt hij gewoon antaal lichten dat ik 
hem , kan ik dan gebruiken in mijn aim , zodat hij altijd mijn niuew licht 
constraint.    




        LastSelectLight = 'PainterLight_aiArealight'+str(LastLight)
        
            
        # Aimconstrain the light between the targets
        # mo=False so no offset
        ConstrainToLocator = cmds.aimConstraint('DistnaceLoc1', 
LastSelectLight, worldUpVector = (0,1,0), aimVector=(1,0,0), upVector = 
(0,1,0), mo = False)
        #cmds.delete(ConstrainToLocator)
    
        cmds.delete('DistnaceLoc','DistnaceLoc1')            


        
        
        RotlightX = cmds.getAttr(LastSelectLight+".rotateX")
        RotlightY = cmds.getAttr(LastSelectLight+".rotateY")
        RotlightZ = cmds.getAttr(LastSelectLight+".rotateZ")


        myNormalConstrain = 
cmds.normalConstraint('PainterObject','PainterLight_aiArealight'+str(LastLight),
 aimVector = (0,0,1), worldUpType = 
'scene',name='NormalConstrainToPainterObject')
        cmds.move(0,0,1,objectSpace=True, relative=True)
        cmds.delete(myNormalConstrain)


        cmds.rotate(0,0,RotlightZ,objectSpace=True,relative=True)


                   
def makeLightStripe():
    
    if cmds.objExists ('PainterObject'):
        cmds.select('PainterObject')
    
    # for getting the mousepoitionww
    if (cmds.contextInfo(draggerContextName, exists = True)):
        cmds.deleteUI(draggerContextName, toolContext = True )
    
    cmds.draggerContext(draggerContextName, pressCommand = 
dragger_onPress2,cursor = "crossHair", space="world",snapping=True)
    cmds.setToolTo(draggerContextName)


    #settting snapmode to points
    cmds.snapMode(point = True)
    
    
makeLightStripe()
    
    
           
       
    
           
       

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/ba409c11-7ba1-428c-adba-5696f17b038f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to