How to find the non inherited attributes of an object whose attributes were dynamically created from C?

I’m trying to find all of the non-inherited attributes of a compositor mix rgb node (api page), and have the below code, but I’m not getting the results I expected.

using dir() returns attributes of all ancestors as well as the current type. How can I find those that are declared only in the CompositorNodeMixRGB class (‘use_alpha’, ‘blend_type’ and ‘use_clamp’) ?


import types
def get_non_inherited_props(scene_name,node_name):
    scene = bpy.data.scenes[scene_name]
    nodes = scene.node_tree.nodes
    node = nodes[node_name]
    print('\nresult from dir()\n')
    print(dir(node))
    print('\nresult from __dict__\n')
    for name,item in type(node).__dict__.items():
        print(name)

results:

result from dir()

['__doc__', '__module__', '__slots__', 'bl_description', 'bl_height_default', 'bl_height_max', 'bl_height_min', 'bl_icon', 'bl_idname', 'bl_label', 'bl_rna', 'bl_static_type', 'bl_width_default', 'bl_width_max', 'bl_width_min', 'blend_type', 'color', 'dimensions', 'draw_buttons', 'draw_buttons_ext', 'height', 'hide', 'input_template', 'inputs', 'internal_links', 'is_registered_node_type', 'label', 'location', 'mute', 'name', 'output_template', 'outputs', 'parent', 'poll', 'poll_instance', 'rna_type', 'select', 'show_options', 'show_preview', 'show_texture', 'socket_value_update', 'tag_need_exec', 'type', 'update', 'use_alpha', 'use_clamp', 'use_custom_color', 'width', 'width_hidden']


result from __dict__

__module__
__slots__
__doc__
bl_rna
is_registered_node_type
input_template
output_template

Should that be node.__dict__.items() instead of type(node).__dict__... ?

I thought that, but it returns node has not attribute '__dict__'

There may be a more elegant way, but you can get the attributes of both the class and base class, and then compute the difference.

I thought that, but the attributes in the class and the attributes in the object seem to not match up. I think they’re generated dynamically, so don’t appear in the any of the base classes, only in the object.

Try:

set(bpy.types.CompositorNodeMixRGB.bl_rna.properties.keys()) - set(bpy.types.CompositorNode.bl_rna.properties.keys())
2 Likes

Brecht, this is why you’re a legend. Thanks.

solution:

def brecht_is_a_legend(scene_name,node_name):
    scene = bpy.data.scenes[scene_name]
    nodes = scene.node_tree.nodes  
    node = nodes[node_name]
    node_type = type(node)
    bases = node_type.__mro__
    print(set(node_type.bl_rna.properties.keys()) - set(bases[1].bl_rna.properties.keys()))