Exemplo n.º 1
0
def parent(parent=True):
    if parent:
        # make member of second selection
        cmds.character(cmds.ls(sl=True)[0], include=cmds.ls(sl=True)[1])
    else:
        # remove membership from second selection
        cmds.character(cmds.ls(sl=True)[0], rm=cmds.ls(sl=True)[1])
def channelbox_command_break(box, menuItem, key, *args):
    with sysCmd.Undo():
        for plug in channelBox_SelectedPlugs(box):
            if cmds.connectionInfo(plug, isDestination=1):
                destination = cmds.connectionInfo(plug, getExactDestination=1)

                # when delete source conn from character, must remove from character set or set becomes inconsistent
                src_conn = cmds.listConnections(destination, s=1, d=0, type="character")
                if src_conn:
                    warn_msg = "Removed \'^1s\' from character \'^2s\'."
                    cmds.warning(cmds.format(warn_msg, s=(destination, src_conn[0])))
                    cmds.character(destination, e=1, rm=src_conn[0])

                # is tracking edits?
                import maya.api.OpenMaya as om
                obj = om.MSelectionList().add(destination).getDependNode(0)
                depend_fn = om.MFnDependencyNode(obj)
                tracking_edits = depend_fn.isTrackingEdits()
                del obj
                del depend_fn

                if tracking_edits:
                    src = cmds.connectionInfo(destination, sourceFromDestination=1)
                    cmds.disconnectAttr(src, destination)
                else:
                    cmds.delete(destination, icn=1)
Exemplo n.º 3
0
def matchCharSet(source=None, objs=[]):
    '''
    source = get character set if connected
    objs = make members of list in same set as source
    '''
    char = cmds.listConnections(source, t='character', s=False, d=True)
    if char:
        char = list(set(char))
        if len(char) == 1:
            for obj in objs:
                cmds.character(obj, include=char[0])
        else:
            message('Object not added to Charecter set. More than one option found.')
Exemplo n.º 4
0
def importFile(path='', prefix='', ns='', cs=['old', 'new'], rp={None: None}):
    '''
    prefix = adds prefix string with underscore after
    ns     = namespace string to replace
    cs     = character set string to replace, is obsolete with "rp" attribute
    rplc   = per line in file replace string, could change to dictionary for clarity
    '''
    # nsCurrent = cmds.namespaceInfo(currentNamespace=True)
    # cmds.namespace(set=':')
    if os.path.isfile(path):
        if prefix != '':
            prefix = prefix + '_'
        addNode = ''
        for line in open(path).readlines():
            if rp.keys() != [None]:
                line = replaceInString(line, rp)
            # character and sub-character set line
            if 'ParentInfo=' in line:
                # print line, '--'
                line = line.split('=')[1].strip('\n').partition('|')
                # line = updateCS(string=line, old=cs[0], new=cs[1])
                if line[0] == 'none':
                    # top character
                    charName = prefix + line[2]
                    charName = cmds.character(name=charName, em=True)
                    print charName,
                    addNode = charName
                else:
                    # sub-character set
                    charName = prefix + line[2]
                    charTmp = cmds.character(name=charName, em=True)
                    # automatic rename of duplicate, splitting extra string
                    dup = charTmp.split(charName)[1]
                    charName = charTmp
                    cmds.character(charName, fe=prefix + line[0] + dup)
                    addNode = charName
            # character set members line
            else:
                # does not account for multiple refs in one set, like character and prop
                if ':' in line:
                    line = updateNS(str(line), str(ns))
                    if cmds.objExists(line) is False:
                        sel = cmds.ls(sl=True)
                        if len(sel) > 0:
                            sel = sel[0]
                            sel = nameSpace(sel, base=True)
                            line = updateNS(line, sel[0] + ':' + sel[1])
                        else:
                            message('Object ' + line + ' was not found. Select an object in desired namespace and try again.')
                try:
                    cmds.character(line.strip('\n'), fe=addNode)
                except:
                    loadWarning = 'no attribute found, %s, skipping...' % (line.strip('\n'))
                    mel.eval("warning\"" + loadWarning + "\";")
                else:
                    cmds.character(line.strip('\n'), fe=addNode)
        # cmds.namespace(set=nsCurrent)
    else:
        message('Path not found: ' + path)
