I'm trying to make custom properties per render layer but I get an error. I tried to add a property to bpy.types.SceneRenderLayer and it seems to work. Then I try to make an UIList to show the render layers and that works, but it can't find the prop. I want to make a blender submitter for our render farm and want to have the ability to change things per layer.

The error is:

rna_uiItemR: property not found: SceneRenderLayer.test2

when I print(dir(layer)) for the renderlayer test2 shows up. Here is my code:

import bpy

class RENDER_UL_my_renderlayers(bpy.types.UIList):    
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        layer = item
        row.prop(layer, 'name', text='')
        row.prop(layer, 'test2', text='')
        row.prop(layer, 'use', text = '')

class TEST_PANEL(bpy.types.Panel):
    bl_label = "TEST"
    bl_idname = "RENDER_PT_ui_test"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"

    def draw(self, context):
        layout = self.layout
        col = layout.column()
        col.prop(context.scene, "test1")
        col.template_list('RENDER_UL_my_renderlayers', 'RenderLayers', context.scene.render, 'layers', context.scene, "testindex")

def register():

    bpy.types.Scene.test1 = bpy.props.IntProperty()
    bpy.types.Scene.testindex = bpy.props.IntProperty()
    bpy.types.SceneRenderLayer.test2 = bpy.props.IntProperty()

def unregister():

    del bpy.types.Scene.test1
    del bpy.types.Scene.test2
    del bpy.types.Scene.testindex

if __name__ == "__main__":

SceneRenderLayer cannot be assigned a bpy.props property.

From the docs on property defininitions

Assigning to Existing Classes

Custom properties can be added to any subclass of an ID, Bone and PoseBone.

Run a little check in console using builtin issubclass (don't need to consider bone or pose bone in this case)

# bpy.types.Scene.prop = ...
>>> issubclass(bpy.types.Scene, bpy.types.ID)

# bpy.types.SceneRenderLayer.prop = ...
>> issubclass(bpy.types.SceneRenderLayer, bpy.types.ID)
| improve this answer | |

You must first register the properties and then register the classes.

bpy.types.Scene.test1 = bpy.props.IntProperty()
bpy.types.Scene.testindex = bpy.props.IntProperty()
bpy.types.SceneRenderLayer.test2 = bpy.props.IntProperty()

The reason is that as soon as the derived UIList class and the Panel are registered they are executed and displayed. In your code, since you were defining the custom properties after registering the UI classes, the custom properties were not defined yet at the time of drawing of the layer properties.

| improve this answer | |
  • 1
    $\begingroup$ Still get the same error :( In both cases the test1 property show up but not test2 $\endgroup$ – Simon Rainerson Jul 26 '17 at 11:52
  • 1
    $\begingroup$ Hmm can't find test2 in the outliner/datablocks either. Test1 is where it should be. bpy.data.scenes[0].render.layers[0].test2 gives me (<built-in function IntProperty>, {}). Which is odd, py.data.scenes[0].test1 gives 0. So I guess I'm adding test2 in the wrong way or on the wrong thing. $\endgroup$ – Simon Rainerson Jul 26 '17 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.