python类setAttr()的实例源码

pipeline.py 文件源码 项目:core 作者: getavalon 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def lock():
    """Lock scene

    Add an invisible node to your Maya scene with the name of the
    current file, indicating that this file is "locked" and cannot
    be modified any further.

    """

    if not cmds.objExists("lock"):
        with lib.maintained_selection():
            cmds.createNode("objectSet", name="lock")
            cmds.addAttr("lock", ln="basename", dataType="string")

            # Permanently hide from outliner
            cmds.setAttr("lock.verticesOnlySet", True)

    fname = cmds.file(query=True, sceneName=True)
    basename = os.path.basename(fname)
    cmds.setAttr("lock.basename", basename, type="string")
maya_tools.py 文件源码 项目:gozbruh 作者: LumaPictures 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def create(obj):
    """Tell ZBrush to treat `obj` as a new object.

    Under the hood this changes a gozbruhBrush ID to match object name.
    """
    # does not change selection:
    cmds.delete(obj, constructionHistory=True)
    shape = cmds.ls(obj, type='mesh', dag=True)[0]
    xform = cmds.listRelatives(shape, parent=True, fullPath=True)[0]
    goz_check_xform = cmds.attributeQuery(
        'gozbruhBrushID', node=xform, exists=True)
    goz_check_shape = cmds.attributeQuery(
        'gozbruhBrushID', node=shape, exists=True)

    if goz_check_shape:
        cmds.setAttr(shape + '.gozbruhBrushID', obj, type='string')
    if goz_check_xform:
        cmds.setAttr(xform + '.gozbruhBrushID', obj, type='string')
    return xform
ml_arcTracer.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def applyBrush(curve, parent):
    '''
    Simply applies the paint effects brush to the curve with the settings we want.
    '''

    mc.AttachBrushToCurves(curve)
    stroke = mc.ls(sl=True)[0]
    stroke = mc.parent(stroke,parent)[0]

    mc.setAttr(stroke+'.displayPercent',92)
    mc.setAttr(stroke+'.sampleDensity',0.5)
    mc.setAttr(stroke+'.inheritsTransform',0)
    mc.setAttr(stroke+'.translate',0,0,0)
    mc.setAttr(stroke+'.rotate',0,0,0)

    return stroke
ml_puppet.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def attributeMenuItem(node, attr):

    plug = node+'.'+attr
    niceName = mc.attributeName(plug, nice=True)

    #get attribute type
    attrType = mc.getAttr(plug, type=True)

    if attrType == 'enum':
        listEnum = mc.attributeQuery(attr, node=node, listEnum=True)[0]
        if not ':' in listEnum:
            return
        listEnum = listEnum.split(':')
        mc.menuItem(label=niceName, subMenu=True)
        for value, label in enumerate(listEnum):
            mc.menuItem(label=label, command=partial(mc.setAttr, plug, value))
        mc.setParent('..', menu=True)
    elif attrType == 'bool':
        value = mc.getAttr(plug)
        label = 'Toggle '+ niceName
        mc.menuItem(label=label, command=partial(mc.setAttr, plug, not value))
ml_utilities.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setAnimValue(plug, value, tangentType=None):
    '''
    Sets key if the channel is keyed, otherwise setAttr
    '''

    if mc.keyframe(plug, query=True, name=True):
        mc.setKeyframe(plug, value=value)
        if tangentType:
            time = mc.currentTime(query=True)
            itt = tangentType
            ott = tangentType
            if tangentType == 'step':
                itt = 'linear'
            mc.keyTangent(plug, time=(time,), edit=True, itt=itt, ott=ott)                                            

    mc.setAttr(plug, value)
ml_colorControl.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def colorShape(obj, rgb=None, hsv=None):

    if not rgb:
        if hsv and len(hsv) == 3:
            rgb = colorsys.hsv_to_rgb(*hsv)
        else:
            raise RuntimeError('colorShape requires an rgb or hsv input.')

    mc.setAttr('{}.overrideEnabled'.format(obj), 1)
    mc.setAttr('{}.overrideRGBColors'.format(obj), 1)
    mc.setAttr('{}.overrideColorRGB'.format(obj), *rgb)

    shapes = mc.listRelatives(obj, shapes=True, pa=True)
    for shape in shapes:
        #if mc.getAttr('{}.overrideEnabled'.format(shape)): 
        mc.setAttr('{}.overrideEnabled'.format(shape), 1)           
        mc.setAttr('{}.overrideRGBColors'.format(shape), 1)
        mc.setAttr('{}.overrideColorRGB'.format(shape), *rgb)
