2

I have 7 shots with 2 or 3 Alembic files in each and around 20 geometries per Alembic.

As I need to export my complete 3D scene in a new Alembic, I need to rename all of the ReadGeo nodes to be easily readable in other software (like Maya).

For this, I want to give the geometry name from the Alembic Scenegraph to the ReadGeo but I don't see how to found Geo name with Python. I have started with this code:

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

AlembicRename()

Any idea how I can find the Geometry Name?

Thank you.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
William Eguienta
  • 135
  • 1
  • 13

2 Answers2

1

To access ABC's Scenegraph's hierarchy in NUKE, you should try this code:

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']

To find out how to extract a substring from inside a string using Python read This Post. After extracting process you can assign (polySphere, for example) name to your ReadGeo node. And do not forget: there is a Python's list containing only zero index.

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

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    thank you, i have founded the same principle but with myReadGeoNode['scene_view'].getSelectedItems(), then i can isolate the wanted geometry – William Eguienta Aug 12 '18 at 08:03
  • hi, yes because it's not the right name, I needed to have only selected geo name so the command i was looking for is getSelectedItems() then separate each / to have the real geo name in the last entry – William Eguienta Aug 13 '18 at 05:06
  • In case you have several groups of geometry inside compound multilayered hierarchy, `.getAllItems()` nuke method + `substring extraction` operation are more robust and reliable than just `.getSelectedItems()` method. – Andy Jazz Aug 13 '18 at 06:30
  • hi, can you explain why please ? – William Eguienta Aug 13 '18 at 06:32
  • Hi)) You might have a compound geometry, not mono. So, definite layer in DAG's hierarchy has all the parts of your object but `.getSelectedItems()` may not select all the desired parts of geometry. In simple cases `.getSelectedItems()` method is quite useful. – Andy Jazz Aug 13 '18 at 07:07
  • That's why I prefer using `.getAllItems()` and `substring extraction`, not the `.getSelectedItems()`. – Andy Jazz Aug 13 '18 at 07:14
-1

Solved with

myReadGeoNode['scene_view'].getSelectedItems()
William Eguienta
  • 135
  • 1
  • 13