Python maya.cmds 模块,objectType() 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用maya.cmds.objectType()

项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def getNormalizedTangent(pt = ""):
    """
    gets normalized tan of selected (or given) list of cvs
    """

    if cmds.objectType(pt) != "nurbsCurve":
        return

    crv = pt.partition(".")[0]
    print pt, crv
    cvs = cmds.ls("{0}.cv[*]".format(crv), fl=True)
    denom = len(cvs)
    num = float(pt.partition("[")[2].rpartition("]")[0])
    pr = num/denom
    tan = cmds.pointOnCurve(crv, pr=pr, nt=True)

    return(tan)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def delete_later_keys(obj, frame, *args):
    """sets a key at 'frame' and then deletes all subsequent keys in the timeline (time based only)"""
    animTypes = ["animCurveTL","animCurveTA", "animCurveTT", "animCurveTU"]
    animNodes = cmds.listConnections(obj, type="animCurve")
    if not animNodes:
        return()
    for a in animNodes:
        if (cmds.objectType(a)in animTypes):
            cmds.setKeyframe(a, time=frame)
            cmds.cutKey(a,clear=1, time=(frame + 1, 100000))
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def setValues(*args):
    """sets the values from window on all selected objs for appropriate channels"""

    sel = cmds.ls(sl=True)

    attrs = cmds.checkBoxGrp(widgets["transCBG"], q=True, va3=True)
    trans = attrs[0]
    rots = attrs[1]
    scls = attrs[2]

    for obj in sel:
        if cmds.objectType(obj)=="transform":
            if trans:
                t = cmds.floatFieldGrp(widgets["trnFFG"], q=True, v=True)
                cmds.setAttr("{}.translate".format(obj), t[0], t[1], t[2])
            if rots:
                r = cmds.floatFieldGrp(widgets["rotFFG"], q=True, v=True)
                cmds.setAttr("{}.rotate".format(obj), r[0],r[1], r[2])
            if scls:
                s = cmds.floatFieldGrp(widgets["sclFFG"], q=True, v=True)
                cmds.setAttr("{}.scale".format(obj), s[0], s[1], s[2])
项目:PythonForMayaSamples    作者:dgovil    | 项目源码 | 文件源码
def createPipe(self, spans):
        # We set the transform and shape to the class variables
        self.transform, self.shape = cmds.polyPipe(subdivisionsAxis=spans)

        # I didn't like having to find the constructor from the extrude node
        # Lets just find it now and save it to the class because it won't change
        for node in cmds.listConnections('%s.inMesh' % self.transform):
            if cmds.objectType(node) == 'polyPipe':
                self.constructor = node
                break
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
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    作者:duncanskertchly    | 项目源码 | 文件源码
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    作者:duncanskertchly    | 项目源码 | 文件源码
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
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def setPlanes(*args):
    """sets clipping planes for cameras based on float fields in UI. Depending on radio button, it will either do all camera or only selected"""

    all = cmds.radioButtonGrp("camRBG", q=True, sl=True)
    far = cmds.floatFieldGrp("farFFG", q=True, v1=True)
    near = cmds.floatFieldGrp("nearFFG", q=True, v1=True)

    cams = []
    if all==1:
        cams.extend(cmds.ls(type="camera"))
    elif all==2:
        transf = cmds.ls(sl=True, type="transform")
        for each in transf:
            shape = cmds.listRelatives(each, s=True)
            if shape:
                if cmds.objectType(shape) == "camera":
                    cams.extend(shape)
    #for each, set shape.farClipPlane 100000
    if cams:
        print cams
        for cam in cams:
            try:
                cmds.setAttr("%s.farClipPlane"%cam, far)
                cmds.setAttr("%s.nearClipPlane"%cam, near)

            except:
                cmds.warning("Couldn't change the farClipPlane of %s"%cam)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def getGeo(self, *args):
        #get selection and put it's full path into the tfbg
        sel = cmds.ls(sl=True, type="transform", l=True)
        print(sel)
        if len(sel) != 1:
            cmds.warning("yo. Select one and only one nurbs surface")
        else:
            #check for nurbsy-ness
            if (cmds.objectType(cmds.listRelatives(sel[0], shapes=True)[0])!="nurbsSurface"):
                cmds.error("Selected is not a nurbs surface")
            else:
                cmds.textFieldButtonGrp(self.widgets["geoTFBG"], e=True, tx=sel[0])
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def curveCheck(obj):
    """ takes object and returns true if it's a curve"""
    shpList = cmds.listRelatives(obj, shapes=True)
    if (not shpList) or (cmds.objectType(shpList[0]) != "nurbsCurve"):
        return False
    else:
        return True
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def isType(obj, typeCheck, *args):
    """
    returns boolean
    give an object and type of object and this will look at a) the node itself and b) if node is transform, will look at shape node
    """
    if cmds.objExists(obj):
        tempType = cmds.objectType(obj)
        if typeCheck == "transform":
            if tempType == "transform":
                return (True)
            else:
                return (False)

        if not tempType == "transform":
            if tempType == typeCheck:
                return True
        else:
            shp = cmds.listRelatives(obj, s=True)
            if shp:
                tempType = cmds.objectType(shp[0])

        if tempType == typeCheck:
            return True

        return False
    return False
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def assignColor(obj=None, clr="yellow", *args):

    if cmds.objectType(obj) != "transform":
        return()

    colors = {}
    colors["red"]=13
    colors["blue"]=6
    colors["green"]=14
    colors["darkRed"]=4
    colors["lightRed"]=31
    colors["darkBlue"]=5
    colors["medBlue"]=15
    colors["lightBlue"]=18
    colors["royalBlue"]=29
    colors["darkGreen"]=7
    colors["medGreen"]=27
    colors["lightGreen"]=19
    colors["yellowGreen"]=26
    colors["yellow"]=17
    colors["darkYellow"]=21
    colors["lightYellow"]=22
    colors["purple"]=30
    colors["lightPurple"]=9
    colors["darkPurple"]=8
    colors["black"]=1
    colors["white"]=16
    colors["brown"]=10
    colors["darkBrown"]=11
    colors["lightBrown"]=24
    colors["pink"]=20
    colors["orange"] =12

    shp = cmds.listRelatives(obj, s=True)
    if shp:
        for s in shp:
            cmds.setAttr("{0}.overrideEnabled".format(s), 1)
            cmds.setAttr("{0}.overrideColor".format(s), colors[clr])
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def prepExtrude(*args):

    name = cmds.textFieldGrp(widgets["nameTFG"], q=True, tx=True)
    if not name:
        cmds.warning("You must give the extrusion a name!")
        return

    if cmds.objExists("{}_extRig_GRP".format(name)):
        cmds.warning("A rig of this name already exists")
        return

    sel = cmds.ls(sl=True, exactType = "transform")
    if len(sel) < 1 or len(sel)>3:
        cmds.warning("You must select the profile crv, then path crv, then optionally a cap rig top node")
        return

    if len(sel)==2:
        for x in range(2):
            shp = cmds.listRelatives(sel[x], shapes=True)
            if shp:
                if cmds.objectType(shp[0]) != "nurbsCurve":
                    cmds.warning("{} is not a curve!".format(sel[x]))
                    return          
    elif len(sel) == 1:
        shp = cmds.listRelatives(sel[0], shapes=True)
        if shp:
            if cmds.objectType(shp[0]) != "nurbsCurve":
                cmds.warning("{} is not a curve!".format(sel[0]))
                return

    extrude(name)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def reverseCrv(*args):
  sel = cmds.ls(sl=True)[0]
  shp = cmds.listRelatives(sel, shapes=True)
  if cmds.objectType(shp) != "nurbsCurve":
    cmds.warning("not a nurbs curve to reverse")
  else: 
    revCrv = cmds.reverseCurve(sel, rpo=True, ch=False)[0]
    cmds.select(revCrv)
    print("reversed curve: %s!"%revCrv)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def getValues(*args):
    """gets the values for the appropriate channels from first selected obj"""

    cmds.floatFieldGrp(widgets["trnFFG"], e=True, v = (0.0,0.0,0.0,0.0))
    cmds.floatFieldGrp(widgets["rotFFG"], e=True, v = (0.0,0.0,0.0,0.0))
    cmds.floatFieldGrp(widgets["sclFFG"], e=True, v = (1.0,1.0,1.0,1.0))

    obj = ""

    attrs = cmds.checkBoxGrp(widgets["transCBG"], q=True, va3=True)
    trans = attrs[0]
    rots = attrs[1]
    scls = attrs[2]

    sel = cmds.ls(sl=True)
    if sel:
        obj = sel[0]
        if cmds.objectType(obj)=="transform":
            t = cmds.getAttr("{}.translate".format(obj))[0]
            cmds.floatFieldGrp(widgets["trnFFG"], e=True, v1 = t[0])
            cmds.floatFieldGrp(widgets["trnFFG"], e=True, v2 = t[1])
            cmds.floatFieldGrp(widgets["trnFFG"], e=True, v3 = t[2])
            r = cmds.getAttr("{}.rotate".format(obj))[0]
            cmds.floatFieldGrp(widgets["rotFFG"], e=True, v1 = r[0])
            cmds.floatFieldGrp(widgets["rotFFG"], e=True, v2 = r[1])
            cmds.floatFieldGrp(widgets["rotFFG"], e=True, v3 = r[2])
            s = cmds.getAttr("{}.scale".format(obj))[0]
            cmds.floatFieldGrp(widgets["sclFFG"], e=True, v1 = s[0])
            cmds.floatFieldGrp(widgets["sclFFG"], e=True, v2 = s[1])
            cmds.floatFieldGrp(widgets["sclFFG"], e=True, v3 = s[2])

        else: 
            cmds.warning("Select an object to catch transforms from")
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def detectClashes(fixClashes=True):
    """
    look in the scene and returns a list of names that clash (transform only, as shapes will get taken care of by
    renaming or another pass of cleaning shapes)
    """
    clashingNames = []
    mayaResolvedName = {}

    allDagNodes = cmds.ls(dag=1)  # get all dag nodes
    for node in allDagNodes:
        if cmds.objectType(node) == "transform":  # only transforms
            if len(node.split("|")) > 1:  # is it a dupe (split by "|")
                clashingNames.append(node.split("|")[-1])  # add it to the list

    clashes = set(clashingNames)  # get rid of dupes, so only one of each name
    print "\n==========================="
    print "Clashing objects: {}".format(list(clashes))

    if fixClashes and clashes:
        fixFirstClash(clashes, 0)

    elif clashes and not fixClashes:
        for clash in clashes:
            print "CLASH -->", clash
            print cmds.ls(clash)

    if not clashes:
        cmds.warning("No transform clashes found")

        # return(list(clashes))
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelBox_ModifyPlugsInLayers(plugs, layers, operation):
    if not plugs:
        cmds.error("No channel attributes selected.")
    if not layers:
        cmds.error("No layer is selected.  Please select a layer.")

    for layer in layers:
        if not cmds.objectType(layer, isType="animLayer"):
            continue
        for plug in plugs:
            if operation:
                mel.eval("evalEcho( \"animLayer -edit -attribute " + plug + " " + layer + "\");")
            else:
                mel.eval("evalEcho( \"animLayer -edit -removeAttribute " + plug + " " + layer + "\");")
