Skip to content

Commit

Permalink
Updated for Blender 4.0 new method of overriding context
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimNyan committed Feb 21, 2024
1 parent 4805398 commit 34632ad
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
6 changes: 4 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
bl_info = {
"name": "Fuse Skeletons",
"author": "Anime Nyan",
"version": (1, 0, 2),
"version": (1, 1, 0),
"blender": (2, 92, 0),
"location": "3D View > Properties > Fuse Skel",
"description": "Adds ability to join selected Skeletons together, delete duplicate bones with the same name and reparent bones which are not duplicates to bones to the original skeleton.",
Expand All @@ -27,7 +27,9 @@
}

"""
Version': '1.0.1' written by Anime Nyan
Version': '1.1.0' written by Anime Nyan
Updated for Blender 4.0
Adds one panel in the 3d View to join Skeletons together, delete duplicate bones with the same name and reparent bones which are not duplicates to bones to the original skeleton.
"""
Expand Down
60 changes: 34 additions & 26 deletions fuse_skeletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,41 @@ def execute(self, context):
#which can only be done in object mode
bpy.ops.object.mode_set(mode='OBJECT')

#If you use a copy of the context, you can change some attributes
#and pass it to an operator without affecting the actual context
#this is much faster for performance
#because blender does not need to update the scene every time if
#join is called in a loop
#also it keeps the currently selected objects intact
ctx = bpy.context.copy()

#Make the active object
#one of the objects to join
#otherwise when trying to join it won't know which
#skeleton to join to
#set the copy of the context's active object
#to the current context's active object
#this is because when joining skeletons it is the active object
#that is the skeleton every other skeleton is joined to
ctx['active_object'] = active_object

ctx['selected_objects'] = armatures

# In Blender 2.8x this needs to be the following instead:
ctx['selected_editable_objects'] = armatures
#debug
#print("armatures before join:", armatures)
#print("ctx['selected_editable_objects'] before join:", ctx['selected_editable_objects'])

bpy.ops.object.join(ctx)

#--------------THESE METHODS ARE ALL DEPRECATED IN BLENDER 4.0 new method of overriding context
# #If you use a copy of the context, you can change some attributes
# #and pass it to an operator without affecting the actual context
# #this is much faster for performance
# #because blender does not need to update the scene every time if
# #join is called in a loop
# #also it keeps the currently selected objects intact
# ctx = bpy.context.copy()

# #Make the active object
# #one of the objects to join
# #otherwise when trying to join it won't know which
# #skeleton to join to
# #set the copy of the context's active object
# #to the current context's active object
# #this is because when joining skeletons it is the active object
# #that is the skeleton every other skeleton is joined to
# ctx['active_object'] = active_object

# ctx['selected_objects'] = armatures

# # In Blender 2.8x this needs to be the following instead:
# ctx['selected_editable_objects'] = armatures
# #debug
# #print("armatures before join:", armatures)
# #print("ctx['selected_editable_objects'] before join:", ctx['selected_editable_objects'])

# bpy.ops.object.join(ctx)

with context.temp_override(active_object=active_object, selected_objects=armatures, selected_editable_objects=armatures):
bpy.ops.object.join()


#debug
#joined armatures will become <bpy_struct, Object invalid>
#in the list
Expand Down

0 comments on commit 34632ad

Please sign in to comment.