Skip to content

Commit

Permalink
0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
docentYT committed Jun 8, 2022
1 parent 6480c22 commit 7816ab5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
48 changes: 46 additions & 2 deletions Blender simple tools.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
bl_info = {
"name": "Blender simple tools",
"description": "Simple functions that will make your life easier.",
"version": (0,1),
"version": (0,2),
"blender": (3, 1, 0),
"category": "Object",
"author": "Christopher Kwiatkowski (kwiatek_123)"
}

import bpy
import os

class JoinLinkedMaterials(bpy.types.Operator):
"""Joining selected objects by the same material on scene."""
Expand Down Expand Up @@ -37,14 +38,57 @@ def execute(self, context):

return {'FINISHED'}

class JoinByNames(bpy.types.Operator):
"""Joining selected objects by the same name with blender's .001, .002 etc."""
bl_idname = "object.join_by_names"
bl_label = "Join objects by the same names"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
object_names = [ob.name for ob in bpy.context.selected_objects]

if not object_names:
self.report({'ERROR_INVALID_INPUT'}, "Please select objects to join.")
return {'FINISHED'}

objs = sorted([x for x in bpy.context.selected_editable_objects if x.type == 'MESH'],
key = lambda x: x.name)

obj_names_stripped = [os.path.splitext(x.name)[0] for x in objs]

bpy.ops.object.select_all(action='DESELECT')
for i, obj_name in enumerate(obj_names_stripped):
# check for i=0 to skip the very first item
if i != 0:
# check if the current item has the same name when stripped
# than the previous item
if obj_name == obj_names_stripped[i-1]:
objs[i].select_set(True)
else:
bpy.ops.object.join()
bpy.ops.object.select_all(action='DESELECT')
objs[i].select_set(True)
context.view_layer.objects.active = bpy.data.objects.get(objs[i].name)
else:
objs[i].select_set(True)
context.view_layer.objects.active = bpy.data.objects.get(objs[i].name)

bpy.ops.object.join()
return {'FINISHED'}

def menu_func(self, context):
self.layout.operator(JoinLinkedMaterials.bl_idname)
self.layout.operator(JoinByNames.bl_idname)

def register():
bpy.utils.register_class(JoinLinkedMaterials)
bpy.utils.register_class(JoinByNames)
bpy.types.VIEW3D_MT_object.append(menu_func)

def unregister():
bpy.utils.unregister_class(JoinLinkedMaterials)
bpy.types.VIEW3D_MT_object.remove(menu_func)
bpy.utils.unregister_class(JoinByNames)
bpy.types.VIEW3D_MT_object.remove(menu_func)

#if __name__ == "__main__":
# register()
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ This function joins all selected objects with other objects with the same materi
<li>Object -> Join objects by linked materials **or** F3 -> Join objects by linked materials</li>
</ol>

## Join objects by the same name with blender's .001, .002 etc.
### Description
This function joins all selected objects with other objects with the same name before blender's .001, .002 etc.
### How to use
<ol>
<li>Select the objects on which you want to perform the operation.</li>
<li>Object -> Join objects by the same names **or** F3 -> Join objects by the same names</li>
</ol>

# More functions
Feel free to open a new "issue" and describe the new functionality that you would like to see in a future version.

0 comments on commit 7816ab5

Please sign in to comment.