Fix exception in bpy_extras.object_utils.object_data_add(..)

Adding object-data that doesn't support edit-mode would raise an
exception when the "Enter Edit Mode" preferences was enabled.

Other changes:

- Don't attempt to enter edit-mode for library-data.
- Support entering edit-mode for grease-pencil objects.

Alternate fix for the issue raised by D15999.
This commit is contained in:
Campbell Barton 2022-10-06 12:59:26 +11:00
parent 68ea6c85ab
commit 63ed9550e9
1 changed files with 11 additions and 2 deletions

View File

@ -142,8 +142,17 @@ def object_data_add(context, obdata, operator=None, name=None):
bpy.ops.object.mode_set(mode='EDIT')
else:
layer.objects.active = obj_new
if obdata and context.preferences.edit.use_enter_edit_mode:
bpy.ops.object.mode_set(mode='EDIT')
if context.preferences.edit.use_enter_edit_mode:
if obdata and obdata.library is None:
obtype = obj_new.type
mode = None
if obtype in {'ARMATURE', 'CURVE', 'CURVES', 'FONT', 'LATTICE', 'MESH', 'META', 'SURFACE'}:
mode = 'EDIT'
elif obtype == 'GPENCIL':
mode = 'EDIT_GPENCIL'
if mode is not None:
bpy.ops.object.mode_set(mode=mode)
return obj_new