Exemplo n.º 5
0
 def checkDeleteConnection(self , attr ):
     # 被输入方
     if mc.connectionInfo(attr , isDestination = 1):
         destination = mc.connectionInfo(attr , getExactDestination = 1)
         srcConn = mc.listConnections(destination, s = 1, d = 0 , type = 'character')
         if srcConn:
             # 断开
             mc.character(destination , e = 1 ,rm = srcConn[0])
         
         sArr = mc.ls(destination , ro = 1)
         if sArr:
             src = mc.connectionInfo(destination , sourceFromDestination = 1)
             if src:
                 mc.disconnectAttr(src , destination)
         else:
             mc.delete(destination , icn = 1)
Exemplo n.º 6
0
def printTimelineClips(charSet):
    '''
	'''
    scheduler = mc.character(charSet, q=True, scheduler=True)
    scheduleList = mc.clipSchedule(clip, q=True)
    for schedule in scheduleList:
        print schedule
Exemplo n.º 7
0
def writeFile(char, parent, outFile=''):
    # Arguments   :<char>   : attribute of a character set
    #            :<parent> : character nodes parent
    #            :<outFile>: filepath of the output file
    # Description :Recursive function that seperates characters nodes children and
    #             attributes and writes them to the specified file.
    #
    # list all attributes of the character)
    characterMembers = cmds.character(char, query=True)
    if characterMembers is not None:
        # write out the parent line
        outFile.write('ParentInfo=' + parent + '|' + char + '\n')
        parent = char
        charList = []
        # check members list for attrs or sub-characters
        for cMember in characterMembers:
            # if attr
            if cmds.nodeType(cMember) != 'character':
                outFile.write(cMember + '\n')
            # must be sub-character set, add to list
            else:
                charList.append(cMember)
        for char in charList:
            writeFile(char, parent, outFile)
    else:
        # empty character set, write info
        outFile.write('ParentInfo=' + parent + '|' + char + '\n')
Exemplo n.º 8
0
 def _buildCharacterSet(self):
     setMembers = [
         "%s.%s" % (mayaJoint.name, attr)
         for mayaJoint in self.mayaJoints.values()
         for attr in kAnimatableAttrs
     ]
     self.characterSet = mc.character(setMembers,
                                      name=("%sCharacter" % self.name()))
Exemplo n.º 9
0
class analyticCharacter(BaseAnalytic):
    """
    Analyze the DG connectivity.
    """
    def run(self):
        """
        Examine the characters in the scene for a few basic structure
        elements. The CSV file headings are generic so as to maximize the
        ability to process the data - 'Character','Type','Value'.

        When the 'details' option is set then the data looks like this:
            - Character Name, 'Member', Character Member Plug name
            - Character Name, 'Map', Character to which it is mapped

        otherwise it looks like this
            - Character Name, 'Member', Number of members in the character
            - Character Name, 'Map', Character to which it is mapped
        """
        self._output_csv(['Character', 'Type', 'Value'])

        characterList = cmds.ls(type='character')
        try:
            if len(characterList) == 0:
                self.warning('No characters to report')
                return
        except Exception, ex:
            # If the 'character' command returns None this is the easiest
            # way to trap that case.
            self.warning('Character report failed ({0:s}'.format(str(ex)))
            return

        for character in characterList:
            characterName = self._node_name(character)
            memberList = cmds.character(character, query=True)
            if memberList == None:
                memberList = []
            if self.option(OPTION_DETAILS):
                for member in memberList:
                    self._output_csv([character, 'Member', member])
            else:
                self._output_csv(
                    [characterName, 'Member',
                     str(len(memberList))])

            # This O(N^2) check for character maps is easier than looking
            # through connections. It's only necessary because the
            # 'characterMap' command can only be queried with both
            # characters as arguments.
            for character2 in characterList:
                # Not sure why Maya thinks a character maps onto itself.
                if character2 == character:
                    continue
                if cmds.characterMap([character, character2],
                                     query=True) != None:
                    character2Name = self._node_name(character2)
                    self._output_csv([characterName, 'Map', character2Name])
Exemplo n.º 10
0
def removeTimelineClips(charSet):
    """
    Remove all clip from the trax timeline for the specified character.
    @param charSet: Character set to bake channels for.
    @type charSet: str
    """
    scheduler = cmds.character(charSet, q=True, scheduler=True)
    scheduleList = cmds.clipSchedule(scheduler, q=True)
    for schedule in scheduleList:
        clipInd = str(schedule).split(',')[1]
        cmds.clipSchedule(scheduler, ci=int(clipInd), remove=True)
