Skip to content

Commit

Permalink
fix: add additional checks to all operator poll methods to avoid sele…
Browse files Browse the repository at this point in the history
…ction (and order) based errors
  • Loading branch information
tristan-hm committed Apr 22, 2022
1 parent 83a080e commit cfdde4c
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion booleans/boolean_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ND_OT_bool_slice(bpy.types.Operator):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 2
return len(context.selected_objects) == 2 and all(obj.type == 'MESH' for obj in context.selected_objects)


def execute(self, context):
Expand Down
2 changes: 1 addition & 1 deletion booleans/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ND_OT_bool_vanilla(bpy.types.Operator):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 2
return len(context.selected_objects) == 2 and all(obj.type == 'MESH' for obj in context.selected_objects)


def execute(self, context):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/array_cubed.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
9 changes: 7 additions & 2 deletions power_mods/circular_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ def invoke(self, context, event):

@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 2
if context.mode == 'OBJECT' and len(context.selected_objects) == 2:
a, b = context.selected_objects
reference_obj = a if a.name != context.object.name else b

return reference_obj.type == 'MESH'
else:
return False


def add_array_modifier(self):
Expand Down
9 changes: 8 additions & 1 deletion power_mods/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) > 0 and len(context.selected_objects) <= 2
if len(context.selected_objects) == 1 and context.object.type == 'MESH':
return True

if len(context.selected_objects) == 2:
a, b = context.selected_objects
reference_obj = a if a.name != context.object.name else b

return reference_obj.type == 'MESH'


def add_mirror_modifier(self):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/profile_extrude.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/screw.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/solidify.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/square_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
2 changes: 1 addition & 1 deletion power_mods/weighted_normal_bevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def prepare_new_operator(self, context):
Expand Down
2 changes: 1 addition & 1 deletion sketching/geo_lift.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def register_mode(self):
Expand Down
2 changes: 1 addition & 1 deletion sketching/view_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def set_selection_mode(self, context):
Expand Down
2 changes: 1 addition & 1 deletion utils/hydrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def operate(self, context):
Expand Down
3 changes: 2 additions & 1 deletion utils/name_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class ND_OT_name_sync(bpy.types.Operator):

@classmethod
def poll(cls, context):
return len(context.selected_objects) >= 1
if context.mode == 'OBJECT':
return len(context.selected_objects) >= 1 and all(obj.type == 'MESH' for obj in context.selected_objects)


def execute(self, context):
Expand Down
2 changes: 1 addition & 1 deletion utils/seams.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def operate(self, context):
Expand Down
3 changes: 2 additions & 1 deletion utils/set_lod_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ND_OT_set_lod_suffix(bpy.types.Operator):

@classmethod
def poll(cls, context):
return len(context.selected_objects) >= 1
if context.mode == 'OBJECT':
return len(context.selected_objects) >= 1 and all(obj.type == 'MESH' for obj in context.selected_objects)


def execute(self, context):
Expand Down
7 changes: 5 additions & 2 deletions utils/set_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ class ND_OT_set_origin(bpy.types.Operator):

@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 2
if context.mode == 'OBJECT' and len(context.selected_objects) == 2:
a, b = context.selected_objects
reference_obj = a if a.name != context.object.name else b

return reference_obj.type == 'MESH'


def execute(self, context):
Expand Down
2 changes: 1 addition & 1 deletion utils/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def invoke(self, context, event):
@classmethod
def poll(cls, context):
if context.mode == 'OBJECT':
return len(context.selected_objects) == 1
return len(context.selected_objects) == 1 and context.object.type == 'MESH'


def add_smooth_shading(self, context):
Expand Down

0 comments on commit cfdde4c

Please sign in to comment.