ml_toggleVisibility.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def main():

    sel = mc.ls(sl=True)

    if not sel:
        return

    for each in sel:
        plug = each+'.v'
        try:
            locked = mc.getAttr(plug, lock=True)
            if locked:
                mc.setAttr(plug, lock=False)

            if mc.getAttr(plug):
                mc.setAttr(plug, 0)
            else:
                mc.setAttr(plug, 1)

            if locked:
                mc.setAttr(plug, lock=True)
        except:
            pass
maya_functions.py 文件源码 项目:TACTIC-Handler 作者: listyque 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_info_to_scene(search_key, context):
    # add info about particular scene
    skey_link = 'skey://{0}&context={1}'.format(search_key, context)
    if not cmds.attributeQuery('tacticHandler_skey', node='defaultObjectSet', exists=True):
        cmds.addAttr('defaultObjectSet', longName='tacticHandler_skey', dataType='string')
    cmds.setAttr('defaultObjectSet.tacticHandler_skey', skey_link, type='string')
tools.py 文件源码 项目:config 作者: mindbender-studio 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def on_pool_changed(self, index):
        pool = self.pools.itemText(index)
        cmds.setAttr(self.render_globals + ".pool", pool, type="string")
tools.py 文件源码 项目:config 作者: mindbender-studio 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def on_group_changed(self, index):
        group = self.groups.itemText(index)
        cmds.setAttr(self.render_globals + ".group", group, type="string")
__init__.py 文件源码 项目:config 作者: mindbender-studio 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _set_uuid(node):
    """Add mbID to `node`

    Unless one already exists.

    """

    attr = "{0}.mbID".format(node)

    if not cmds.objExists(attr):
        cmds.addAttr(node, longName="mbID", dataType="string")
        _, uid = str(uuid.uuid4()).rsplit("-", 1)
        cmds.setAttr(attr, uid, type="string")
orientjoints.py 文件源码 项目:cmt 作者: chadmv 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def zero_orient(joints):
    for joint in joints:
        children = _unparent_children(joint)
        cmds.setAttr('{0}.jointOrient'.format(joint), 0, 0, 0)
        _reparent_children(joint, children)

    if joints:
        cmds.select(joints)
orientjoints.py 文件源码 项目:cmt 作者: chadmv 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def template_joints(joints=None, reorient_children=True, reset_orientation=True):
    if joints is None:
        joints = cmds.ls(sl=True, type='joint')
    if not joints:
        raise RuntimeError('No joint selected to orient.')

    if reorient_children:
        children = cmds.listRelatives(fullPath=True, allDescendents=True, type='joint')
        joints.extend(children)

    red, green, blue = create_shaders()

    orient_group = cmds.createNode('transform', name=ORIENT_GROUP)
    manips = []
    for joint in joints:
        if reset_orientation:
            cmds.makeIdentity(joint, apply=True)
            cmds.joint(joint, edit=True, orientJoint='xyz', secondaryAxisOrient='yup', children=False, zeroScaleOrient=True)
        if not cmds.listRelatives(joint, children=True):
            zero_orient([joint])
            continue
        group, manip = create_orient_manipulator(joint, blue)
        manips.append(manip)
        cmds.parent(group, orient_group)
        cmds.parentConstraint(joint, group)
        cmds.setAttr(joint + '.template', 1)
    cmds.select(manips)
orientjoints.py 文件源码 项目:cmt 作者: chadmv 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def create_orient_manipulator(joint, material):
    joint_scale = cmds.jointDisplayScale(query=True)
    joint_radius = cmds.getAttr('{0}.radius'.format(joint))
    radius = joint_scale * joint_radius
    children = cmds.listRelatives(joint, children=True, path=True)
    if children:
        p1 = cmds.xform(joint, q=True, ws=True, t=True)
        p1 = OpenMaya.MPoint(*p1)
        p2 = cmds.xform(children[0], q=True, ws=True, t=True)
        p2 = OpenMaya.MPoint(*p2)
        radius = p1.distanceTo(p2)
    arrow_cvs = [[-1, 0, 0], [-1, 2, 0], [-2, 2, 0], [0, 4, 0], [2, 2, 0], [1, 2, 0], [1, 0, 0], [-1, 0, 0]]
    arrow_cvs = [[x[0]*radius, x[1]*radius, x[2]*radius] for x in arrow_cvs]
    shape = cmds.curve(name='{0}_zForward'.format(joint), degree=1, point=arrow_cvs)
    # shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0]
    # cmds.setAttr('{0}.sz'.format(shape), 0)
    # cmds.select(shape)
    # cmds.hyperShade(assign=material)
    group = cmds.createNode('transform', name='{0}_grp'.format(shape))
    cmds.parent(shape, group)
    cmds.makeIdentity(shape, apply=True)
    cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType='message')
    cmds.connectAttr('{0}.message'.format(joint), '{0}.{1}'.format(shape, MESSAGE_ATTRIBUTE))
    for attr in ['tx', 'ty', 'tz', 'ry', 'rz', 'v']:
        cmds.setAttr('{0}.{1}'.format(shape, attr), lock=True, keyable=False)
    return group, shape