Exemplo n.º 11
0
def removeTimelineClips(charSet):
    '''
	Remove all clip from the trax timeline for the specified character.
	@param charSet: Character set to bake channels for.
	@type charSet: str
	'''
    scheduler = mc.character(charSet, q=True, scheduler=True)
    scheduleList = mc.clipSchedule(scheduler, q=True)
    for schedule in scheduleList:
        clipInd = str(schedule).split(',')[1]
        mc.clipSchedule(scheduler, ci=int(clipInd), remove=True)
Exemplo n.º 12
0
def make_Clip_from_MotionCaptureData():
    _clipName = mel.eval( 'basenameEx(`file -q -sn`)')
    _Char = 'Clip'

    # make Character
    _bodyJoints = [
        'HipsTranslation','Hips','Spine','Spine1','Spine2','Spine3','Neck','Head',
        'LeftShoulder','LeftArm','LeftArmRoll','LeftForeArm','LeftForeArmRoll','LeftHand',
        'LeftUpLeg','LeftUpLegRoll','LeftLeg','LeftLegRoll','LeftFoot','LeftToeBase',
        'RightShoulder','RightArm','RightArmRoll','RightForeArm','RightForeArmRoll','RightHand',    
        'RightUpLeg','RightUpLegRoll','RightLeg','RightLegRoll','RightFoot','RightToeBase'
        ]
    _attrList = ['tx','ty','tz','rx','ry','rz']
    cmds.character(name=_Char)

    # tr, rt 속성 추가
    for _jnt in _bodyJoints:
        for _attr in _attrList:
            cmds.character(_jnt+'.'+_attr ,forceElement=_Char)

    _attrList = ['tx','ty','tz']
    # tr속성 제거
    for _jnt in _bodyJoints:
        if _jnt == 'HipsTranslation' or _jnt == 'Hips': continue
        for _attr in _attrList:
            cmds.character( _jnt+'.'+_attr , remove=_Char )

    # 애니메이션 클립 생성
    cmds.clip(_Char, name=_clipName, scheduleClip=True, allAbsolute=True, animCurveRange=True)
Exemplo n.º 13
0
 def populateMembers(self):
     stp = '  '
     self.message('')
     cmds.textScrollList(self.membersForm.scroll, edit=True, ra=True)
     charSet = cmds.textScrollList(self.setsForm.scroll, query=True, si=True)
     members = cmds.character(charSet, query=True)
     if members:
         members.sort()
         for member in members:
             if cmds.nodeType(member) != 'character':
                 cmds.textScrollList(self.membersForm.scroll, edit=True, append=member)
             else:
                 cmds.textScrollList(self.membersForm.scroll, edit=True, append=stp + member)
     else:
         cmds.textScrollList(self.membersForm.scroll, edit=True, append='None')
def CreateAnimationAttrFromTrax():
    characcterSet = cmds.textScrollList(characterSetsList, q=True, si=True)
    characterScheduler = cmds.character(characcterSet, q=True, scheduler=True)
    # Return Hero_Dummy:HeroControlRigScheduler1

    # traxList = cmds.clipSchedule( characterScheduler, q=True ) - this is one way to do it.
    # Return [u'Hero_Combo01,0,20.000000,1.000000,30.000000,1.000000,0.000000,0.000000,0.000000\n', u'Hero_Combo02,1,50.000000,1.000000,30.000000,1.000000,0.000000,0.000000,0.000000\n']
    traxList = cmds.clipSchedule(characterScheduler, q=True, n=True)
    # Return Hero_Combo01 Hero_Combo02 Hero_Combo03 Hero_Heavy01 Hero_DodgeLeft Hero_DodgeRight Hero_StrafeLeft Hero_StrafeRight Hero_IdleReady01 Hero_IdleInjured01 Hero_TPose //

    # Flush all Anim attributes first
    CheckAndDeleteAnimClips(selList)

    for i in range(len(traxList)):
        print (traxList[i])

        clipName = traxList[i] + "_anim"
        clipStart = cmds.clipSchedule(characterScheduler, ci=i, q=True, s=True)
        print (clipStart)

        clipEnd = GetClipEnd(characterScheduler, i, clipStart)
        print (clipEnd)

        AddClipAttr(selList, clipName, clipStart, clipEnd)
