Problem updating my script to 2.77 (object has no attribute 'layers')

Hi all,

I try to make my House Primitive script work on 2.77.
When I install and test it, at the creation time, console says:


  File "/home/tmaes/.config/blender/2.77/scripts/addons/ArToKi_House.py", line 218, in execute
    object_utils.object_data_add(context, mesh, operator=self)
  File "/home/tmaes/Applications/blender-2.77-4af287f-linux-glibc219-x86_64/2.77/scripts/modules/bpy_extras/object_utils.py", line 140, in object_data_add
    if operator is not None and any(operator.layers):
  File "/home/tmaes/Applications/blender-2.77-4af287f-linux-glibc219-x86_64/2.77/scripts/modules/bpy_types.py", line 598, in __getattribute__
    return super().__getattribute__(attr)
AttributeError: 'AddHouse' object has no attribute 'layers'

So I searched th API and found this page: https://www.blender.org/api/blender_python_api_2_77_0/bpy_extras.object_utils.html
Where I can see that object_data_add has a new(?) parameter called use_active_layer (that is not documented below).
If I use it, and put use_active_layer=TRUE in the line concerned (218) the bug remains almost the same, asking for a ‘layer’ attribute.

Am I wrong working on line 218?

Thanks in advance (at least for reading), I put the script code (working till 2.67) in attachment.
ArToKi_House.zip (3.53 KB)

tmaes

hi, this commit here should help: do the same in your addon:
https://developer.blender.org/rB0f63ce61c52fce82f18df687369d513c3b6c19b1

Thank you, I’ll try now!

Best regards.

Edit:

It works well!
Now at creation time, in the object options, I have a list of 20 layers checkboxes.
Sorry for my laziness but maybe you have an idea on the way to display it a better way (like in the 3d view by example).

Thanks again.

hi Again! It seems the template is wrong so here’s the correct code:

layers = BoolVectorProperty(
        name="Layers",
        size=20,
        subtype='LAYER',
        options={'HIDDEN', 'SKIP_SAVE'},
        )

thank you again!

the subtype is what I was looking for.
I didn’t need the hidden option but it’s useful to know where to pass the options.

Best regards,

tmaes