control.py 文件源码 项目:cmt 作者: chadmv 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def set_color(self):
        """Open a dialog to set the override RGB color of the selected nodes."""
        nodes = cmds.ls(sl=True) or []
        if nodes:
            color = cmds.getAttr('{0}.overrideColorRGB'.format(nodes[0]))[0]
            color = QtGui.QColor(color[0]*255, color[1]*255, color[2]*255)
            color = QtWidgets.QColorDialog.getColor(color, self, 'Set Curve Color')
            if color.isValid():
                color = [color.redF(), color.greenF(), color.blueF()]
                for node in nodes:
                    cmds.setAttr('{0}.overrideEnabled'.format(node), True)
                    cmds.setAttr('{0}.overrideRGBColors'.format(node), True)
                    cmds.setAttr('{0}.overrideColorRGB'.format(node), *color)
maya_warpper.py 文件源码 项目:pipeline 作者: liorbenhorin 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def snapshot(path = None, width = 96, height = 96):
    current_image_format = cmds.getAttr("defaultRenderGlobals.imageFormat")
    cmds.setAttr("defaultRenderGlobals.imageFormat", 32) # *.png
    #path = "/Users/liorbenhorin/Library/Preferences/Autodesk/maya/2015-x64/scripts/pipeline/thumb.png"
    cmds.playblast(cf = path, fmt="image", frame = cmds.currentTime( query=True ), orn=False, wh = [width,height], p=100, v=False)
    cmds.setAttr("defaultRenderGlobals.imageFormat", current_image_format)

    if os.path.isfile(path):
        return path
    else:
        return False
fov_converter.py 文件源码 项目:surume 作者: tm8r 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _apply(self, *args):
        selected = cmds.textScrollList(self.text_scroll, q=True, si=True)
        fov = cmds.textFieldGrp(self.text_field, q=True, tx=True)
        if not selected or not fov:
            return
        camera = selected[0]
        vfa = cmds.getAttr(camera + ".verticalFilmAperture")

        focal_length = 0.5 * vfa / math.tan(float(fov) / 2.0 / 57.29578) / 0.03937

        cmds.setAttr(camera + ".focalLength", focal_length)
        cmds.textFieldGrp(self.result_field, e=True, tx=round(focal_length, 3))
BlendTransforms.py 文件源码 项目:BlendTransforms 作者: duncanskertchly 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def BT_Setup(set = None):

    if not set:
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
        cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
    else:
        return False

    btNode = cmds.createNode("BlendTransforms")
    cmds.setAttr(set +'.Blend_Node', btNode, type = "string")

    for i in range(0, len(transforms)):
        baseMatrix = cmds.xform(transforms[i], q = True, m = True)
        baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
        baseRotOffset = [0.0, 0.0, 0.0]

        if cmds.objectType(transforms[i], isType = 'joint'):
            baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]

        btAttr = 'transforms[' +str(i) +'].baseMatrix'
        btScaleAttr = 'transforms[' +str(i) +'].baseScale'
        btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'

        BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
        BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
        BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
        BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])

    return True
BlendTransforms.py 文件源码 项目:BlendTransforms 作者: duncanskertchly 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def BT_Double3ValuesToNode(values = None, node = None, attr = None):
    if not values or len(values) != 3:
        return False

    cmds.setAttr(node +'.' +attr, values[0], values[1], values[2], type = 'double3')
BlendTransforms.py 文件源码 项目:BlendTransforms 作者: duncanskertchly 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def BT_Setup(set = None):

    if not set:
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
        cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
    else:
        return False

    btNode = cmds.createNode("BlendTransforms")
    cmds.setAttr(set +'.Blend_Node', btNode, type = "string")

    for i in range(0, len(transforms)):
        baseMatrix = cmds.xform(transforms[i], q = True, m = True)
        baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
        baseRotOffset = [0.0, 0.0, 0.0]

        if cmds.objectType(transforms[i], isType = 'joint'):
            baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]

        btAttr = 'transforms[' +str(i) +'].baseMatrix'
        btScaleAttr = 'transforms[' +str(i) +'].baseScale'
        btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'

        BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
        BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
        BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
        BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])

    return True


问题


面经


文章

微信
公众号

扫码关注公众号