Skip to main content
 首页 » 编程设计

python之通过 Alembic SceneGraph 重命名 ReadGeo 节点

2024年12月31日8lhb25

我有 7 个镜头,每个镜头有 2 或 3 个 Alembic 文件,每个 Alembic 大约有 20 个几何图形。

因为我需要在新的 Alembic 中导出完整的 3D 场景,所以我需要重命名所有 ReadGeo 节点,以便在其他软件(如 Maya)中轻松读取。

为此,我想将 Alembic Scenegraph 中的几何名称提供给 ReadGeo,但我不知道如何找到 Geo 用 Python 命名。我从这段代码开始:

def AlembicRename(): 
    for s in nuke.allNodes("ReadGeo2"): 
        GeoName = # don't know how to find this 
        s['name'].setValue(GeoName) 
 
AlembicRename() 

知道如何找到 Geometry 名称吗?

谢谢。

请您参考如下方法:

要在 NUKE 中访问 ABC 的场景图形层次结构,您应该尝试以下代码:

import nuke 
 
# 'ReadGeo2' – node's class  
nuke.createNode('ReadGeo2', 'file { /Users/swift/Desktop/scene.abc }')  
 
def alembicRename(): 
    # 'ReadGeo18' – node's name in graph  
    for s in nuke.allNodes('ReadGeo18'): 
        sceneView = s['scene_view'] 
        hierarchy = sceneView.getAllItems() 
        print hierarchy 
 
alembicRename() 
 
# Result: ['/root/polySphere/polySphereShape'] 

要了解如何使用 Python 从字符串中提取子字符串,请阅读 This Post .在提取过程之后,您可以将(例如,polySphere)名称分配给您的 ReadGeo 节点。不要忘记:有一个仅包含零索引的 Python 列表。

s['name'].setValue(hierarchy[0])