コード例 #1
0
    def getMessage(self, *a, **kw):
        """ 
        Get and store attribute value as if they were messages. Used for bufferFactory to use a connected
        attribute as a poor man's attribute message function
        
        Keyword arguments:
        *a, **kw
        """
        try:
            if self.form == 'message':
                self.value = attributes.returnMessageObject(
                    self.obj.nameShort, self.attr)
                if search.returnObjectType(self.value) == 'reference':
                    if attributes.repairMessageToReferencedTarget(
                            self.obj.nameLong, self.attr, *a, **kw):
                        self.value = attributes.returnMessageObject(
                            self.obj.nameShort, self.attr)
            else:
                self.value = attributes.returnDriverAttribute(
                    "%s.%s" % (self.obj.nameShort, self.attr))

            guiFactory.report("'%s.%s' >Message> '%s'" %
                              (self.obj.nameShort, self.attr, self.value))
            return self.value

        except:
            guiFactory.warning("'%s.%s' failed to get" %
                               (self.obj.nameShort, self.attr))
コード例 #2
0
    def doAlias(self, arg):
        """ 
        Set the alias of an attribute
        
        Keyword arguments:
        arg(string) -- name you want to use as an alias
        """
        assert type(
            arg) is str or unicode, "Must pass string argument into doAlias"
        if arg:
            try:
                if arg != self.nameAlias:
                    if mc.aliasAttr(arg, self.nameCombined):
                        self.nameAlias = arg
                else:
                    guiFactory.report("'%s.%s' already has that alias!" %
                                      (self.obj.nameShort, self.attr, arg))

            except:
                guiFactory.warning("'%s.%s' failed to set alias of '%s'!" %
                                   (self.obj.nameShort, self.attr, arg))

        else:
            if self.nameAlias:
                self.attr = self.nameLong
                mc.aliasAttr(self.nameCombined, remove=True)
                self.nameAlias = False
                self.updateData()
コード例 #3
0
def ObjectFacesToFolicles():
    try:
        import parentConstraintToSurface
    except:
        "Can't find parentConstraintToSurface"

    selection = mc.ls(sl=True) or []
    if not selection:
        return "Nothing selected"

    #If we're going, create a return set
    returnSet = SetFactory.SetFactory('folicledLocs', 'td', True)

    # Make some groups
    mLocGroup = mc.group(em=True, name='locators_grp')

    number = len(selection)
    returnList = []
    for i, o in enumerate(selection):
        guiFactory.report("On %s. %s of %s" % (o, i, number))
        faceBuffer = "%s.f[4]" % o
        if not mc.objExists(faceBuffer):
            print "'%s' has no face!" % o

        loc = locators.locMeObject(faceBuffer)
        returnSet.store(loc)
        mc.select(cl=True)
        mc.select(loc, o)
        parentConstraintToSurface.parentConstraintToSurface()

        rigging.doParentReturnName(loc, mLocGroup)

    follicles = mc.ls(type='follicle')
    mc.select(follicles)
    mc.group(name='folicles_grp')
コード例 #4
0
 def removeTargetMesh(self,mesh):
     """
     Remove target mesh to the tool
     """
     if mesh in self.meshList:
         self.meshList.remove(mesh) 
         guiFactory.report("'%s' removed from '%s'"%(mesh,self.name))
コード例 #5
0
 def removeTargetMesh(self, mesh):
     """
     Remove target mesh to the tool
     """
     if mesh in self.meshList:
         self.meshList.remove(mesh)
         guiFactory.report("'%s' removed from '%s'" % (mesh, self.name))
コード例 #6
0
ファイル: AttrFactory.py プロジェクト: GuidoPollini/MuTools
 def doAlias(self,arg):
     """ 
     Set the alias of an attribute
     
     Keyword arguments:
     arg(string) -- name you want to use as an alias
     """     
     assert type(arg) is str or unicode,"Must pass string argument into doAlias"                
     if arg:
         try:
             if arg != self.nameAlias:
                 if mc.aliasAttr(arg,self.nameCombined):
                     self.nameAlias = arg
             else:
                 guiFactory.report("'%s.%s' already has that alias!"%(self.obj.nameShort,self.attr,arg))
                 
         except:
             guiFactory.warning("'%s.%s' failed to set alias of '%s'!"%(self.obj.nameShort,self.attr,arg))
                 
     else:
         if self.nameAlias:
             self.attr = self.nameLong                
             mc.aliasAttr(self.nameCombined,remove=True)
             self.nameAlias = False
             self.updateData()
コード例 #7
0
 def toggle(self):
     """
     Toggles an int type variable
     """
     assert self.form == 'int',"'%s' not an int type var"%(self.name)
     
     mc.optionVar(iv = (self.name,not self.value))
     self.value = not self.value
     guiFactory.report("'%s':%s"%(self.name,self.value))
