python - 玛雅Python : Check to see if the attribute has any keyframes

标签 python graphics 3d maya maya-api

我正在尝试为 Maya 编写一个 python 脚本,它将关键帧从一个装备复制到另一个装备。我找到了物体并将它们配对。我现在想做的是从原始对象复制 key (如果原始对象有要复制的 key )。我希望使用关键帧命令来检查对象是否有键。

示例:if cmds.keyframe(oldObjPath attribute=oldAttr,sl=True, q=True, tc=True ) > 0:

然而,这总是返回 false。当我打印出 oldObjPath 的属性时,我确实打印出了所有属性。知道我在这里做错了什么吗?完整代码如下

有关关键帧命令的文档: http://download.autodesk.com/global/docs/maya2014/en_us/index.html?url=files/Python_Python_in_Maya.htm,topicNumber=d30e813275

#create a decunary of the object names and paths for faster searching
#[search_name:path]

originalObjectDic = {}
newObjectDic = {}

for obj in originalObjects:

    #First remove the full path to give us somthing to search the new object with
    subStrLoc = 0
    index = 0
    for char in obj:
        if char == ':':
            subStrLoc = index
        index=index+1

    searchName = obj[subStrLoc+1:]

    originalObjectDic.update({searchName:obj})


    #next look at all the names of the new object and see if they match up    
for nObj in newObjects:
    #correct the new objects name
    subStrLoc=0
    index=0
    for char in nObj:
        if index != 0:
            if char == '_' and nObj[index-1] == 'r' and nObj[index-2] == 'u' and nObj[index-3] == 'F':
                    subStrLoc = index
        index = index + 1  

    if subStrLoc == 0:
        index = 0
        for char in obj:
            if char == ':':
                subStrLoc = index
        index=index+1 

    searchName = nObj[subStrLoc+1:]
    newObjectDic.update({searchName:nObj})   


#now that we have to dicunaries to check agaenst we will match up the two obj paths
# and copy the keys on all attributes on each node

for key in newObjectDic:

    newObjPath = newObjectDic.get(key)
    oldObjPath = originalObjectDic.get(key)
    #if there is a match between the two dics
    if newObjPath != None and oldObjPath != None:
        #get a list of all the attributes
        newObjAttributes = cmds.listAttr(newObjPath,v=True,r=True, w=True)
        oldObjAttributes = cmds.listAttr(oldObjPath,v=True,r=True, w=True)

        for x in range(len(newObjAttributes)-1):
            newAttr = newObjAttributes[x]
            oldAttr = oldObjAttributes[x]
            if cmds.keyframe(oldObjPath attribute=oldAttr,sl=True, q=True, tc=True ) > 0:
                print oldObjPath
                print oldAttr
                print 'Has Key'
                print '----------------------------'

最佳答案

得到了 friend 的帮助。选项选错了。代表选择的 sl 应该是 false 或根本不存在,所以...

if cmds.keyframe(oldObjPath, attribute=oldAttr, sl=False, q=True, tc=True):

关于python - 玛雅Python : Check to see if the attribute has any keyframes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29975922/

相关文章:

python base64转十六进制

python - OpenCV drawMatches函数错误(源类型错误)

python - 从信号交叉点在 pandas 中创建 bool 标志

java - Canvas 双缓冲图形不起作用

3d - 切割表面网格

python - Teradata 和 sqlachemy 连接

c - glPolygonOffset() 不适用于对象轮廓

c - 在沉迷于sdl编程之前我应该​​了解多少c编程

graphics - PBR菲涅尔效应

c# - 我怎么能多边形化一个 bool[,,]