Bpy.data.groups no longer exist?

Hello!

I want to make addons to 2.80. But I have some problems, for examples trying this:

if not obj.name in bpy.data.groups:

Doesn’t work, I get error:
Attribute Error - BlendData object has no attribute groups

Please help to fix.

Groups no longer exist in Blender 2.8. Use collections.

Thanks for the detailed explanation I guess.

Some more details are here:

For your purpose, just renaming groups to collections in the code may work.

Thanks, that did in fact work. But now I’m stuck a few lines later:

https://en.blender.org/index.php/Dev:2.8/Source/LayersCollections/API-Changes
suggests that you have to do now:
bpy.context.scene_collection.objects.link(obj)

But again
Attribute error: 'Context' object has no attribute "scene_collection"

Oh, that’s an outdated page from the old wiki.

It is now bpy.context.collection.objects.link(obj) to add it to the active collection.

This is also true for this?
context.render_layer.objects.active

Where is the up to date wiki?

Thanks a lot for your help.

The most up to date page is here, but it does not document everything yet:
https://wiki.blender.org/wiki/Process/Addons/Guidelines/UpdatingScripts

context.render_layer.objects should be context.view_layer.objects or context.scene.objects depending if you want to look at all the objects in the view layer or the entire scene.

1 Like

Sorry guys, I’m stuck again:
Access (bpy.types)

Now only [Header, Menu, Operator, Panel, UIList] are accessed from bpy.types.

Generally scripts access classes they define by importing their own modules, 
so this should not impact many scripts. 

It does impact mine scripts. Would be great to have more information how to convert this.

E.g.:

# I save  lot of setting here e.g. bpy.context.scene.xy_props.startCount
bpy.types.Scene.xy_props = bpy.props.PointerProperty(type=XYProps)
bpy.types.Scene.finalName = bpy.props.StringProperty()

That script should continue to work. It is only user defined class that will no longer be available through bpy.types.

I get this error
ValueError: bpy_struct "Scene" registration error: xy_props could not register

There must be another cause of the error then, because the access to bpy.types.Scene worked. It’s impossible to tell from that snippet of code though.

There’s another thing maybe you can help:
SpaceView3D object has no attribute viewport_shade

All the settings for 3D viewport shading changed, there is no one to one mapping to the new ones. Just enable Python tooltips and look in the UI for the right properties that you need.

This was popular way to access and change things on viewport windows:

for area in bpy.context.screen.areas: 
        if area.type == 'VIEW_3D':
            for space in area.spaces:
                if space.type == 'VIEW_3D': 
                     #....do a thing 
                     space.viewport_shade = ...

I trie to look up in blender console and tooltips but I cannot lookup this. I really need the help, I have multiple complex scripts for Blender to update and it’s become overwhelming. There’s so many things changed and I don’t know where to look up or documentation. I check the list of SpaceView3D object in the console but viewport_shade is just not there any more.

viewport_shade is now shading.type.

2 Likes

Thanks! This is very helpful for setting keyboard shortcuts for shading type. I am curious, where can you find information for similar changes in the future? Often I’m googling odd bits of python in the hopes that I come across the correct terminology.

Sometimes I can right click the button and the Online Python Reference seems to help, but this time it brought me to a 404 page…