在 Maya 中使用 Python 过滤列表/列表条件

Filtering Lists / Conditions on Lists with Python in Maya

我是 python 的新手,在花了很多时间尝试解决问题后,我很迷茫,所以我想在这里问我的第一个问题。

我在 Maya 中有一个带有引用文件的主文件,我试图在其中列出某个节点的连接,源在引用文件中,目标在主文件中

import pymel.core

# get relevant list:
aSourceNodeCC = cmds.ls ("ShaderReference:CC*")

# source details
for eSourceNodeCC in aSourceNodeCC:
    
    # destination details
    if cmds.connectionInfo ('%s.outColor' % eSourceNodeCC, destinationFromSource = 1) is not None:  
        aConnectionCC = cmds.connectionInfo ('%s.outColor' % eSourceNodeCC, destinationFromSource = 1)

        # list generation
        for eConnectionCC in aConnectionCC:
            aConnectionCCMaster = eSourceNodeCC + ('.outColor ') + eConnectionCC
            print aConnectionCCMaster

我遇到的问题是 CC* 节点有时在引用文件和主文件中都有连接。我只需要到主文件的连接,并且正在努力过滤掉那些连接到引用文件中其他节点的连接。即我需要保留如下所示的条目:

着色器参考:CC_white.outColor SS_white_custom.baseColor

但需要排除如下条目:

ShaderReference:CC_white.outcolor ShaderReference:SS_white_custom.baseColor

非常感谢任何帮助。谢谢

试试这个:

# list generation
    for eConnectionCC in aConnectionCC:

        # check if ref
        if cmds.referenceQuery(eConnectionCC, isNodeReferenced=True):
            continue

        aConnectionCCMaster = eSourceNodeCC + ('.outColor ') + eConnectionCC
        print aConnectionCCMaster