コード例 #8
0
    def doLocked(self, arg=True):
        """ 
        Set lock state of an attribute
        
        Keyword arguments:
        arg(bool)
        """
        assert type(arg) is bool, "doLocked arg must be a bool!"
        if arg:
            if self.children:
                guiFactory.warning(
                    "'%s' has children, running set command on '%s'" %
                    (self.nameCombined, "','".join(self.children)))
                for c in self.children:
                    cInstance = AttrFactory(self.obj.nameShort, c)
                    if not cInstance.locked:
                        mc.setAttr(
                            (cInstance.obj.nameShort + '.' + cInstance.attr),
                            e=True,
                            lock=True)
                        guiFactory.report(
                            "'%s.%s' locked!" %
                            (cInstance.obj.nameShort, cInstance.attr))
                        cInstance.locked = True
                self.updateData()

            elif not self.locked:
                mc.setAttr((self.obj.nameShort + '.' + self.attr),
                           e=True,
                           lock=True)
                guiFactory.report("'%s.%s' locked!" %
                                  (self.obj.nameShort, self.attr))
                self.locked = True

        else:
            if self.children:
                guiFactory.warning(
                    "'%s' has children, running set command on '%s'" %
                    (self.nameCombined, "','".join(self.children)))
                for c in self.children:
                    cInstance = AttrFactory(self.obj.nameShort, c)
                    if cInstance.locked:
                        mc.setAttr(
                            (cInstance.obj.nameShort + '.' + cInstance.attr),
                            e=True,
                            lock=False)
                        guiFactory.report(
                            "'%s.%s' unlocked!" %
                            (cInstance.obj.nameShort, cInstance.attr))
                        cInstance.locked = False
                self.updateData()

            elif self.locked:
                mc.setAttr((self.obj.nameShort + '.' + self.attr),
                           e=True,
                           lock=False)
                guiFactory.report("'%s.%s' unlocked!" %
                                  (self.obj.nameShort, self.attr))
                self.locked = False
コード例 #9
0
 def release(self):
     """
     Store current data to return buffers
     """
     if self.posBuffer:
         guiFactory.report("Position data : %s "%(self.returnList))
     if self.createModeBuffer:
         guiFactory.report("Created : %s "%(self.createModeBuffer))
         mc.select(cl=True)
             
     #Only store return values on release
     if self.posBuffer:
         for p in self.posBuffer:
             self.returnList.append(p)            
     if self.createModeBuffer:
         self.createdList.extend(self.createModeBuffer)
コード例 #10
0
 def release(self,debugReport = False):
     """
     Store current data to return buffers
     """
     if self.posBuffer:
         if debugReport:guiFactory.report("Position data : %s "%(self.returnList))
     if self.createModeBuffer:
         if debugReport:guiFactory.report("Created : %s "%(self.createModeBuffer))
         mc.select(cl=True)
             
     #Only store return values on release
     if self.posBuffer:
         for p in self.posBuffer:
             self.returnList.append(p)            
     if self.createModeBuffer:
         self.createdList.extend(self.createModeBuffer)
コード例 #11
0
ファイル: AttrFactory.py プロジェクト: GuidoPollini/MuTools
 def setEnum(self,enumCommand):
     """ 
     Set the options for an enum attribute
     
     Keyword arguments:
     enumCommand(string) -- 'off:on', 'off=0:on=2', etc
     """   
     try:
         if self.form == 'enum':
             mc.addAttr ((self.obj.nameShort+'.'+self.attr), e = True, at=  'enum', en = enumCommand)
             self.enum = enumCommand
             guiFactory.report("'%s.%s' has been updated!"%(self.obj.nameShort,self.attr))
             
         else:
             guiFactory.warning("'%s.%s' is not an enum. Invalid call"%(self.obj.nameShort,self.attr))
         
     except:
         guiFactory.warning("'%s.%s' failed to change..."%(self.obj.nameShort,self.attr))
コード例 #12
0
ファイル: AttrFactory.py プロジェクト: smdharris/config
    def getMessage(self,*a, **kw):
        """ 
        Get and store attribute value as if they were messages. Used for bufferFactory to use a connected
        attribute as a poor man's attribute message function
        
        Keyword arguments:
        *a, **kw
        """   
        try:
            if self.form == 'message':
                self.value = attributes.returnMessageObject(self.obj.nameShort,self.attr)
            else:
                self.value = attributes.returnDriverAttribute("%s.%s"%(self.obj.nameShort,self.attr))

            guiFactory.report("'%s.%s' >Message> '%s'"%(self.obj.nameShort,self.attr,self.value))
            return self.value
            
        except:
            guiFactory.warning("'%s.%s' failed to get"%(self.obj.nameShort,self.attr))
コード例 #13
0
ファイル: AttrFactory.py プロジェクト: GuidoPollini/MuTools
 def doRename(self,arg):
     """ 
     Rename an attribute as something else
     
     Keyword arguments:
     arg(string) -- name you want to use as a nice name
     """            
     assert type(arg) is str or unicode,"Must pass string argument into doRename"
     if arg:
         try:
             if arg != self.nameLong:
                 attributes.doRenameAttr(self.obj.nameShort,self.nameLong,arg)
                 self.attr = arg
                 self.updateData()
                 
             else:
                 guiFactory.report("'%s.%s' already has that nice name!"%(self.obj.nameShort,self.attr,arg))
                 
         except:
             guiFactory.warning("'%s.%s' failed to rename name of '%s'!"%(self.obj.nameShort,self.attr,arg))
コード例 #14
0
 def set(self,value):
     if self.form == 'int':
         try:
             mc.optionVar(iv = (self.name,value))
             self.value = value
         except:
             guiFactory.warning("'%s' couldn't be added to '%s' of type '%s'"%(value,self.name,self.form))
         
     elif self.form == 'float':
         try:
             mc.optionVar(fv = (self.name,value))
             self.value = value
             
         except:
             guiFactory.report("'%s' couldn't be added to '%s' of type '%s'"%(value,self.name,self.form))
         
     elif self.form == 'string':
         try:
             mc.optionVar(sv = (self.name,str(value)))
             self.value = value
             
         except:
             guiFactory.report("'%s' couldn't be added to '%s' of type '%s'"%(value,self.name,self.form))
