Example #1
0
def build(itemType, task, code):
    parcial = False
    empty = True

    item = Item(task=task, code=code, itemType=itemType)

    if not item.source:
        itemList = item.components
    else:
        itemList = item.source

    pm.newFile(f=True, new=True)
    newComponentsDict = {}

    if item.type == 'shot':
        print 'creating camera...'
        cameraItem = Item(task='rig', code='0000', itemType='asset')
        print cameraItem.noData
        if cameraItem.noData:
            pm.confirmDialog(title='No base camera', ma='center',
                             message='Please make an asset code:0000 as base camera',
                             button=['OK'], defaultButton='OK', dismissString='OK')
            return

        cameraMData = {'code': '0000', 'ver': cameraItem.publishVer, 'updateMode': 'last',
                      'task': 'rig', 'assembleMode': 'camera','proxyMode':'rig', 'type': 'asset'}
        camera = CameraComponent('cam', cameraMData, parent=item)



        camera.wrapData()
        if not camera.cameraTransform:
            camera.addToScene()
        newComponentsDict['cam'] = camera.getDataDict()


    for ns, sourceMData in itemList.iteritems():
        source = SceneSource(ns, sourceMData, parent=item)
        sourceItem = source.getItem()

        if sourceItem.publishVer == 0:
            print 'Component %s not yet published!!' % (ns + ':' + source.task + source.code)
            parcial = True
            continue

        empty = False

        if source.assembleMode == 'import':
            source.importToScene()

        elif source.assembleMode == 'reference':
            newComponentsDict[ns] = source.addReferenceToScene()

        elif source.assembleMode == 'copy':
            newComponentsDict = source.copyToScene()

        elif source.assembleMode == 'cache':
            newComponentsDict = source.addCacheToScene()

        elif source.assembleMode == 'xlo':
            newComponentsDict = source.addXloToScene()

    item.components = newComponentsDict

    # update infos on scene and database
    if not empty or not item.components:
        pm.fileInfo['projectName'] = database.getCurrentProject()
        pm.fileInfo['task'] = item.task
        pm.fileInfo['code'] = item.code
        pm.fileInfo['type'] = item.type

        if item.type == 'shot':
            pm.playbackOptions(ast=item.frameRange[0], aet=item.frameRange[1])
            pm.currentUnit(time='film')

        item.workVer = 1
        item.status = 'created'

        item.putDataToDB()
        sceneDirPath = item.getPath()[0]
        sceneFullPath = item.getWorkPath()

        if not os.path.exists(sceneDirPath):
            os.makedirs(sceneDirPath)

        pm.saveAs(sceneFullPath)

        if parcial:
            item.status = 'partial'
            pm.confirmDialog(title='Warning', ma='center',
                             message='WARNING build: Some components have no publish to complete build this file!',
                             button=['OK'], defaultButton='OK', dismissString='OK')
            item.putDataToDB()
        else:
            pm.confirmDialog(title='Warning', ma='center',
                             message='%s assembled sucessfully!' % item.filename,
                             button=['OK'], defaultButton='OK', dismissString='OK')

    else:
        pm.confirmDialog(title='Warning', ma='center',
                         message='ERROR build: No component published to build this file',
                         button=['OK'], defaultButton='OK', dismissString='OK')
