Skip to content

Commit d985775

Browse files
committed
Improved helper methods
1 parent c47776e commit d985775

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

helper.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ def focus_on_object(obj, edit=False):
3333

3434
def remove_object(obj):
3535
if (obj):
36-
data = obj.data
37-
type = obj.type
36+
try:
37+
data = obj.data
38+
type = obj.type
39+
except:
40+
return
3841
bpy.data.objects.remove(obj, do_unlink=True, do_id_user=True)
3942
if hasattr(data, "users"):
4043
if data.users == 0:
@@ -43,10 +46,12 @@ def remove_object(obj):
4346
elif (type in ['CURVE', 'FONT']):
4447
bpy.data.curves.remove(data, do_unlink=True, do_id_user=True)
4548

46-
def apply_all_modifiers():
47-
obj = bpy.context.active_object
48-
while(obj.modifiers):
49-
bpy.ops.object.modifier_apply(modifier=obj.modifiers[0].name)
49+
def apply_all_modifiers(object):
50+
if (object):
51+
if (object.name in bpy.context.view_layer.objects):
52+
bpy.context.view_layer.objects.active = object
53+
while(object.modifiers):
54+
bpy.ops.object.modifier_apply(modifier=object.modifiers[0].name)
5055

5156
def get_override(active=None, edit=False, selected=[], type='VIEW_3D'):
5257
override = bpy.context.copy()

0 commit comments

Comments
 (0)