From 2768161bc0d210e84a569b0e46d5658395424d36 Mon Sep 17 00:00:00 2001 From: Tristan Strathearn Date: Fri, 12 Jul 2024 20:34:40 +1000 Subject: [PATCH] fix: fix Blender version polling --- bevels/bevel.py | 4 ++-- bevels/edge_bevel.py | 14 +++++++------- bevels/vertex_bevel.py | 4 ++-- booleans/hydrate.py | 4 ++-- deform/lattice.py | 4 ++-- extrusion/profile_extrude.py | 4 ++-- extrusion/screw.py | 4 ++-- extrusion/solidify.py | 4 ++-- lib/axis.py | 3 ++- lib/modifiers.py | 23 ++++++++++++----------- lib/objects.py | 5 +++-- lib/overlay.py | 23 ++++++++++++----------- lib/points.py | 3 ++- lib/polling.py | 5 +++++ packaging/seams.py | 4 ++-- packaging/triangulate.py | 4 ++-- replicate/mirror.py | 4 ++-- scene/clean_utils.py | 4 ++-- shading/smooth.py | 10 +++++----- shading/wn.py | 4 ++-- sketch/circularize.py | 4 ++-- standalone/cycle.py | 4 ++-- utils/apply_modifiers.py | 10 +++++----- 23 files changed, 81 insertions(+), 71 deletions(-) diff --git a/bevels/bevel.py b/bevels/bevel.py index 271da12..365bb0c 100644 --- a/bevels/bevel.py +++ b/bevels/bevel.py @@ -35,7 +35,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, set_stream, has_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, add_smooth_by_angle, rectify_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_obj_mode, obj_exists, obj_is_mesh +from .. lib.polling import ctx_obj_mode, obj_exists, obj_is_mesh, app_minor_version mod_bevel = "Bevel — ND B" @@ -277,7 +277,7 @@ def add_smooth_shading(self, context): if not get_preferences().enable_auto_smooth: return - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): add_smooth_by_angle(self.target_object) return diff --git a/bevels/edge_bevel.py b/bevels/edge_bevel.py index 4999008..7de37a5 100644 --- a/bevels/edge_bevel.py +++ b/bevels/edge_bevel.py @@ -35,7 +35,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_edit_mode, obj_edges_selected, obj_is_mesh +from .. lib.polling import ctx_edit_mode, obj_edges_selected, obj_is_mesh, app_minor_version mod_bevel = "Bevel — ND EB" @@ -181,7 +181,7 @@ def do_invoke(self, context, event): bevel_weight_layer = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bevel_weight_layer = bm.edges.layers.bevel_weight.verify() else: bevel_weight_layer = bm.edges.layers.float.get("bevel_weight_edge", None) @@ -212,7 +212,7 @@ def do_invoke(self, context, event): self.target_object = context.active_object - if bpy.app.version < (3, 4, 0): + if app_minor_version() < (3, 4): if not self.target_object.data.use_customdata_edge_bevel: self.target_object.data.use_customdata_edge_bevel = True @@ -278,7 +278,7 @@ def add_smooth_shading(self, context): if not get_preferences().enable_auto_smooth: return - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): bpy.ops.object.mode_set(mode='OBJECT') add_smooth_by_angle(self.target_object) bpy.ops.object.mode_set(mode='EDIT') @@ -331,7 +331,7 @@ def take_edges_snapshot(self, context): bevel_weight_layer = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bevel_weight_layer = bm.edges.layers.bevel_weight.verify() else: bevel_weight_layer = bm.edges.layers.float.get("bevel_weight_edge", None) @@ -358,7 +358,7 @@ def operate(self, context): bevel_weight_layer = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bevel_weight_layer = bm.edges.layers.bevel_weight.verify() else: bevel_weight_layer = bm.edges.layers.float.get("bevel_weight_edge", None) @@ -403,7 +403,7 @@ def revert(self, context): bevel_weight_layer = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bevel_weight_layer = bm.edges.layers.bevel_weight.verify() else: bevel_weight_layer = bm.edges.layers.float.get("bevel_weight_edge", None) diff --git a/bevels/vertex_bevel.py b/bevels/vertex_bevel.py index cc85bcb..dc3652e 100644 --- a/bevels/vertex_bevel.py +++ b/bevels/vertex_bevel.py @@ -35,7 +35,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_edit_mode, obj_is_mesh, obj_verts_selected +from .. lib.polling import ctx_edit_mode, obj_is_mesh, obj_verts_selected, app_minor_version mod_bevel = "Bevel — ND VB" @@ -261,7 +261,7 @@ def add_smooth_shading(self, context): if not get_preferences().enable_auto_smooth: return - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): bpy.ops.object.mode_set(mode='OBJECT') add_smooth_by_angle(self.target_object) bpy.ops.object.mode_set(mode='EDIT') diff --git a/booleans/hydrate.py b/booleans/hydrate.py index 54dde83..720c2ab 100644 --- a/booleans/hydrate.py +++ b/booleans/hydrate.py @@ -31,7 +31,7 @@ from .. lib.overlay import update_overlay, init_overlay, toggle_pin_overlay, toggle_operator_passthrough, register_draw_handler, unregister_draw_handler, draw_header, draw_property, draw_hint from .. lib.events import capture_modifier_keys, pressed from .. lib.preferences import get_preferences -from .. lib.polling import ctx_obj_mode, list_ok +from .. lib.polling import ctx_obj_mode, list_ok, app_minor_version class ND_OT_hydrate(BaseOperator): @@ -130,7 +130,7 @@ def finish(self, context): new_obj.select_set(True) bpy.context.view_layer.objects.active = new_obj - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.parent_clear({'object': new_obj}, type='CLEAR_KEEP_TRANSFORM') else: with bpy.context.temp_override(object=new_obj): diff --git a/deform/lattice.py b/deform/lattice.py index be55a34..1f2cda9 100644 --- a/deform/lattice.py +++ b/deform/lattice.py @@ -36,7 +36,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected +from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected, app_minor_version mod_lattice = "Lattice — ND L" @@ -293,7 +293,7 @@ def add_lattice_object(self, context): context.active_object.data.name = "ND — Lattice" context.active_object.data.use_outside = True - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): context.active_object.scale = eval_obj.dimensions * 1.001 else: context.active_object.dimensions = eval_obj.dimensions * 1.001 diff --git a/extrusion/profile_extrude.py b/extrusion/profile_extrude.py index 23634cd..383b143 100644 --- a/extrusion/profile_extrude.py +++ b/extrusion/profile_extrude.py @@ -36,7 +36,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_multi_mode, obj_is_mesh, ctx_objects_selected +from .. lib.polling import ctx_multi_mode, obj_is_mesh, ctx_objects_selected, app_minor_version mod_screw = "Extrusion — ND PE" @@ -230,7 +230,7 @@ def add_smooth_shading(self, context): bpy.ops.object.mode_set(mode='OBJECT') return_to_edit = True - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): add_smooth_by_angle(self.target_object) if return_to_edit: bpy.ops.object.mode_set(mode='EDIT') diff --git a/extrusion/screw.py b/extrusion/screw.py index f8f57ff..17787a8 100644 --- a/extrusion/screw.py +++ b/extrusion/screw.py @@ -36,7 +36,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, add_smooth_by_angle, rectify_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_multi_mode, obj_moddable, ctx_objects_selected +from .. lib.polling import ctx_multi_mode, obj_moddable, ctx_objects_selected, app_minor_version mod_displace = "Offset — ND SCR" @@ -246,7 +246,7 @@ def add_smooth_shading(self, context): bpy.ops.object.mode_set(mode='OBJECT') return_to_edit = True - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): add_smooth_by_angle(self.target_object) if return_to_edit: bpy.ops.object.mode_set(mode='EDIT') diff --git a/extrusion/solidify.py b/extrusion/solidify.py index 95974bb..752aaf6 100644 --- a/extrusion/solidify.py +++ b/extrusion/solidify.py @@ -35,7 +35,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected +from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected, app_minor_version mod_displace = "Offset — ND SOL" @@ -192,7 +192,7 @@ def add_smooth_shading(self, context): if not get_preferences().enable_auto_smooth: return - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): add_smooth_by_angle(self.target_object) return diff --git a/lib/axis.py b/lib/axis.py index d12c5b8..a39d3ac 100644 --- a/lib/axis.py +++ b/lib/axis.py @@ -30,6 +30,7 @@ from mathutils import Vector, Matrix from gpu_extras.batch import batch_for_shader from . preferences import get_preferences +from . polling import app_minor_version def register_axis_handler(cls): @@ -98,7 +99,7 @@ def update_axis(cls): shader = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') else: shader = gpu.shader.from_builtin('UNIFORM_COLOR') diff --git a/lib/modifiers.py b/lib/modifiers.py index 0f57472..46ac463 100644 --- a/lib/modifiers.py +++ b/lib/modifiers.py @@ -28,7 +28,8 @@ import bpy import re from math import radians -from .. lib.preferences import get_preferences +from . preferences import get_preferences +from . polling import app_minor_version def new_modifier(object, mod_name, mod_type, rectify=True): @@ -80,7 +81,7 @@ def rectify_mod_order(object, mod_name): if matching_mod_index is None: return - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_move_to_index({'object': object}, modifier=mod_name, index=matching_mod_index) else: with bpy.context.temp_override(object=object): @@ -100,7 +101,7 @@ def has_sba_mod(object): def add_smooth_by_angle(object): - if bpy.app.version < (4, 1, 0): + if app_minor_version() < (4, 1): return if has_sba_mod(object): @@ -109,12 +110,12 @@ def add_smooth_by_angle(object): with bpy.context.temp_override(object=object): sba_node_group = bpy.data.node_groups.get("Smooth by Angle") - if sba_node_group == None and bpy.app.version == (4, 1, 0): + if sba_node_group == None and app_minor_version() == (4, 1): bpy.ops.object.shade_smooth() bpy.ops.object.modifier_add_node_group(asset_library_type='ESSENTIALS', asset_library_identifier="", relative_asset_identifier="geometry_nodes\\smooth_by_angle.blend\\NodeTree\\Smooth by Angle") - if sba_node_group == None and bpy.app.version > (4, 1, 0): + if sba_node_group == None and app_minor_version() > (4, 1): bpy.ops.object.shade_auto_smooth() sba_mod = None @@ -122,9 +123,9 @@ def add_smooth_by_angle(object): if sba_node_group != None: sba_mod = object.modifiers.new("Smooth — ND SBA", 'NODES') sba_mod.node_group = sba_node_group - if bpy.app.version > (4, 1, 0): + if app_minor_version() > (4, 1): sba_mod.use_pin_to_last = True - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): sba_mod.show_group_selector = False # It isn't pretty, but it's the only way to get the modifier as modifier_add_node_group/shade_auto_smooth @@ -168,7 +169,7 @@ def set_smoothing_angle(object, angle, ignore_sharpness=False): def rectify_smooth_by_angle(object, force=False): # For Blender 4.1.0 and above, the smoothing and weighted normal # modifiers are pinned at the end of the stack by ND. - if force == False and bpy.app.version > (4, 1, 0): + if force == False and app_minor_version() > (4, 1): return mod_order = ['Smooth by Angle', 'Smooth — ND SBA', 'Weighted Normal — ND WN'] @@ -178,7 +179,7 @@ def rectify_smooth_by_angle(object, force=False): if not(mod_name in object_mods): continue - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_move_to_index({'object': object}, modifier=mod_name, index=len(object_mods) - 1) else: with bpy.context.temp_override(object=object): @@ -210,7 +211,7 @@ def remove_modifiers_ending_with(objects, suffix, strict=False): for mod_name in mod_names: base_name = re.sub(r"(.+?)(\.[0-9]{3})$", r"\1", mod_name) if not strict else mod_name if base_name.endswith(suffix): - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_remove({'object': object}, modifier=mod_name) else: with bpy.context.temp_override(object=object): @@ -224,7 +225,7 @@ def remove_modifiers_starting_with(objects, suffix): for mod_name in mod_names: base_name = re.sub(r"(.+?)(\.[0-9]{3})$", r"\1", mod_name) if base_name.startswith(suffix): - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_remove({'object': object}, modifier=mod_name) else: with bpy.context.temp_override(object=object): diff --git a/lib/objects.py b/lib/objects.py index bf6f452..9297e2a 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -30,6 +30,7 @@ from math import radians from mathutils.geometry import distance_point_to_plane, normal from . preferences import get_preferences +from . polling import app_minor_version def add_single_vertex_object(cls, context, name): @@ -47,7 +48,7 @@ def add_single_vertex_object(cls, context, name): context.view_layer.objects.active = obj - if bpy.app.version < (4, 1, 0): + if app_minor_version() < (4, 1): bpy.ops.object.shade_smooth() obj.data.use_auto_smooth = True obj.data.auto_smooth_angle = radians(float(get_preferences().default_smoothing_angle)) @@ -111,7 +112,7 @@ def create_duplicate_liftable_geometry(context, mode, object_name, ignore_comple bevel_weight_layer = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bevel_weight_layer = bm.edges.layers.bevel_weight.verify() else: bevel_weight_layer = bm.edges.layers.float.get("bevel_weight_edge", None) diff --git a/lib/overlay.py b/lib/overlay.py index ffef846..3b2b812 100644 --- a/lib/overlay.py +++ b/lib/overlay.py @@ -28,6 +28,7 @@ import bpy import blf from . preferences import get_preferences +from . polling import app_minor_version def register_draw_handler(cls, callback): @@ -145,7 +146,7 @@ def draw_header(cls): blf.color(0, r, g, b, 1.0) if cls.operator_passthrough or is_summoned or cls.pin_overlay: - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 11, cls.dpi) else: blf.size(0, 11 * cls.dpi_scalar) @@ -162,7 +163,7 @@ def draw_header(cls): blf.draw(0, " // ".join(states)) - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 24, cls.dpi) else: blf.size(0, 24 * cls.dpi_scalar) @@ -173,7 +174,7 @@ def draw_header(cls): def draw_property(cls, property_content, metadata_content, active=False, alt_mode=False, mouse_value=False, input_stream=None): - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 28, cls.dpi) else: blf.size(0, 28 * cls.dpi_scalar) @@ -194,8 +195,8 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod blf.position(0, cls.overlay_x, cls.overlay_y - ((38 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0) - if bpy.app.version >= (3, 4, 0): - if bpy.app.version < (4, 0, 0): + if app_minor_version() >= (3, 4): + if app_minor_version() < (4, 0): blf.size(0, 14, cls.dpi) else: blf.size(0, 14 * cls.dpi_scalar) @@ -207,7 +208,7 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod blf.draw(0, "●") if get_preferences().enable_mouse_values and mouse_value: - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 22, cls.dpi) blf.position(0, cls.overlay_x - (15 * cls.dpi_scalar), cls.overlay_y - ((34 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0) else: @@ -215,7 +216,7 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod blf.position(0, cls.overlay_x - (15 * cls.dpi_scalar), cls.overlay_y - ((33 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0) blf.draw(0, "»") - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 16, cls.dpi) else: blf.size(0, 16 * cls.dpi_scalar) @@ -228,7 +229,7 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod blf.position(0, cls.overlay_x + (25 * cls.dpi_scalar), cls.overlay_y - ((25 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0) blf.draw(0, property_content) - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 11, cls.dpi) else: blf.size(0, 11 * cls.dpi_scalar) @@ -250,7 +251,7 @@ def draw_property(cls, property_content, metadata_content, active=False, alt_mod def draw_hint(cls, hint_content, metadata_content): - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 22, cls.dpi) else: blf.size(0, 16 * cls.dpi_scalar) @@ -265,7 +266,7 @@ def draw_hint(cls, hint_content, metadata_content): blf.position(0, cls.overlay_x - (3 * cls.dpi_scalar), cls.overlay_y - ((36 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0) blf.draw(0, "◈") - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 16, cls.dpi) else: blf.size(0, 16 * cls.dpi_scalar) @@ -278,7 +279,7 @@ def draw_hint(cls, hint_content, metadata_content): blf.position(0, cls.overlay_x + (25 * cls.dpi_scalar), cls.overlay_y - ((25 * cls.dpi_scalar) + (cls.line_spacer * cls.line_step)), 0) blf.draw(0, hint_content) - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): blf.size(0, 11, cls.dpi) else: blf.size(0, 11 * cls.dpi_scalar) diff --git a/lib/points.py b/lib/points.py index 5eca4b3..957142d 100644 --- a/lib/points.py +++ b/lib/points.py @@ -31,6 +31,7 @@ from mathutils import Vector, Matrix from gpu_extras.batch import batch_for_shader from . preferences import get_preferences +from . polling import app_minor_version def register_points_handler(cls): @@ -90,7 +91,7 @@ def draw_guideline(shader, line, size, color): def update_points(cls): shader = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') else: shader = gpu.shader.from_builtin('UNIFORM_COLOR') diff --git a/lib/polling.py b/lib/polling.py index b52d998..7ff8225 100644 --- a/lib/polling.py +++ b/lib/polling.py @@ -25,6 +25,7 @@ # Contributors: Tristo (HM) # --- +import bpy import bmesh @@ -104,3 +105,7 @@ def list_gt(objs, count): def list_lte(objs, count): return len(objs) <= count + + +def app_minor_version(): + return (bpy.app.version[0], bpy.app.version[1]) diff --git a/packaging/seams.py b/packaging/seams.py index 3c6d133..3cd621d 100644 --- a/packaging/seams.py +++ b/packaging/seams.py @@ -35,7 +35,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream from .. lib.modifiers import add_smooth_by_angle, set_smoothing_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected +from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected, app_minor_version class ND_OT_seams(BaseOperator): @@ -158,7 +158,7 @@ def finish(self, context): bpy.ops.object.mode_set(mode='OBJECT') if self.commit_auto_smooth: - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): add_smooth_by_angle(self.target_object) set_smoothing_angle(self.target_object, radians(180), False) else: diff --git a/packaging/triangulate.py b/packaging/triangulate.py index 9b01917..0c45cc6 100644 --- a/packaging/triangulate.py +++ b/packaging/triangulate.py @@ -27,7 +27,7 @@ import bpy from .. lib.modifiers import new_modifier, remove_modifiers_ending_with -from .. lib.polling import ctx_obj_mode, list_ok +from .. lib.polling import ctx_obj_mode, list_ok, app_minor_version class ND_OT_triangulate(bpy.types.Operator): @@ -64,7 +64,7 @@ def invoke(self, context, event): for obj in valid_objects: triangulate = new_modifier(obj, 'Triangulate — ND', 'TRIANGULATE', rectify=False) - if bpy.app.version < (4, 1, 0): + if app_minor_version() < (4, 1): triangulate.keep_custom_normals = self.preserve_normals triangulate.quad_method = 'FIXED' if self.preserve_normals else 'BEAUTY' diff --git a/replicate/mirror.py b/replicate/mirror.py index 07bcf5c..1eecb56 100644 --- a/replicate/mirror.py +++ b/replicate/mirror.py @@ -37,7 +37,7 @@ from .. lib.collections import move_to_utils_collection, isolate_in_utils_collection from .. lib.modifiers import new_modifier, remove_modifiers_starting_with from .. lib.objects import get_real_active_object -from .. lib.polling import obj_moddable, obj_is_curve, obj_exists, ctx_edit_mode, ctx_obj_mode, ctx_objects_selected, ctx_min_objects_selected +from .. lib.polling import obj_moddable, obj_is_curve, obj_exists, ctx_edit_mode, ctx_obj_mode, ctx_objects_selected, ctx_min_objects_selected, app_minor_version class ND_OT_mirror(BaseOperator): @@ -337,7 +337,7 @@ def add_mirror_modifiers(self): if self.early_apply: while obj.modifiers[0].name != mirror.name: - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_move_up({'object': obj}, modifier=mirror.name) else: with bpy.context.temp_override(object=obj): diff --git a/scene/clean_utils.py b/scene/clean_utils.py index f808724..0a8c7fa 100644 --- a/scene/clean_utils.py +++ b/scene/clean_utils.py @@ -27,7 +27,7 @@ import bpy from .. lib.collections import get_all_util_objects -from .. lib.polling import ctx_obj_mode +from .. lib.polling import ctx_obj_mode, app_minor_version class ND_OT_clean_utils(bpy.types.Operator): @@ -95,7 +95,7 @@ def remove_utils(self): deleted_objects.append(obj) removal_count += 1 - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.delete({'active_object': None, 'object': None, 'selected_objects': deleted_objects}, use_global=False) else: with bpy.context.temp_override(active_object=None, object=None, selected_objects=deleted_objects): diff --git a/shading/smooth.py b/shading/smooth.py index 6e1a5a0..dd4c912 100644 --- a/shading/smooth.py +++ b/shading/smooth.py @@ -34,7 +34,7 @@ from .. lib.preferences import get_preferences from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream from .. lib.modifiers import add_smooth_by_angle, set_smoothing_angle -from .. lib.polling import ctx_obj_mode, list_ok +from .. lib.polling import ctx_obj_mode, list_ok, app_minor_version class ND_OT_smooth(BaseOperator): @@ -70,7 +70,7 @@ def do_modal(self, context, event): self.angle = max(0, self.angle - angle_factor) self.dirty = True - if bpy.app.version >= (4, 1, 0) and pressed(event, {'S'}): + if app_minor_version() >= (4, 1) and pressed(event, {'S'}): self.ignore_sharpness = not self.ignore_sharpness self.dirty = True @@ -122,7 +122,7 @@ def poll(cls, context): def add_smooth_shading(self, context): - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): for obj in self.valid_objects: add_smooth_by_angle(obj) return @@ -134,7 +134,7 @@ def add_smooth_shading(self, context): def operate(self, context): - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): for obj in self.valid_objects: set_smoothing_angle(obj, radians(self.angle), self.ignore_sharpness) else: @@ -167,7 +167,7 @@ def draw_text_callback(self): mouse_value=True, input_stream=self.angle_input_stream) - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): draw_hint( self, "Ignore Sharpness [S]: {}".format("Yes" if self.ignore_sharpness else "No"), diff --git a/shading/wn.py b/shading/wn.py index f2f8dda..a40ce9c 100644 --- a/shading/wn.py +++ b/shading/wn.py @@ -27,7 +27,7 @@ import bpy from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle -from .. lib.polling import ctx_obj_mode, list_ok +from .. lib.polling import ctx_obj_mode, list_ok, app_minor_version class ND_OT_weighted_normal(bpy.types.Operator): @@ -67,7 +67,7 @@ def invoke(self, context, event): mod.weight = 100 mod.use_face_influence = True - if bpy.app.version > (4, 1, 0): + if app_minor_version() > (4, 1): mod.use_pin_to_last = True rectify_smooth_by_angle(obj, force=True) diff --git a/sketch/circularize.py b/sketch/circularize.py index 0a402d0..96384bc 100644 --- a/sketch/circularize.py +++ b/sketch/circularize.py @@ -35,7 +35,7 @@ from .. lib.numeric_input import update_stream, no_stream, get_stream_value, new_stream, has_stream, set_stream from .. lib.modifiers import new_modifier, remove_modifiers_ending_with, rectify_smooth_by_angle, add_smooth_by_angle from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_multi_mode, obj_is_mesh, ctx_objects_selected +from .. lib.polling import ctx_multi_mode, obj_is_mesh, ctx_objects_selected, app_minor_version mod_bevel = "Bevel — ND CIRC" @@ -167,7 +167,7 @@ def add_smooth_shading(self, context): bpy.ops.object.mode_set(mode='OBJECT') return_to_edit = True - if bpy.app.version >= (4, 1, 0): + if app_minor_version() >= (4, 1): add_smooth_by_angle(self.target_object) if return_to_edit: bpy.ops.object.mode_set(mode='EDIT') diff --git a/standalone/cycle.py b/standalone/cycle.py index dccb950..54f3af5 100644 --- a/standalone/cycle.py +++ b/standalone/cycle.py @@ -33,7 +33,7 @@ from .. lib.collections import hide_utils_collection, isolate_in_utils_collection from .. lib.preferences import get_preferences from .. lib.objects import get_real_active_object -from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected +from .. lib.polling import ctx_obj_mode, obj_is_mesh, ctx_objects_selected, app_minor_version class ND_OT_cycle(BaseOperator): @@ -245,7 +245,7 @@ def finish(self, context): for apply_obj in self.applied_utils: for mod in self.target_obj.modifiers: if mod.type == 'BOOLEAN' and mod.object == apply_obj: - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_apply({'object': self.target_obj}, modifier=mod.name) else: with bpy.context.temp_override(object=self.target_obj): diff --git a/utils/apply_modifiers.py b/utils/apply_modifiers.py index 263992d..1a88218 100644 --- a/utils/apply_modifiers.py +++ b/utils/apply_modifiers.py @@ -27,7 +27,7 @@ import bpy import bmesh -from .. lib.polling import ctx_obj_mode, list_ok +from .. lib.polling import ctx_obj_mode, list_ok, app_minor_version class ND_OT_apply_modifiers(bpy.types.Operator): @@ -123,21 +123,21 @@ def collapse_modifiers(self, obj): for mod_name in mods_to_apply: try: - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_apply({'object': obj}, modifier=mod_name) else: with bpy.context.temp_override(object=obj): bpy.ops.object.modifier_apply(modifier=mod_name) except: # If the modifier is disabled, just remove it. - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_remove({'object': obj}, modifier=mod_name) else: with bpy.context.temp_override(object=obj): bpy.ops.object.modifier_remove(modifier=mod_name) for mod_name in mods_to_remove: - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bpy.ops.object.modifier_remove({'object': obj}, modifier=mod_name) else: with bpy.context.temp_override(object=obj): @@ -156,7 +156,7 @@ def remove_edge_weights(self, obj): bevel_weight_layer = None - if bpy.app.version < (4, 0, 0): + if app_minor_version() < (4, 0): bevel_weight_layer = bm.edges.layers.bevel_weight.verify() else: bevel_weight_layer = bm.edges.layers.float.get("bevel_weight_edge", None)