Exemplo n.º 15
0
def create(objectList,
           name,
           root='',
           excludeTranslate=False,
           excludeRotate=False,
           excludeScale=False,
           excludeDynamic=False,
           excludeVisibility=False):
    '''
	Create a character set.
	@param objectList: List of objects to add to the character set.
	@type objectList: list
	@param name: Character set name.
	@type name: str
	@param root: Character set root object.
	@type root: str
	@param excludeTranslate: Character set to exclude translate channels.
	@type excludeTranslate: bool
	@param excludeRotate: Character set to exclude rotate channels.
	@type excludeRotate: bool
	@param excludeScale: Character set to exclude scale channels.
	@type excludeScale: bool
	@param excludeDynamic: Character set to exclude dynamic channels.
	@type excludeDynamic: bool
	@param excludeVisibility: Character set to exclude visibility channels.
	@type excludeVisibility: bool
	'''
    # ==========
    # - Checks -
    # ==========

    # Check Character Set
    if isCharSet(name):
        raise Exception('Character set "' + name + '" already exists!')

    # Check Root
    if root and not mc.objExists(root):
        raise Exception('Root object "' + root + '" does not exists!')

    # ========================
    # - Create Character Set -
    # ========================

    # Initialize Character Var
    char = ''

    if root:
        # Create With Root Node
        char = mc.character(objectList,
                            n=name,
                            root=root,
                            excludeTranslate=excludeTranslate,
                            excludeRotate=excludeRotate,
                            excludeScale=excludeScale,
                            excludeDynamic=excludeDynamic,
                            excludeVisibility=excludeVisibility)
    else:
        # Create Without Root Node
        char = mc.character(objectList,
                            n=name,
                            excludeTranslate=excludeTranslate,
                            excludeRotate=excludeRotate,
                            excludeScale=excludeScale,
                            excludeDynamic=excludeDynamic,
                            excludeVisibility=excludeVisibility)

    # =================
    # - Return Result -
    # =================

    return char
Exemplo n.º 16
0
	def _buildCharacterSet(self):
		setMembers = [ "%s.%s" % (mayaJoint.name, attr) for mayaJoint in self.mayaJoints.values() for attr in kAnimatableAttrs ]
		self.characterSet = mc.character(setMembers, name=("%sCharacter" % self.name()))
Exemplo n.º 17
0
def toggleMembershipToCurrentSet(sel=[], attrs=[], shapeAttrs=[]):
    current = GetSetOptions()
    # current.currentSet()  # add if current == None, return message and bail
    if not sel:
        sel = cmds.ls(sl=True)
        # collect object attrs
    if not attrs:
        attrs = cmds.channelBox('mainChannelBox', q=True, sma=True)
    # obj = cmds.channelBox('mainChannelBox', q=True, mol=True)[0]
    # collect shape attrs
    if not shapeAttrs:
        shapeAttrs = cmds.channelBox('mainChannelBox', q=True, ssa=True)
    # print sel
    output = None
    # change this to ask for selected channelBox attrs fist, if None, work with entire object
    if len(sel) == 1:
        sel = sel[0]
        try:
            shape = cmds.channelBox('mainChannelBox', q=True, sol=True)[0]
        except:
            pass
        # object attr toggle
        if attrs:
            # print '__1'
            for attr in attrs:
                if cmds.attributeQuery(attr, node=sel, ex=True):
                    if cmds.character(sel + '.' + attr, im=currentSet()) is False:
                        # print attr, sel
                        cmds.character(sel + '.' + attr, fe=currentSet())  # BUG: sometimes throws error, only one set was in scene, no sub chars
                        # print attr, '  added'
                    else:
                        output = cmds.character(sel + '.' + attr, rm=currentSet())
                        # print attr, '  removed'
                else:
                    pass
                    # print 'doesnt exist  ', sel + '.' + attr
        # shape attr toggle
        elif shapeAttrs:
            # print '__2'
            for attr in shapeAttrs:
                if cmds.character(shape + '.' + attr, im=currentSet()) is False:
                    cmds.character(shape + '.' + attr, fe=current.currentSet())
                    # print attr, '  added'
                else:
                    output = cmds.character(shape + '.' + attr, rm=currentSet())
                    # print attr, '  removed'
        else:
            # print 'there'
            members = cmds.character(currentSet(), q=True)
            membersObj = []
            if members:
                for member in members:
                    membersObj.append(member.split('.')[0])
            membersObj = list(set(membersObj))
            if sel not in membersObj:
                # print sel
                # print currentSet()
                try:
                    cmds.character(sel, fe=currentSet())
                except:
                    cmds.warning('--  ' + sel + '  -- Likely something wrong with the connected anim curve, Try deleting it. --')
            else:
                for member in members:
                    if sel in member:
                        cmds.character(member, rm=currentSet())
                    else:
                        pass
    else:
        for item in sel:
            toggleMembershipToCurrentSet(sel=[item], attrs=attrs, shapeAttrs=shapeAttrs)
