1
$\begingroup$

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=layout.row()
        print(dir(layer))
        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.utils.register_class(RENDER_UL_my_renderlayers)
    bpy.utils.register_class(TEST_PANEL)

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

def unregister():
    bpy.utils.unregister_class(RENDER_UL_my_renderlayers)
    bpy.utils.unregister_class(TEST_PANEL)

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


if __name__ == "__main__":
    register()
$\endgroup$

2 Answers 2

1
$\begingroup$

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)
True

# bpy.types.SceneRenderLayer.prop = ...
>> issubclass(bpy.types.SceneRenderLayer, bpy.types.ID)
False
$\endgroup$
0
$\begingroup$

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()
bpy.utils.register_class(RENDER_UL_my_renderlayers)
bpy.utils.register_class(TEST_PANEL)

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.

$\endgroup$
2
  • 1
    $\begingroup$ Still get the same error :( In both cases the test1 property show up but not test2 $\endgroup$ Jul 26, 2017 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$ Jul 26, 2017 at 12:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .