# Python Join Same Name function

I'm getting this error and am not quite sure how to fix it

Please see below for my code....

def execute(self, context):
for obj in bpy.context.selected_objects:
charlen = 15
namestore_1 = obj.name[:charlen]
bpy.context.scene.objects.active = obj
for ob in bpy.context.scene.objects:
namestore_2 = ob.name[:charlen]
if ob.type == 'MESH':
if str(namestore_1) == (namestore_2):
ob.select = True
else:
ob.select = False
for selected in bpy.context.selected_objects:
if selected.type == 'MESH':
bpy.ops.object.join()


Thanks in advance for any help :) this ones been bugging me for a while!

[edit - updated code slightly for variable in place of number where the character lenght is involved]

• I think you're messing up with the "selected_objects" when you start de-selecting objects in your nested loop. What are you trying to achieve here? Perhaps if you describe the logic of what you're aiming for, we can find the right algorithm to achieve it. – TLousky Jul 24 '17 at 14:33
• Hi,Thanks very much for your response. Im trying to make addon that automatically joins objects of similar names. (i.e. all glass objects in the scene) for a few reasons. Most important of which is that it means that materials are easier to work with (in my case). So the process is as follows, user clicks on the object, then hits the button and all the objects with similar names are selected and joined. I should have mentioned that currently the addon does it's job - but the error message keeps coming up anyway! I just wanted to get rid of the error message really. – dood Jul 25 '17 at 2:27

An operator's execute(), invoke() or modal() methods must return a status as a set(). Also note that the return result must be one of {'RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH', ‘INTERFACE’}
The shortcut to creating a set is to wrap the item in curly braces {}.
def execute(self, context):

• @dood The error is incompatible return value which is because you don't return a result (at least not in the code you shared). You could also do return bpy.ops.object.join() – sambler Jul 25 '17 at 10:27