ml_controlLibrary.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:ml_tools 作者: morganloomis 项目源码 文件源码
def promptExportControl(*args):
    '''Export selection, prompt for name, and create icon as well.
    '''

    sel = mc.ls(sl=True)

    assert sel, 'Select a control curve(s) to export.'

    for each in sel:
        if mc.nodeType(each) == 'nurbsCurve':
            continue
        shapes = mc.listRelatives(each, shapes=True, type='nurbsCurve')
        assert shapes, '{} is not a nurbsCurve'.format(each)

    result = mc.promptDialog(
        title='Export Control Curve',
        message='Enter Name:',
        button=['OK', 'Cancel'],
        defaultButton='OK',
        cancelButton='Cancel',
        dismissString='Cancel')

    if result != 'OK':
        return

    ctrlName = mc.promptDialog(query=True, text=True)
    ctrlName = ''.join(x if x.isalnum() else '_' for x in ctrlName)

    if os.path.exists(controlFilePath(ctrlName)):
        result = mc.confirmDialog(title='Control Exists', 
                                  message='A control of this name already exists.', 
                                  button=['Overwrite','Cancel'], 
                                  defaultButton='Cancel', 
                                  cancelButton='Cancel', 
                                  dismissString='Cancel'
                                  )
        if result != 'Overwrite':
            return 

    ctrl = exportControl(sel, ctrlName)

    strokes = mc.ls(type='stroke')

    #create the icon
    mc.ResetTemplateBrush()
    brush = mc.getDefaultBrush()
    mc.setAttr(brush+'.screenspaceWidth', 1)
    mc.setAttr(brush+'.distanceScaling', 0.01)
    mc.setAttr(brush+'.color1', 0.1, 0.65, 1, type='double3')

    mc.select(ctrl)
    mc.AttachBrushToCurves(ctrl)
    image = utl.renderShelfIcon(name=ctrlName, width=64, height=64)

    imagePath = os.path.join(REPOSITORY_PATH, os.path.basename(image))
    shutil.move(image, imagePath)

    #delete new strokes.
    newStrokes = [x for x in mc.ls(type='stroke') if x not in strokes]
    for each in newStrokes:
        mc.delete(mc.listRelatives(each, parent=True, pa=True))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号