Exemplo n.º 18
0
def printTimelineClips(charSet):
    """
    """
    scheduler = cmds.character(charSet, q=True, scheduler=True)
    scheduleList = cmds.clipSchedule(clip, q=True)
    for schedule in scheduleList: print schedule
Exemplo n.º 19
0
def parentSet():
    # forces first selection to be a member of second selection
    cmds.character(cmds.ls(sl=True)[0], fe=cmds.ls(sl=True)[1])
Exemplo n.º 20
0
def character(*args, **kwargs):
    res = cmds.character(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Exemplo n.º 21
0
def create(objectList,
           name,
           root='',
           excludeTranslate=False,
           excludeRotate=False,
           excludeScale=False,
           excludeDynamic=False,
           excludeVisibility=False):
    """
    Create a character set.
    @param objectList: List of objects to add to the character set.
    @type objectList: list
    @param name: Character set name.
    @type name: str
    @param root: Character set root object.
    @type root: str
    @param excludeTranslate: Character set to exclude translate channels.
    @type excludeTranslate: bool
    @param excludeRotate: Character set to exclude rotate channels.
    @type excludeRotate: bool
    @param excludeScale: Character set to exclude scale channels.
    @type excludeScale: bool
    @param excludeDynamic: Character set to exclude dynamic channels.
    @type excludeDynamic: bool
    @param excludeVisibility: Character set to exclude visibility channels.
    @type excludeVisibility: bool
    """
    # ==========
    # - Checks -
    # ==========

    # Check Character Set
    if isCharSet(name):
        raise Exception('Character set "' + name + '" already exists!')

    # Check Root
    if root and not cmds.objExists(root):
        raise Exception('Root object "' + root + '" does not exists!')

    # ========================
    # - Create Character Set -
    # ========================

    # Initialize Character Var
    char = ''

    if root:
        # Create With Root Node
        char = cmds.character(objectList,
                            n=name,
                            root=root,
                            excludeTranslate=excludeTranslate,
                            excludeRotate=excludeRotate,
                            excludeScale=excludeScale,
                            excludeDynamic=excludeDynamic,
                            excludeVisibility=excludeVisibility)
    else:
        # Create Without Root Node
        char = cmds.character(objectList,
                            n=name,
                            excludeTranslate=excludeTranslate,
                            excludeRotate=excludeRotate,
                            excludeScale=excludeScale,
                            excludeDynamic=excludeDynamic,
                            excludeVisibility=excludeVisibility)

    # =================
    # - Return Result -
    # =================

    return char
Exemplo n.º 22
0
for char in Charlist:
    print char
    animlist=os.listdir(projpath+char+"\Animation\\")
    print animlist
    for eachanim in animlist:
        if "meta" not in eachanim:
            AllAnimList.append(eachanim)


for each in AllAnimList:
    # char=each.split('@')[0]
    anim=(each.split('@')[1]).strip(".fbx")
    mc.file(new=1,f=1)
    mc.file(projpath+char+'\Animation\\'+ each,i=1,ifr=1,itr='override')
    mc.select("Root",hi=1)
    mc.character(n=char)
    animclip=mc.clip( char, acr=1, n=anim )[0]
    mc.select(animclip)
    melcmd='clipEditorExportClip("C:/Users/Ji/Desktop/RogueRacers/AnimationClips/'+char+'@'+anim+ '","ma")'
    mel.eval(melcmd)
    # mc.file("C:\Users\Ji\Desktop\RogueRacers\\"+  char + ".ma" ,i=1,ifr=1,itr='override') 
    
            
            
 
    
    



# for eachfile in animlist: