Search code examples
pythonblenderbpy

Get inner nodes in Blender Frame Node


I want to parse Cycles shader to my Game Engine. I have frame which is input for GLSL shader in engine: enter image description here I'd like to iterate over each of nodes inside the frame. How? I haven't found anything in: https://www.blender.org/api/blender_python_api_2_78a_release/bpy.types.NodeFrame.html?highlight=frame#bpy.types.NodeFrame


Solution

  • A frame node doesn't keep a list of it's contents but each frame knows who it's parent is. Keeping with blender terminology used elsewhere, a frame node is the parent of nodes that are inside it.

    To get a list of frame contents, you can iterate over the node tree and find nodes that have the frame as a parent.

    import bpy
    
    mat_nodes = bpy.data.materials['Material'].node_tree.nodes
    frame_node = mat_nodes['Frame']
    
    frame_children = []
    for n in mat_nodes:
        if n.parent == frame_node:
            frame_children += [n]