Example #2
0
def build(itemType=None, task=None, code=None, silent=False):
    logger.debug('initiate Scene Building %s %s %s' % (task, code, itemType))
    parcial = False
    empty = True


    item = Item(task=task, code=code, itemType=itemType)

    if not item.source:
        logger.debug('No source found. Using components')
        logger.debug('components %s' % item.components)
        itemUnOrdered = item.components
    else:
        logger.debug('Using source')
        itemUnOrdered = item.source

    pm.newFile(f=True, new=True)
    newComponentsDict = {}

    itemDict = OrderedDict()
    parentList = ['']
    count = 0

    while len(itemUnOrdered) != len(itemDict):
        count += 1
        level = [[key, x['code']] for key, x in itemUnOrdered.iteritems() if x['onSceneParent'] in parentList]

        parentList = [x[1] for x in level]
        for x in level:
            itemDict[x[0]] = itemUnOrdered[x[0]]
        if count > 100:
            break

    logger.debug(itemDict)

    if item.type == 'shot':
        logger.debug('creating camera...')
        cameraItem = Item(task='rig', code='0000', itemType='asset')
        if cameraItem.noData:
            pm.confirmDialog(title='No base camera', ma='center',
                             message='Please make an asset code:0000 as base camera',
                             button=['OK'], defaultButton='OK', dismissString='OK')
            return

        cameraMData = {'code': '0000', 'ver': cameraItem.publishVer, 'updateMode': 'last',
                      'task': 'rig', 'assembleMode': 'camera', 'proxyMode': 'rig',
                       'onSceneParent': None, 'type': 'asset', 'xform': {}}
        camera = CameraComponent('cam', cameraMData, parent=item)

        camera.wrapData()
        if not camera.cameraTransform:
            camera.addToScene()
        newComponentsDict['cam'] = camera.getDataDict()
        empty = False

    for ns, sourceMData in itemDict.iteritems():
        source = SceneSource(ns, sourceMData, parent=item)
        if source.assembleMode == 'createGroup':
            source.createGroup()
        empty = False

    for ns, sourceMData in itemDict.iteritems():
        source = SceneSource(ns, sourceMData, parent=item)
        sourceItem = source.getItem()

        if sourceItem.publishVer == 0:
            logger.warn('Component %s not yet published!!' % (ns + ':' + source.task + source.code))
            parcial = True
            newComponentsDict[ns] = sourceMData
            continue

        empty = False

        if source.assembleMode == 'import':
            source.importToScene()

        elif source.assembleMode == 'reference':
            newComponentsDict[ns] = source.addReferenceToScene()

        elif source.assembleMode == 'copy':
            newComponentsDict = source.copyToScene()

        elif source.assembleMode == 'cache':
            newComponentsDict = source.addCacheToScene()

        elif source.assembleMode == 'xlo':
            newComponentsDict = source.addXloToScene()

    item.components = newComponentsDict

    # update infos on scene and database
    if not empty or not item.components:
        pm.fileInfo['projectName'] = database.getCurrentProject()
        pm.fileInfo['task'] = item.task
        pm.fileInfo['code'] = item.code
        pm.fileInfo['type'] = item.type

        if item.type == 'shot':
            pm.playbackOptions(ast=item.frameRange[0], aet=item.frameRange[1])
            pm.currentUnit(time='film')

        item.workVer = 1
        item.status = 'created'

        item.putDataToDB()

        sceneDirPath = item.getPath()[0]
        sceneFullPath = item.getWorkPath()

        if not os.path.exists(sceneDirPath):
            os.makedirs(sceneDirPath)

        pm.saveAs(sceneFullPath)

        if parcial:  # todo make parcial rebuild
            item.status = 'partial'
            if not silent:
                pm.confirmDialog(title='Warning', ma='center',
                                 message='WARNING build: Some components have no publish to complete build this file!',
                                 button=['OK'], defaultButton='OK', dismissString='OK')
            else:
                logger.warn ('Some components have no publish to complete build this file!'
                             '')
            item.putDataToDB()
        else:
            if not silent:
                pm.confirmDialog(title='Warning', ma='center',
                                 message='%s assembled sucessfully!' % item.filename,
                                 button=['OK'], defaultButton='OK', dismissString='OK')
            else:
                logger.info('%s assembled sucessfully!' % item.filename)
    else:
        if not silent:
            pm.confirmDialog(title='Warning', ma='center',
                             message='ERROR build: No component published to build this file',
                             button=['OK'], defaultButton='OK', dismissString='OK')
        else:
            logger.error('No component published to build this file')