项目:maya-capture-gui    作者:Colorbleed    | 项目源码 | 文件源码
def get_current_camera():
    """Returns the currently active camera.

    Searched in the order of:
        1. Active Panel
        2. Selected Camera Shape
        3. Selected Camera Transform

    Returns:
        str: name of active camera transform

    """

    # Get camera from active modelPanel  (if any)
    panel = cmds.getPanel(withFocus=True)
    if cmds.getPanel(typeOf=panel) == "modelPanel":
        cam = cmds.modelEditor(panel, query=True, camera=True)
        # In some cases above returns the shape, but most often it returns the
        # transform. Still we need to make sure we return the transform.
        if cam:
            if cmds.nodeType(cam) == "transform":
                return cam
            # camera shape is a shape type
            elif cmds.objectType(cam, isAType="shape"):
                parent = cmds.listRelatives(cam, parent=True, fullPath=True)
                if parent:
                    return parent[0]

    # Check if a camShape is selected (if so use that)
    cam_shapes = cmds.ls(selection=True, type="camera")
    if cam_shapes:
        return cmds.listRelatives(cam_shapes,
                                  parent=True,
                                  fullPath=True)[0]

    # Check if a transform of a camShape is selected
    # (return cam transform if any)
    transforms = cmds.ls(selection=True, type="transform")
    if transforms:
        cam_shapes = cmds.listRelatives(transforms, shapes=True, type="camera")
        if cam_shapes:
            return cmds.listRelatives(cam_shapes,
                                      parent=True,
                                      fullPath=True)[0]
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_SetPose(set = None, index = None):
    if not set:
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Disconnect setup first!')
        return False

    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

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

    unitResult = BT_SetUnits()
    if unitResult:
        QtGui.QMessageBox.warning(BT_GetMayaWindow(), "Blend Transforms", "Units set to centimetres.", "Okay")

    for i in range(0, len(transforms)):
        baseM = cmds.getAttr(node +'.transforms[' +str(i) +'].baseMatrix')
        baseS = cmds.getAttr(node +'.transforms[' +str(i) +'].baseScale')[0]
        baseRO = cmds.getAttr(node +'.transforms[' +str(i) +'].baseRotOffset')[0]

        poseM = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        poseS = [0,0,0]

        if index is not None:
            numPoses = cmds.getAttr(node +'.transforms[0].poses', size = True)
            if not index < numPoses:
                return False 
            poseM = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].matrix')
            poseS = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].scale')[0]

        finalM = [x+y for x, y in zip(poseM, baseM)]
        finalS = [x+y for x, y in zip(poseS, baseS)]

        cmds.xform(transforms[i], m = finalM)
        cmds.setAttr(transforms[i] +'.scale', finalS[0], finalS[1], finalS[2], type = 'double3')
        #hack to fix joint orient stuff
        if cmds.objectType(transforms[i], isType = 'joint'):
            cmds.setAttr(transforms[i] +'.jointOrient', baseRO[0], baseRO[1], baseRO[2], type = 'double3')
            currentRot = cmds.getAttr(transforms[i] +'.rotate')[0]
            cmds.setAttr(transforms[i] +'.rotate', currentRot[0] - baseRO[0], currentRot[1] - baseRO[1], currentRot[2] - baseRO[2], type = 'double3')


    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_SetPose(set = None, index = None):
    if not set:
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Disconnect setup first!')
        return False

    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

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

    unitResult = BT_SetUnits()
    if unitResult:
        QtGui.QMessageBox.warning(BT_GetMayaWindow(), "Blend Transforms", "Units set to centimetres.", "Okay")

    for i in range(0, len(transforms)):
        baseM = cmds.getAttr(node +'.transforms[' +str(i) +'].baseMatrix')
        baseS = cmds.getAttr(node +'.transforms[' +str(i) +'].baseScale')[0]
        baseRO = cmds.getAttr(node +'.transforms[' +str(i) +'].baseRotOffset')[0]

        poseM = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        poseS = [0,0,0]

        if index is not None:
            numPoses = cmds.getAttr(node +'.transforms[0].poses', size = True)
            if not index < numPoses:
                return False 
            poseM = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].matrix')
            poseS = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].scale')[0]

        finalM = [x+y for x, y in zip(poseM, baseM)]
        finalS = [x+y for x, y in zip(poseS, baseS)]

        cmds.xform(transforms[i], m = finalM)
        cmds.setAttr(transforms[i] +'.scale', finalS[0], finalS[1], finalS[2], type = 'double3')
        #hack to fix joint orient stuff
        if cmds.objectType(transforms[i], isType = 'joint'):
            cmds.setAttr(transforms[i] +'.jointOrient', baseRO[0], baseRO[1], baseRO[2], type = 'double3')
            currentRot = cmds.getAttr(transforms[i] +'.rotate')[0]
            cmds.setAttr(transforms[i] +'.rotate', currentRot[0] - baseRO[0], currentRot[1] - baseRO[1], currentRot[2] - baseRO[2], type = 'double3')


    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_SetPose(set = None, index = None):
    if not set:
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Disconnect setup first!')
        return False

    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

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

    unitResult = BT_SetUnits()
    if unitResult:
        QtGui.QMessageBox.warning(BT_GetMayaWindow(), "Blend Transforms", "Units set to centimetres.", "Okay")

    for i in range(0, len(transforms)):
        baseM = cmds.getAttr(node +'.transforms[' +str(i) +'].baseMatrix')
        baseS = cmds.getAttr(node +'.transforms[' +str(i) +'].baseScale')[0]
        baseRO = cmds.getAttr(node +'.transforms[' +str(i) +'].baseRotOffset')[0]

        poseM = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        poseS = [0,0,0]

        if index is not None:
            numPoses = cmds.getAttr(node +'.transforms[0].poses', size = True)
            if not index < numPoses:
                return False 
            poseM = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].matrix')
            poseS = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].scale')[0]

        finalM = [x+y for x, y in zip(poseM, baseM)]
        finalS = [x+y for x, y in zip(poseS, baseS)]

        cmds.xform(transforms[i], m = finalM)
        cmds.setAttr(transforms[i] +'.scale', finalS[0], finalS[1], finalS[2], type = 'double3')
        #hack to fix joint orient stuff
        if cmds.objectType(transforms[i], isType = 'joint'):
            cmds.setAttr(transforms[i] +'.jointOrient', baseRO[0], baseRO[1], baseRO[2], type = 'double3')
            currentRot = cmds.getAttr(transforms[i] +'.rotate')[0]
            cmds.setAttr(transforms[i] +'.rotate', currentRot[0] - baseRO[0], currentRot[1] - baseRO[1], currentRot[2] - baseRO[2], type = 'double3')


    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_SetPose(set = None, index = None):
    if not set:
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Disconnect setup first!')
        return False

    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

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

    unitResult = BT_SetUnits()
    if unitResult:
        QtGui.QMessageBox.warning(BT_GetMayaWindow(), "Blend Transforms", "Units set to centimetres.", "Okay")

    for i in range(0, len(transforms)):
        baseM = cmds.getAttr(node +'.transforms[' +str(i) +'].baseMatrix')
        baseS = cmds.getAttr(node +'.transforms[' +str(i) +'].baseScale')[0]
        baseRO = cmds.getAttr(node +'.transforms[' +str(i) +'].baseRotOffset')[0]

        poseM = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        poseS = [0,0,0]

        if index is not None:
            numPoses = cmds.getAttr(node +'.transforms[0].poses', size = True)
            if not index < numPoses:
                return False 
            poseM = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].matrix')
            poseS = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].scale')[0]

        finalM = [x+y for x, y in zip(poseM, baseM)]
        finalS = [x+y for x, y in zip(poseS, baseS)]

        cmds.xform(transforms[i], m = finalM)
        cmds.setAttr(transforms[i] +'.scale', finalS[0], finalS[1], finalS[2], type = 'double3')
        #hack to fix joint orient stuff
        if cmds.objectType(transforms[i], isType = 'joint'):
            cmds.setAttr(transforms[i] +'.jointOrient', baseRO[0], baseRO[1], baseRO[2], type = 'double3')
            currentRot = cmds.getAttr(transforms[i] +'.rotate')[0]
            cmds.setAttr(transforms[i] +'.rotate', currentRot[0] - baseRO[0], currentRot[1] - baseRO[1], currentRot[2] - baseRO[2], type = 'double3')


    return True
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def curve_through_selection(*args):
    """
    creates a curve through the selection, hopefully in order
    Args:
        None
    Returns:
        string, name of curve created
    """
    sel = cmds.ls(sl=True, fl=True)
    if not sel or len(sel)==1:
        cmds.warning("You need to select multiple things to create curve through!")
        return()

    pList = []
    crvType = cmds.radioButtonGrp(widgets["crvSelRBG"], q=True, sl=True)

    for obj in sel:
        if cmds.objectType(obj) in ["transform"]:
            pos = cmds.xform(obj, q=True, ws=True, rp=True)
            pList.append(pos)
        elif obj in cmds.filterExpand(sm=[28, 30, 31, 32, 34, 46]):
            pos = cmds.pointPosition(obj)
            pList.append(pos)

    #add points if only 2 (cv, ep) or 3 (cv) are given, and create the curve
    if crvType == 1:
        if len(pList) == 2:
            f = [float(sum(x)/2) for x in zip(*pList)]
            pList.insert(1, f)
            vec1 = [pList[1][0]-pList[0][0], pList[1][1]-pList[0][1], pList[1][2]-pList[0][2]]
            newPt1 =[pList[0][0] + (vec1[0]*0.05), pList[0][1] + (vec1[1]*0.05), pList[0][2] + (vec1[2]*0.05)]
            vec2 = [pList[1][0] - pList[2][0], pList[1][1] - pList[2][1], pList[1][2] - pList[2][2]]
            newPt2= [pList[2][0] + (vec2[0]*0.05), pList[2][1] + (vec2[1]*0.05), pList[2][2] + (vec2[2]*0.05)]
            pList.insert(1, newPt1)
            pList.insert(3, newPt2)
        if len(pList) == 3:
            vec1 = [pList[1][0]-pList[0][0], pList[1][1]-pList[0][1], pList[1][2]-pList[0][2]]
            newPt1 =[pList[0][0] + (vec1[0]*0.05), pList[0][1] + (vec1[1]*0.05), pList[0][2] + (vec1[2]*0.05)]
            vec2 = [pList[1][0] - pList[2][0], pList[1][1] - pList[2][1], pList[1][2] - pList[2][2]]
            newPt2= [pList[2][0] + (vec2[0]*0.05), pList[2][1] + (vec2[1]*0.05), pList[2][2] + (vec2[2]*0.05)]
            pList.insert(1, newPt1)
            pList.insert(3, newPt2)
        crv = cmds.curve(d=3, p=pList, name="newCurve")

    if crvType == 2:
        if len(pList) == 2:
            f = [float(sum(x)/2) for x in zip(*pList)]
            pList.insert(1, f)
        crv = cmds.curve(d=3, ep=pList, name="newCurve")

    return(crv)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def extendPoly(*args):
    """does the polyextension by grabbing the curve, offsetting it and then lofting. Then converts the nurbs surface to polys"""

    #make sure a curve is selected
    selection = cmds.ls(sl=True)
    if selection:
        sel = selection[0]
        shape = cmds.listRelatives(sel, s=True)[0]
        type = cmds.objectType(shape)
        name = cmds.textFieldGrp("name", q=True, tx=True)
        hisGrp = cmds.checkBox("history", q=True, v=True)
        hisPoly = cmds.checkBox("polyHistory", q=True, v=True)

        if type== "nurbsCurve":
            #offset the curb
            distance = cmds.floatFieldGrp("curbFFG", q=True, v1=True)
            # bump = cmds.checkBox("bumpCB", q=True, v=True)
            pos = cmds.checkBox("curbCB", q=True, v=True)
            if pos == 0:
                dist = distance * -1
            else:
                dist = distance
            U = cmds.intFieldGrp("UDivIFG", q=True, v1=True)
            V = cmds.intFieldGrp("VDivIFG", q=True, v1=True)

            origCrv = cmds.rename(sel, "%s_inner_CRV"%name)
            outCurve = cmds.offsetCurve(origCrv, d=dist, n="%s_outer_CRV"%name)
            midCurve = cmds.offsetCurve(origCrv, d=dist/2, n="%s_mid_CRV"%name)
            # if bump:
            #     cmds.xform(midCurve, ws=True, r=True, t=(0,5,0))

            cmds.select(cl=True)

            lofted = cmds.loft(origCrv, midCurve, outCurve)[0]
            loft = cmds.rename(lofted, "%s_lofted"%name)

            polygon = cmds.nurbsToPoly(loft, pt=1, ch=hisPoly, f=2, un=U, vn=V)[0]
            poly = cmds.rename(polygon, "%s_poly"%name)

            curbGrp = cmds.group(empty=True)
            grp = cmds.rename(curbGrp, "%s_History_GRP"%name)

            # cmds.rename(poly, "polyCurb")

            cmds.parent(loft, outCurve, midCurve, origCrv, grp)

            cmds.setAttr("%s.v"%grp, 0)
            if not hisGrp:
                cmds.delete(grp)

        else:
            cmds.warning("That's not a curve! You need to select a curve!")
    else:
        cmds.warning("You haven't selected anything!")