コード例 #15
0
ファイル: AttrFactory.py プロジェクト: GuidoPollini/MuTools
    def doKeyable(self,arg = True):
        """ 
        Set keyable state of an attribute
        
        Keyword arguments:
        arg(bool)
        """         
        assert type(arg) is bool, "doLocked arg must be a bool!"        
        if arg:
            if self.children:
                guiFactory.warning("'%s' has children, running set command on '%s'"%(self.nameCombined,"','".join(self.children)))
                for c in self.children:
                    cInstance = AttrFactory(self.obj.nameShort,c)                                            
                    if not cInstance.keyable:
                        mc.setAttr(cInstance.nameCombined,e=True,keyable = True) 
                        guiFactory.report("'%s.%s' keyable!"%(cInstance.obj.nameShort,cInstance.attr))
                        cInstance.keyable = True
                        cInstance.hidden = False

                
            elif not self.keyable:
                mc.setAttr((self.obj.nameShort+'.'+self.attr),e=True,keyable = True) 
                guiFactory.report("'%s.%s' keyable!"%(self.obj.nameShort,self.attr))
                self.keyable = True
                self.hidden = False
                    
                
        else:
            if self.children:
                guiFactory.warning("'%s' has children, running set command on '%s'"%(self.nameCombined,"','".join(self.children)))
                for c in self.children:
                    cInstance = AttrFactory(self.obj.nameShort,c)                                            
                    if cInstance.keyable:
                        mc.setAttr((cInstance.obj.nameShort+'.'+cInstance.attr),e=True,keyable = False) 
                        guiFactory.report("'%s.%s' unkeyable!"%(cInstance.obj.nameShort,cInstance.attr))
                        cInstance.keyable = False
                        if not mc.getAttr(cInstance.nameCombined,channelBox=True):
                            cInstance.updateData()
                            cInstance.doHidden(False)                
                
            elif self.keyable:
                mc.setAttr((self.obj.nameShort+'.'+self.attr),e=True,keyable = False)           
                guiFactory.report("'%s.%s' unkeyable!"%(self.obj.nameShort,self.attr))
                self.keyable = False
                if not mc.getAttr(self.nameCombined,channelBox=True):
                    self.updateData()
                    self.doHidden(False)
コード例 #16
0
    def doRename(self, arg):
        """ 
        Rename an attribute as something else
        
        Keyword arguments:
        arg(string) -- name you want to use as a nice name
        """
        assert type(
            arg) is str or unicode, "Must pass string argument into doRename"
        if arg:
            try:
                if arg != self.nameLong:
                    attributes.doRenameAttr(self.obj.nameShort, self.nameLong,
                                            arg)
                    self.attr = arg
                    self.updateData()

                else:
                    guiFactory.report("'%s.%s' already has that nice name!" %
                                      (self.obj.nameShort, self.attr, arg))

            except:
                guiFactory.warning("'%s.%s' failed to rename name of '%s'!" %
                                   (self.obj.nameShort, self.attr, arg))
コード例 #17
0
    def append(self,value): 
        if type(self.value) is list:
            if value in self.value:
                return guiFactory.warning("'%s' already added"%(value))

        if self.form == 'int':
            try:
                mc.optionVar(iva = (self.name,int(value)))
                self.update(self.form)
                guiFactory.report("'%s' added to '%s'"%(value,self.name))
                
            except:
                guiFactory.warning("'%s' couldn't be added to '%s' of type '%s'"%(value,self.name,self.form))
            
        elif self.form == 'float':
            try:
                mc.optionVar(fva = (self.name,value))
                self.update(self.form)
                guiFactory.report("'%s' added to '%s'"%(value,self.name))
                
            except:
                guiFactory.report("'%s' couldn't be added to '%s' of type '%s'"%(value,self.name,self.form))
            
        elif self.form == 'string':
            try:
                mc.optionVar(sva = (self.name,str(value)))
                for i in "",'':
                    if i in self.value:
                        self.remove(i)

                self.update(self.form)
                guiFactory.report("'%s' added to '%s'"%(value,self.name))
                             
                
            except:
                guiFactory.report("'%s' couldn't be added to '%s' of type '%s'"%(value,self.name,self.form))
コード例 #18
0
    def setEnum(self, enumCommand):
        """ 
        Set the options for an enum attribute
        
        Keyword arguments:
        enumCommand(string) -- 'off:on', 'off=0:on=2', etc
        """
        try:
            if self.form == 'enum':
                mc.addAttr((self.obj.nameShort + '.' + self.attr),
                           e=True,
                           at='enum',
                           en=enumCommand)
                self.enum = enumCommand
                guiFactory.report("'%s.%s' has been updated!" %
                                  (self.obj.nameShort, self.attr))

            else:
                guiFactory.warning("'%s.%s' is not an enum. Invalid call" %
                                   (self.obj.nameShort, self.attr))

        except:
            guiFactory.warning("'%s.%s' failed to change..." %
                               (self.obj.nameShort, self.attr))
