Hi,
In my addon, I have a button that I use to do the join function.
The code below works fine. However, it seems long and clunky.
Is there a better way to do this. I spent a couple of hours to get to this point.
Here is what the button is supposed to do in the @poll section of code…
It only enables the button if all the selected objects are the same, i.e all MESH or all CURVES.
If it detects that there are two different types it will not enable the button.
CODE THAT WORKS:
class SELJOIN_OT_Operator(bpy.types.Operator):
bl_idname = "viewed3d.select_join"
bl_label = "Join Selected Objects"
bl_description = "Join Selected Objects"
@classmethod
def poll(cls, context):
obj = context.active_object
objs = context.selected_objects
if len(objs) == 0: return False
#selection_names = []
strType = "none"
boolFirst = False
boolTF = False
for objs in bpy.context.selected_objects:
#gets the firs obj intance
if boolFirst == False:
boolFirst = True
if obj.mode == "OBJECT":
if objs.type == "MESH":
strType = "MESH"
elif objs.type == "CURVE":
strType = "CURVE"
elif objs.type == "GPENCIL":
strType = "GPENCIL"
elif objs.type == "SURFACE":
strType = "SURFACE"
elif objs.type == "ARMATURE":
strType = "ARMATURE"
else:
print("no valid object selected")
else:
#checks if there is a match or not
if obj.mode == "OBJECT":
if objs.type == strType:
boolTF = True
else:
boolTF = False
break
#if T/F, then return T/F
if boolTF == True:
return True
else:
return False
return False
def execute(self, context):
bpy.ops.object.join()
return {'FINISHED'}
Can this be done more effciently?
Thanks in advanced.