예제 #1
0
def retargetRefs(refHandles, targetDir):
    refFilenamesToRetarget = set([os.path.basename(rh.getRefFilename()).lower() for rh in refHandles])
    duplicatesInTargetDir = set()
    targetsDb = {}
    for root, directories, files in os.walk(targetDir):
        for f in files:
            lowCaseFilename = f.lower()
            if lowCaseFilename not in refFilenamesToRetarget:
                continue

            fullPath = cleanupPath(os.path.join(root, f))
            if lowCaseFilename in targetsDb:
                duplicatesInTargetDir.add(f)
            else:
                targetsDb[lowCaseFilename] = fullPath

    notFoundInTargetDir = set()
    rhToRetarget = []
    for rh in refHandles:
        basename = os.path.basename(rh.getRefFilename())
        basenameLower = basename.lower()

        if basenameLower in notFoundInTargetDir:
            continue

        if basenameLower not in targetsDb:
            notFoundInTargetDir.add(basename)
            continue

        rhToRetarget.append((rh, getRelativePath(targetsDb[basenameLower])))

    saveSelection()

    activeRefHandles = [rh for rh, target in rhToRetarget if rh.active]

    # see activateRefs() for explanation why deactivate is not in activate() method
    for refHandle, target in rhToRetarget:
        refHandle.deactivate()

    for refHandle, target in rhToRetarget:
        refHandle.setRefFilename(target)

    for refHandle in activeRefHandles:
        refHandle.activate()

    maintenanceProcedure()
    restoreSelection()

    if duplicatesInTargetDir:
        log.logAppend('Duplicates found in target directory tree for following reference(s) (retargeted to first occurence):')
        log.logAppend(sorted(duplicatesInTargetDir))
    if notFoundInTargetDir:
        log.logAppend('')
        log.logAppend('Following reference(s) was not found in target directory tree (leaved intact):')
        log.logAppend(sorted(notFoundInTargetDir))
    log.logShow()
예제 #2
0
def makeRefsPathRelative():

    cleanupEmptyRefNodes()

    if not getRefRootValue():
        return

    for rh in getAllRefHandles():
        refFilename = rh.getRefFilename()
        relativeFilename = getRelativePath(refFilename)
        if not (refFilename.lower() == relativeFilename.lower()):
            rh.setRefFilename(relativeFilename)
예제 #3
0
def makeRefsPathRelative():

    cleanupEmptyRefNodes()

    if not getRefRootValue():
        return

    for rh in getAllRefHandles():
        refFilename = rh.getRefFilename()
        relativeFilename = getRelativePath(refFilename)
        if not (refFilename.lower() == relativeFilename.lower()):
            rh.setRefFilename(relativeFilename)
예제 #4
0
def browseForSource(fileMode):
    globalPrefsHandler.loadPrefs()
    lastBrowsed = globalPrefsHandler.getValue(globalPrefsHandler.KEY_LAST_BROWSED_SOURCE) or ''

    filename = m.fileDialog2(
        dialogStyle=1,
        caption='Choose Reference Scene',
        fileFilter='Maya Scenes (*.mb; *.ma);;Maya Binary (*.mb);;Maya ASCII (*.ma);;All Files (*.*)',
        fileMode=fileMode,
        returnFilter=False,
        startingDirectory=lastBrowsed
    )
    if not filename:
        return None

    filename = cleanupPath(filename[0])

    globalPrefsHandler.setValue(globalPrefsHandler.KEY_LAST_BROWSED_SOURCE, cleanupPath(os.path.dirname(filename)))
    globalPrefsHandler.savePrefs()

    return getRelativePath(filename)
예제 #5
0
def retargetRefs(refHandles, targetDir):
    refFilenamesToRetarget = set(
        [os.path.basename(rh.getRefFilename()).lower() for rh in refHandles])
    duplicatesInTargetDir = set()
    targetsDb = {}
    for root, directories, files in os.walk(targetDir):
        for f in files:
            lowCaseFilename = f.lower()
            if lowCaseFilename not in refFilenamesToRetarget:
                continue

            fullPath = cleanupPath(os.path.join(root, f))
            if lowCaseFilename in targetsDb:
                duplicatesInTargetDir.add(f)
            else:
                targetsDb[lowCaseFilename] = fullPath

    notFoundInTargetDir = set()
    rhToRetarget = []
    for rh in refHandles:
        basename = os.path.basename(rh.getRefFilename())
        basenameLower = basename.lower()

        if basenameLower in notFoundInTargetDir:
            continue

        if basenameLower not in targetsDb:
            notFoundInTargetDir.add(basename)
            continue

        rhToRetarget.append((rh, getRelativePath(targetsDb[basenameLower])))

    saveSelection()

    activeRefHandles = [rh for rh, target in rhToRetarget if rh.active]

    # see activateRefs() for explanation why deactivate is not in activate() method
    for refHandle, target in rhToRetarget:
        refHandle.deactivate()

    for refHandle, target in rhToRetarget:
        refHandle.setRefFilename(target)

    for refHandle in activeRefHandles:
        refHandle.activate()

    maintenanceProcedure()
    restoreSelection()

    if duplicatesInTargetDir:
        log.logAppend(
            'Duplicates found in target directory tree for following reference(s) (retargeted to first occurence):'
        )
        log.logAppend(sorted(duplicatesInTargetDir))
    if notFoundInTargetDir:
        log.logAppend('')
        log.logAppend(
            'Following reference(s) was not found in target directory tree (leaved intact):'
        )
        log.logAppend(sorted(notFoundInTargetDir))
    log.logShow()