コード例 #19
0
ファイル: project_02012.py プロジェクト: GuidoPollini/MuTools
def ObjectFacesToFolicles():
    try:
	import parentConstraintToSurface
    except:
	"Can't find parentConstraintToSurface"
	
    selection = mc.ls(sl=True) or []
    if not selection:
	return "Nothing selected"
    
    #If we're going, create a return set
    returnSet = SetFactory.SetFactory('folicledLocs','td',True)
    
    # Make some groups
    mLocGroup = mc.group(em=True,name = 'locators_grp')   
    
    number = len(selection)
    returnList = []
    for i,o in enumerate(selection):
	guiFactory.report("On %s. %s of %s"%(o,i,number))
	faceBuffer = "%s.f[4]"%o
	if not mc.objExists(faceBuffer):
	    print "'%s' has no face!"%o
	    
	loc = locators.locMeObject(faceBuffer)
	returnSet.store(loc)	
	mc.select(cl=True)
	mc.select(loc,o)
	parentConstraintToSurface.parentConstraintToSurface()
	
	rigging.doParentReturnName(loc,mLocGroup)
	
    
    follicles = mc.ls(type='follicle')
    mc.select(follicles)
    mc.group(name = 'folicles_grp')
コード例 #20
0
 def remove(self,value):
     if value in self.value:
         try:         
             i = self.value.index(value)
             mc.optionVar(removeFromArray = (self.name,i))
             self.update(self.form)
             guiFactory.report("'%s' removed from '%s'"%(value,self.name))
         except:
             guiFactory.report("'%s' failed to remove '%s'"%(value,self.name))
     else:
         guiFactory.report("'%s' wasn't found in '%s'"%(value,self.name))
コード例 #21
0
ファイル: AttrFactory.py プロジェクト: GuidoPollini/MuTools
 def doLocked(self,arg = True):
     """ 
     Set lock state of an attribute
     
     Keyword arguments:
     arg(bool)
     """ 
     assert type(arg) is bool, "doLocked arg must be a bool!"
     if arg:
         if self.children:
             guiFactory.warning("'%s' has children, running set command on '%s'"%(self.nameCombined,"','".join(self.children)))
             for c in self.children:
                 cInstance = AttrFactory(self.obj.nameShort,c)                                            
                 if not cInstance.locked:
                     mc.setAttr((cInstance.obj.nameShort+'.'+cInstance.attr),e=True,lock = True) 
                     guiFactory.report("'%s.%s' locked!"%(cInstance.obj.nameShort,cInstance.attr))
                     cInstance.locked = True
             self.updateData()  
             
         elif not self.locked:
             mc.setAttr((self.obj.nameShort+'.'+self.attr),e=True,lock = True) 
             guiFactory.report("'%s.%s' locked!"%(self.obj.nameShort,self.attr))
             self.locked = True
             
     else:
         if self.children:
             guiFactory.warning("'%s' has children, running set command on '%s'"%(self.nameCombined,"','".join(self.children)))
             for c in self.children:
                 cInstance = AttrFactory(self.obj.nameShort,c)                                            
                 if cInstance.locked:
                     mc.setAttr((cInstance.obj.nameShort+'.'+cInstance.attr),e=True,lock = False) 
                     guiFactory.report("'%s.%s' unlocked!"%(cInstance.obj.nameShort,cInstance.attr))
                     cInstance.locked = False
             self.updateData()  
             
         elif self.locked:
             mc.setAttr((self.obj.nameShort+'.'+self.attr),e=True,lock = False)           
             guiFactory.report("'%s.%s' unlocked!"%(self.obj.nameShort,self.attr))
             self.locked = False
コード例 #22
0
def findMeshIntersection(mesh, raySource, rayDir, maxDistance = 1000):
    """
    Thanks to Deane @ https://groups.google.com/forum/?fromgroups#!topic/python_inside_maya/n6aJq27fg0o%5B1-25%5D
    
    Return the closest point on a surface from a raySource and rayDir
    
    Arguments
    mesh(string) -- currently poly surface only
    raySource(double3) -- point in world space
    rayDir(double3) -- world space vector
    
    returns hitpoint(double3)
    """    
    #Create an empty selection list.
    selectionList = om.MSelectionList()

    #Put the mesh's name on the selection list.
    selectionList.add(mesh)

    #Create an empty MDagPath object.
    meshPath = om.MDagPath()

    #Get the first item on the selection list (which will be our mesh)
    #as an MDagPath.
    selectionList.getDagPath(0, meshPath)

    #Create an MFnMesh functionset to operate on the node pointed to by
    #the dag path.
    meshFn = om.MFnMesh(meshPath)

    #Convert the 'raySource' parameter into an MFloatPoint.
    raySource = om.MFloatPoint(raySource[0], raySource[1], raySource[2])

    #Convert the 'rayDir' parameter into an MVector.`
    rayDirection = om.MFloatVector(rayDir[0], rayDir[1], rayDir[2])

    #Create an empty MFloatPoint to receive the hit point from the call.
    hitPoint = om.MFloatPoint()

    #Set up a variable for each remaining parameter in the
    #MFnMesh::closestIntersection call. We could have supplied these as
    #literal values in the call, but this makes the example more readable.
    sortIds = False
    maxDist = om.MDistance.internalToUI(1000000)# This needs work    
    #maxDist = om.MDistance.internalToUI(maxDistance) # This needs work
    bothDirections = False
    noFaceIds = None
    noTriangleIds = None
    noAccelerator = None
    noHitParam = None
    noHitFace = None
    noHitTriangle = None
    noHitBary1 = None
    noHitBary2 = None

    #Get the closest intersection.
    gotHit = meshFn.closestIntersection(
        raySource, rayDirection,
        noFaceIds, noTriangleIds,
        sortIds, om.MSpace.kWorld, maxDist, bothDirections,
        noAccelerator,
        hitPoint,
        noHitParam, noHitFace, noHitTriangle, noHitBary1, noHitBary2)
    
    #Return the intersection as a Pthon list.
    if gotHit:
        #Thank you Mattias Bergbom, http://bergbom.blogspot.com/2009/01/float2-and-float3-in-maya-python-api.html
        hitMPoint = om.MPoint(hitPoint) # Thank you Capper on Tech-artists.org          
        pArray = [0.0,0.0]
        x1 = om.MScriptUtil()
        x1.createFromList( pArray, 2 )
        uvPoint = x1.asFloat2Ptr()
        uvSet = None
        closestPolygon=None
        uvReturn = meshFn.getUVAtPoint(hitMPoint,uvPoint,om.MSpace.kWorld)
        
        uValue = om.MScriptUtil.getFloat2ArrayItem(uvPoint, 0, 0) or False
        vValue = om.MScriptUtil.getFloat2ArrayItem(uvPoint, 0, 1) or False
        if debugReport:guiFactory.report("Hit! [%s,%s,%s]"%(hitPoint.x, hitPoint.y, hitPoint.z))
        if uValue and vValue:
            return {'hit':[hitPoint.x, hitPoint.y, hitPoint.z],'source':[raySource.x,raySource.y,raySource.z],'uv':[uValue,vValue]}                
        else:
            return {'hit':[hitPoint.x, hitPoint.y, hitPoint.z],'source':[raySource.x,raySource.y,raySource.z],'uv':False}
    else:
        return None    
コード例 #23
0
def placerLocsToCubey():
    import random
    from cgm.lib import position
    selection = mc.ls(sl=True) or []
    mStable = [
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male1.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male2.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male3.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male4.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male5.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male6.ma'
    ]
    fStable = [
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/female1.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/female2.ma',
        'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/female3.ma'
    ]

    maleFileCnt = 0
    femaleFileCnt = 0
    maleCnt = 0
    femCnt = 0

    length = len(selection)
    for i, loc in enumerate(selection):
        guiFactory.report("On %s of %s" % (i, length))

        #Pick a sex
        sexInt = random.randint(0, 10)
        sex = 'male'
        if sexInt in [2, 3]:
            sex = 'female'

        guiFactory.report("sex is '%s'" % sex)

        #Pick a file
        if sex is 'male':
            locFile = mStable[maleFileCnt]
            maleFileCnt += 1
            maleCnt += 1
            if not maleFileCnt < len(mStable):
                maleFileCnt = 0
            locNameSpace = 'male_%s' % maleCnt
        else:
            locFile = fStable[femaleFileCnt]
            femaleFileCnt += 1
            femCnt += 1
            if not femaleFileCnt < len(fStable):
                femaleFileCnt = 0
            locNameSpace = 'female_%s' % femCnt

        guiFactory.report("File is '%s'" % locFile)

        #Import the file
        mc.file(locFile,
                i=True,
                namespace=locNameSpace,
                pr=True,
                force=True,
                prompt=False)  # prompt means no error message
        buffer = mc.ls('%s:*' % locNameSpace)

        if not 'RN' in buffer[0]:
            return guiFactory.warning('Failed to find name space')

        splitBuffer = buffer[0].split('RN')
        realLocNameSpace = splitBuffer[0]

        #Snap Master constraint group and constrain to loc
        nestedNameSpace = 'male'
        if sex == 'female':
            nestedNameSpace = 'female'

        snappingObject = ('%s:%s:Cubey_masterAnim_constraint_grp' %
                          (locNameSpace, nestedNameSpace))
        if not mc.objExists(snappingObject):
            return "Snapping object doesn't exist = '%s'" % snappingObject
        position.moveParentSnap(snappingObject, loc)

        masterObject = ('%s:%s:Cubey_masterAnim' %
                        (locNameSpace, nestedNameSpace))
        if not mc.objExists(masterObject):
            return "Master object doesn't exist = '%s'" % masterObject

        mc.parentConstraint(loc, snappingObject, maintainOffset=False)
        if sex == 'male':
            attributes.doSetAttr(masterObject, 'tz', .606)
        attributes.doSetAttr(masterObject, 'rz', -90)

        #Randomize
        if sex == 'male':
            randomizeCubey('%s:%s' % (locNameSpace, nestedNameSpace))
        if sex == 'female':
            randomizeCubette('%s:%s' % (locNameSpace, nestedNameSpace))
コード例 #24
0
    def doCopyTo(self, target, targetAttrName=None, debug=True, *a, **kw):
        """                                     
        Replacement for Maya's since maya's can't handle shapes....blrgh...
        Copy attributes from one object to another as well as other options. If the attribute already
        exists, it'll copy the values. If it doesn't, it'll make it. If it needs to convert, it can.
        It will not make toast.
    
        Keywords:
        toObject(string) - obj to copy to
        targetAttrName(string) -- name of the attr to copy to . Default is None which will create an 
                          attribute oft the fromAttr name on the toObject if it doesn't exist
        convertToMatch(bool) -- whether to convert if necessary.default True        
        values(bool) -- copy values. default True
        inputConnections(bool) -- default False
        outGoingConnections(bool) -- default False
        keepSourceConnections(bool)-- keeps connections on source. default True
        copyAttrSettings(bool) -- copy the attribute state of the fromAttr (keyable,lock,hidden). default True
        connectSourceToTarget(bool) useful for moving attribute controls to another object. default False
        
        RETURNS:
        success(bool)
        """
        assert mc.objExists(target), "'%s' doesn't exist" % target
        assert mc.ls(target, long=True) != [self.obj.nameShort
                                            ], "Can't transfer to self!"
        functionName = 'doCopyTo'

        convertToMatch = kw.pop('convertToMatch', True)
        values = kw.pop('values', True)
        inputConnections = kw.pop('inputConnections', False)
        outgoingConnections = kw.pop('outgoingConnections', False)
        keepSourceConnections = kw.pop('keepSourceConnections', True)
        copyAttrSettings = kw.pop('copyAttrSettings', True)
        connectSourceToTarget = kw.pop('connectSourceToTarget', False)
        connectTargetToSource = kw.pop('connectTargetToSource', False)

        if debug:
            guiFactory.doPrintReportStart(functionName)
            guiFactory.report("AttrFactory instance: '%s'" % self.nameCombined)
            guiFactory.report("convertToMatch: '%s'" % convertToMatch)
            guiFactory.report("targetAttrName: '%s'" % targetAttrName)
            guiFactory.report("inputConnections: '%s'" % inputConnections)
            guiFactory.report("outgoingConnections: '%s'" %
                              outgoingConnections)
            guiFactory.report("keepSourceConnections: '%s'" %
                              keepSourceConnections)
            guiFactory.report("copyAttrSettings: '%s'" % copyAttrSettings)
            guiFactory.report("connectSourceToTarget: '%s'" %
                              connectSourceToTarget)
            guiFactory.report("keepSourceConnections: '%s'" %
                              keepSourceConnections)
            guiFactory.report("connectTargetToSource: '%s'" %
                              connectTargetToSource)
            guiFactory.doPrintReportBreak()

        copyTest = [
            values, inputConnections, outgoingConnections,
            keepSourceConnections, connectSourceToTarget, copyAttrSettings
        ]

        if sum(copyTest) < 1:
            guiFactory.warning(
                "You must have at least one option for copying selected. Otherwise, you're looking for the 'doDuplicate' function."
            )
            return False

        if '.' in list(target):
            targetBuffer = target.split('.')
            if len(targetBuffer) == 2:
                attributes.doCopyAttr(
                    self.obj.nameShort,
                    self.nameLong,
                    targetBuffer[0],
                    targetBuffer[1],
                    convertToMatch=convertToMatch,
                    values=values,
                    inputConnections=inputConnections,
                    outgoingConnections=outgoingConnections,
                    keepSourceConnections=keepSourceConnections,
                    copyAttrSettings=copyAttrSettings,
                    connectSourceToTarget=connectSourceToTarget)

            else:
                guiFactory.warning(
                    "Yeah, not sure what to do with this. Need an attribute call with only one '.'"
                )
        else:
            attributes.doCopyAttr(self.obj.nameShort,
                                  self.nameLong,
                                  target,
                                  targetAttrName,
                                  convertToMatch=convertToMatch,
                                  values=values,
                                  inputConnections=inputConnections,
                                  outgoingConnections=outgoingConnections,
                                  keepSourceConnections=keepSourceConnections,
                                  copyAttrSettings=copyAttrSettings,
                                  connectSourceToTarget=connectSourceToTarget)
        if debug:
            guiFactory.doPrintReportEnd(functionName)
コード例 #25
0
    def doKeyable(self, arg=True):
        """ 
        Set keyable state of an attribute
        
        Keyword arguments:
        arg(bool)
        """
        assert type(arg) is bool, "doLocked arg must be a bool!"
        if arg:
            if self.children:
                guiFactory.warning(
                    "'%s' has children, running set command on '%s'" %
                    (self.nameCombined, "','".join(self.children)))
                for c in self.children:
                    cInstance = AttrFactory(self.obj.nameShort, c)
                    if not cInstance.keyable:
                        mc.setAttr(cInstance.nameCombined,
                                   e=True,
                                   keyable=True)
                        guiFactory.report(
                            "'%s.%s' keyable!" %
                            (cInstance.obj.nameShort, cInstance.attr))
                        cInstance.keyable = True
                        cInstance.hidden = False

            elif not self.keyable:
                mc.setAttr((self.obj.nameShort + '.' + self.attr),
                           e=True,
                           keyable=True)
                guiFactory.report("'%s.%s' keyable!" %
                                  (self.obj.nameShort, self.attr))
                self.keyable = True
                self.hidden = False

        else:
            if self.children:
                guiFactory.warning(
                    "'%s' has children, running set command on '%s'" %
                    (self.nameCombined, "','".join(self.children)))
                for c in self.children:
                    cInstance = AttrFactory(self.obj.nameShort, c)
                    if cInstance.keyable:
                        mc.setAttr(
                            (cInstance.obj.nameShort + '.' + cInstance.attr),
                            e=True,
                            keyable=False)
                        guiFactory.report(
                            "'%s.%s' unkeyable!" %
                            (cInstance.obj.nameShort, cInstance.attr))
                        cInstance.keyable = False
                        if not mc.getAttr(cInstance.nameCombined,
                                          channelBox=True):
                            cInstance.updateData()
                            cInstance.doHidden(False)

            elif self.keyable:
                mc.setAttr((self.obj.nameShort + '.' + self.attr),
                           e=True,
                           keyable=False)
                guiFactory.report("'%s.%s' unkeyable!" %
                                  (self.obj.nameShort, self.attr))
                self.keyable = False
                if not mc.getAttr(self.nameCombined, channelBox=True):
                    self.updateData()
                    self.doHidden(False)
コード例 #26
0
ファイル: AttrFactory.py プロジェクト: GuidoPollini/MuTools
    def doCopyTo(self,target, targetAttrName = None,  debug = True,*a,**kw):
        """                                     
        Replacement for Maya's since maya's can't handle shapes....blrgh...
        Copy attributes from one object to another as well as other options. If the attribute already
        exists, it'll copy the values. If it doesn't, it'll make it. If it needs to convert, it can.
        It will not make toast.
    
        Keywords:
        toObject(string) - obj to copy to
        targetAttrName(string) -- name of the attr to copy to . Default is None which will create an 
                          attribute oft the fromAttr name on the toObject if it doesn't exist
        convertToMatch(bool) -- whether to convert if necessary.default True        
        values(bool) -- copy values. default True
        incomingConnections(bool) -- default False
        outGoingConnections(bool) -- default False
        keepSourceConnections(bool)-- keeps connections on source. default True
        copyAttrSettings(bool) -- copy the attribute state of the fromAttr (keyable,lock,hidden). default True
        connectSourceToTarget(bool) useful for moving attribute controls to another object. default False
        
        RETURNS:
        success(bool)
        """
        assert mc.objExists(target),"'%s' doesn't exist"%target
        assert mc.ls(target,long=True) != [self.obj.nameShort], "Can't transfer to self!"
        functionName = 'doCopyTo'
        
        convertToMatch = kw.pop('convertToMatch',True)
        values = kw.pop('values',True)
        incomingConnections = kw.pop('incomingConnections',False)
        outgoingConnections = kw.pop('outgoingConnections',False)
        keepSourceConnections = kw.pop('keepSourceConnections',True)
        copyAttrSettings = kw.pop('copyAttrSettings',True)
        connectSourceToTarget = kw.pop('connectSourceToTarget',False)
        connectTargetToSource = kw.pop('connectTargetToSource',False)  
        
        if debug:
            guiFactory.doPrintReportStart(functionName)
            guiFactory.report("AttrFactory instance: '%s'"%self.nameCombined)
            guiFactory.report("convertToMatch: '%s'"%convertToMatch)
            guiFactory.report("targetAttrName: '%s'"%targetAttrName)
            guiFactory.report("incomingConnections: '%s'"%incomingConnections)
            guiFactory.report("outgoingConnections: '%s'"%outgoingConnections)
            guiFactory.report("keepSourceConnections: '%s'"%keepSourceConnections)
            guiFactory.report("copyAttrSettings: '%s'"%copyAttrSettings)
            guiFactory.report("connectSourceToTarget: '%s'"%connectSourceToTarget)
            guiFactory.report("keepSourceConnections: '%s'"%keepSourceConnections)
            guiFactory.report("connectTargetToSource: '%s'"%connectTargetToSource)
            guiFactory.doPrintReportBreak()
            

                
        copyTest = [values,incomingConnections,outgoingConnections,keepSourceConnections,connectSourceToTarget,copyAttrSettings]
        
        if sum(copyTest) < 1:
            guiFactory.warning("You must have at least one option for copying selected. Otherwise, you're looking for the 'doDuplicate' function.")            
            return False

        if '.' in list(target):
            targetBuffer = target.split('.')
            if len(targetBuffer) == 2:
                attributes.doCopyAttr(self.obj.nameShort,
                                      self.nameLong,
                                      targetBuffer[0],
                                      targetBuffer[1],
                                      convertToMatch = convertToMatch,
                                      values=values, incomingConnections = incomingConnections,
                                      outgoingConnections=outgoingConnections, keepSourceConnections = keepSourceConnections,
                                      copyAttrSettings = copyAttrSettings, connectSourceToTarget = connectSourceToTarget)               

            else:
                guiFactory.warning("Yeah, not sure what to do with this. Need an attribute call with only one '.'")
        else:
            attributes.doCopyAttr(self.obj.nameShort,
                                  self.nameLong,
                                  target,
                                  targetAttrName,
                                  convertToMatch = convertToMatch,
                                  values=values, incomingConnections = incomingConnections,
                                  outgoingConnections=outgoingConnections, keepSourceConnections = keepSourceConnections,
                                  copyAttrSettings = copyAttrSettings, connectSourceToTarget = connectSourceToTarget)                                                 
        if debug:
            guiFactory.doPrintReportEnd(functionName)        
コード例 #27
0
def findMeshIntersection(mesh, raySource, rayDir, maxDistance=1000):
    """
    Thanks to Deane @ https://groups.google.com/forum/?fromgroups#!topic/python_inside_maya/n6aJq27fg0o%5B1-25%5D
    
    Return the closest point on a surface from a raySource and rayDir
    
    Arguments
    mesh(string) -- currently poly surface only
    raySource(double3) -- point in world space
    rayDir(double3) -- world space vector
    
    returns hitpoint(double3)
    """
    #Create an empty selection list.
    selectionList = om.MSelectionList()

    #Put the mesh's name on the selection list.
    selectionList.add(mesh)

    #Create an empty MDagPath object.
    meshPath = om.MDagPath()

    #Get the first item on the selection list (which will be our mesh)
    #as an MDagPath.
    selectionList.getDagPath(0, meshPath)

    #Create an MFnMesh functionset to operate on the node pointed to by
    #the dag path.
    meshFn = om.MFnMesh(meshPath)

    #Convert the 'raySource' parameter into an MFloatPoint.
    raySource = om.MFloatPoint(raySource[0], raySource[1], raySource[2])

    #Convert the 'rayDir' parameter into an MVector.`
    rayDirection = om.MFloatVector(rayDir[0], rayDir[1], rayDir[2])

    #Create an empty MFloatPoint to receive the hit point from the call.
    hitPoint = om.MFloatPoint()

    #Set up a variable for each remaining parameter in the
    #MFnMesh::closestIntersection call. We could have supplied these as
    #literal values in the call, but this makes the example more readable.
    sortIds = False
    maxDist = om.MDistance.internalToUI(1000000)  # This needs work
    #maxDist = om.MDistance.internalToUI(maxDistance) # This needs work
    bothDirections = False
    noFaceIds = None
    noTriangleIds = None
    noAccelerator = None
    noHitParam = None
    noHitFace = None
    noHitTriangle = None
    noHitBary1 = None
    noHitBary2 = None

    #Get the closest intersection.
    gotHit = meshFn.closestIntersection(raySource, rayDirection, noFaceIds,
                                        noTriangleIds, sortIds,
                                        om.MSpace.kWorld, maxDist,
                                        bothDirections, noAccelerator,
                                        hitPoint, noHitParam, noHitFace,
                                        noHitTriangle, noHitBary1, noHitBary2)

    #Return the intersection as a Pthon list.
    if gotHit:
        #Thank you Mattias Bergbom, http://bergbom.blogspot.com/2009/01/float2-and-float3-in-maya-python-api.html
        hitMPoint = om.MPoint(hitPoint)  # Thank you Capper on Tech-artists.org
        pArray = [0.0, 0.0]
        x1 = om.MScriptUtil()
        x1.createFromList(pArray, 2)
        uvPoint = x1.asFloat2Ptr()
        uvSet = None
        closestPolygon = None
        uvReturn = meshFn.getUVAtPoint(hitMPoint, uvPoint, om.MSpace.kWorld)

        uValue = om.MScriptUtil.getFloat2ArrayItem(uvPoint, 0, 0) or False
        vValue = om.MScriptUtil.getFloat2ArrayItem(uvPoint, 0, 1) or False
        if debugReport:
            guiFactory.report("Hit! [%s,%s,%s]" %
                              (hitPoint.x, hitPoint.y, hitPoint.z))
        if uValue and vValue:
            return {
                'hit': [hitPoint.x, hitPoint.y, hitPoint.z],
                'source': [raySource.x, raySource.y, raySource.z],
                'uv': [uValue, vValue]
            }
        else:
            return {
                'hit': [hitPoint.x, hitPoint.y, hitPoint.z],
                'source': [raySource.x, raySource.y, raySource.z],
                'uv': False
            }
    else:
        return None
コード例 #28
0
ファイル: project_02012.py プロジェクト: GuidoPollini/MuTools
def placerLocsToCubey():
    import random
    from cgm.lib import position
    selection = mc.ls(sl=True) or []
    mStable = ['J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male1.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male2.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male3.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male4.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male5.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/male6.ma']
    fStable = ['J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/female1.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/female2.ma',
               'J:/Dropbox/MasterCard/Sequences/mc/mc0010/Anim/maya/scenes/cycles/female3.ma']
    
    maleFileCnt = 0
    femaleFileCnt = 0
    maleCnt = 0
    femCnt = 0
    
    length = len(selection)
    for i,loc in enumerate(selection):
	guiFactory.report("On %s of %s"%(i,length))
	
	#Pick a sex
	sexInt = random.randint(0,10)
	sex = 'male'
	if sexInt in [2,3]:
	    sex = 'female'
	    
	guiFactory.report("sex is '%s'"%sex)
	
	#Pick a file
	if sex is 'male':
	    locFile = mStable[maleFileCnt]
	    maleFileCnt +=1
	    maleCnt +=1
	    if not maleFileCnt < len(mStable):
		maleFileCnt = 0
	    locNameSpace = 'male_%s'%maleCnt
	else:
	    locFile = fStable[femaleFileCnt]
	    femaleFileCnt +=1
	    femCnt +=1
	    if not femaleFileCnt < len(fStable):
		femaleFileCnt = 0
	    locNameSpace = 'female_%s'%femCnt
		
	guiFactory.report("File is '%s'"%locFile)
	
	#Import the file
	mc.file(locFile, i = True,namespace = locNameSpace,pr = True, force = True,prompt = False) # prompt means no error message
	buffer =  mc.ls('%s:*'%locNameSpace) 
	
	if not 'RN' in buffer[0]:
	    return guiFactory.warning('Failed to find name space')
	
	splitBuffer = buffer[0].split('RN')
	realLocNameSpace = splitBuffer[0]
	
	#Snap Master constraint group and constrain to loc
	nestedNameSpace = 'male'
	if sex == 'female':
	    nestedNameSpace = 'female'
	    
	snappingObject = ('%s:%s:Cubey_masterAnim_constraint_grp'%(locNameSpace,nestedNameSpace))
	if not mc.objExists(snappingObject):
	    return "Snapping object doesn't exist = '%s'"%snappingObject
	position.moveParentSnap(snappingObject,loc)
	
	masterObject = ('%s:%s:Cubey_masterAnim'%(locNameSpace,nestedNameSpace))
	if not mc.objExists(masterObject):
	    return "Master object doesn't exist = '%s'"%masterObject
	
	mc.parentConstraint(loc,snappingObject, maintainOffset=False)
	if sex == 'male':
	    attributes.doSetAttr(masterObject,'tz',.606)
	attributes.doSetAttr(masterObject,'rz',-90)
	
	#Randomize
	if sex == 'male':
	    randomizeCubey('%s:%s'%(locNameSpace,nestedNameSpace))
	if sex == 'female':
	    randomizeCubette('%s:%s'%(locNameSpace,nestedNameSpace))