From 7e71c5d48bd0385f3660bd13dd756cd3d9e76f2a Mon Sep 17 00:00:00 2001 From: Loren Osborn Date: Tue, 16 Jul 2024 11:03:01 -0700 Subject: [PATCH 1/2] Apply autopep8 changes from `pyproject.toml` --- source/Boltfactory.py | 574 +++++++++++++++++++++--------------------- source/__init__.py | 2 - source/createMesh.py | 516 +++++++++++++++++++------------------ 3 files changed, 542 insertions(+), 550 deletions(-) diff --git a/source/Boltfactory.py b/source/Boltfactory.py index 8fc5e1e..26141c2 100644 --- a/source/Boltfactory.py +++ b/source/Boltfactory.py @@ -9,13 +9,13 @@ from mathutils import Matrix from bpy.types import Operator from bpy_extras.object_utils import AddObjectHelper from bpy.props import ( - BoolProperty, - EnumProperty, - FloatProperty, - IntProperty, - FloatVectorProperty, - StringProperty, - ) + BoolProperty, + EnumProperty, + FloatProperty, + IntProperty, + FloatVectorProperty, + StringProperty, +) from . import createMesh from bpy_extras import object_utils @@ -26,307 +26,307 @@ class add_mesh_bolt(Operator, AddObjectHelper): bl_options = {'REGISTER', 'UNDO', 'PRESET'} bl_description = "Construct many types of Bolts" - MAX_INPUT_NUMBER = 50 - Bolt : BoolProperty(name = "Bolt", - default = True, - description = "Bolt") - change : BoolProperty(name = "Change", - default = False, - description = "change Bolt") + Bolt: BoolProperty(name="Bolt", + default=True, + description="Bolt") + change: BoolProperty(name="Change", + default=False, + description="change Bolt") # Model Types Model_Type_List = [('bf_Model_Bolt', 'BOLT', 'Bolt Model'), ('bf_Model_Nut', 'NUT', 'Nut Model')] bf_Model_Type: EnumProperty( - attr='bf_Model_Type', - name='Model', - description='Choose the type off model you would like', - items=Model_Type_List, default='bf_Model_Bolt' - ) + attr='bf_Model_Type', + name='Model', + description='Choose the type off model you would like', + items=Model_Type_List, default='bf_Model_Bolt' + ) # Head Types Model_Type_List = [('bf_Head_Hex', 'HEX', 'Hex Head'), ('bf_Head_12Pnt', '12 POINT', '12 Point Head'), - ('bf_Head_Cap', 'CAP', 'Cap Head'), - ('bf_Head_Dome', 'DOME', 'Dome Head'), - ('bf_Head_Pan', 'PAN', 'Pan Head'), - ('bf_Head_CounterSink', 'COUNTER SINK', 'Counter Sink Head')] + ('bf_Head_Cap', 'CAP', 'Cap Head'), + ('bf_Head_Dome', 'DOME', 'Dome Head'), + ('bf_Head_Pan', 'PAN', 'Pan Head'), + ('bf_Head_CounterSink', 'COUNTER SINK', 'Counter Sink Head')] bf_Head_Type: EnumProperty( - attr='bf_Head_Type', - name='Head', - description='Choose the type off Head you would like', - items=Model_Type_List, default='bf_Head_Hex' - ) + attr='bf_Head_Type', + name='Head', + description='Choose the type off Head you would like', + items=Model_Type_List, default='bf_Head_Hex' + ) # Bit Types Bit_Type_List = [('bf_Bit_None', 'NONE', 'No Bit Type'), - ('bf_Bit_Allen', 'ALLEN', 'Allen Bit Type'), - ('bf_Bit_Torx', 'TORX', 'Torx Bit Type'), - ('bf_Bit_Philips', 'PHILLIPS', 'Phillips Bit Type')] + ('bf_Bit_Allen', 'ALLEN', 'Allen Bit Type'), + ('bf_Bit_Torx', 'TORX', 'Torx Bit Type'), + ('bf_Bit_Philips', 'PHILLIPS', 'Phillips Bit Type')] bf_Bit_Type: EnumProperty( - attr='bf_Bit_Type', - name='Bit Type', - description='Choose the type of bit to you would like', - items=Bit_Type_List, default='bf_Bit_None' - ) + attr='bf_Bit_Type', + name='Bit Type', + description='Choose the type of bit to you would like', + items=Bit_Type_List, default='bf_Bit_None' + ) # Nut Types Nut_Type_List = [('bf_Nut_Hex', 'HEX', 'Hex Nut'), - ('bf_Nut_Lock', 'LOCK', 'Lock Nut'), - ('bf_Nut_12Pnt', '12 POINT', '12 Point Nut')] + ('bf_Nut_Lock', 'LOCK', 'Lock Nut'), + ('bf_Nut_12Pnt', '12 POINT', '12 Point Nut')] bf_Nut_Type: EnumProperty( - attr='bf_Nut_Type', - name='Nut Type', - description='Choose the type of nut you would like', - items=Nut_Type_List, default='bf_Nut_Hex' - ) + attr='bf_Nut_Type', + name='Nut Type', + description='Choose the type of nut you would like', + items=Nut_Type_List, default='bf_Nut_Hex' + ) # Shank Types bf_Shank_Length: FloatProperty( - attr='bf_Shank_Length', - name='Shank Length', default=0, - min=0, soft_min=0, max=MAX_INPUT_NUMBER, - description='Length of the unthreaded shank', - unit='LENGTH', - ) + attr='bf_Shank_Length', + name='Shank Length', default=0, + min=0, soft_min=0, max=MAX_INPUT_NUMBER, + description='Length of the unthreaded shank', + unit='LENGTH', + ) bf_Shank_Dia: FloatProperty( - attr='bf_Shank_Dia', - name='Shank Dia', default=3, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Diameter of the shank', - unit='LENGTH', - ) + attr='bf_Shank_Dia', + name='Shank Dia', default=3, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Diameter of the shank', + unit='LENGTH', + ) bf_Phillips_Bit_Depth: FloatProperty( - attr='bf_Phillips_Bit_Depth', - name='Bit Depth', default=1.1431535482406616, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Depth of the Phillips Bit', - unit='LENGTH', - ) + attr='bf_Phillips_Bit_Depth', + name='Bit Depth', default=1.1431535482406616, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Depth of the Phillips Bit', + unit='LENGTH', + ) bf_Allen_Bit_Depth: FloatProperty( - attr='bf_Allen_Bit_Depth', - name='Bit Depth', default=1.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Depth of the Allen Bit', - unit='LENGTH', - ) + attr='bf_Allen_Bit_Depth', + name='Bit Depth', default=1.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Depth of the Allen Bit', + unit='LENGTH', + ) bf_Allen_Bit_Flat_Distance: FloatProperty( - attr='bf_Allen_Bit_Flat_Distance', - name='Flat Dist', default=2.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Flat Distance of the Allen Bit', - unit='LENGTH', - ) + attr='bf_Allen_Bit_Flat_Distance', + name='Flat Dist', default=2.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Flat Distance of the Allen Bit', + unit='LENGTH', + ) # Torx Size Types Torx_Size_Type_List = [('bf_Torx_T10', 'T10', 'T10'), - ('bf_Torx_T20', 'T20', 'T20'), - ('bf_Torx_T25', 'T25', 'T25'), - ('bf_Torx_T30', 'T30', 'T30'), - ('bf_Torx_T40', 'T40', 'T40'), - ('bf_Torx_T50', 'T50', 'T50'), - ('bf_Torx_T55', 'T55', 'T55'), - ] + ('bf_Torx_T20', 'T20', 'T20'), + ('bf_Torx_T25', 'T25', 'T25'), + ('bf_Torx_T30', 'T30', 'T30'), + ('bf_Torx_T40', 'T40', 'T40'), + ('bf_Torx_T50', 'T50', 'T50'), + ('bf_Torx_T55', 'T55', 'T55'), + ] bf_Torx_Size_Type: EnumProperty( - attr='bf_Torx_Size_Type', - name='Torx Size', - description='Size of the Torx Bit', - items=Torx_Size_Type_List, default='bf_Torx_T20' - ) + attr='bf_Torx_Size_Type', + name='Torx Size', + description='Size of the Torx Bit', + items=Torx_Size_Type_List, default='bf_Torx_T20' + ) bf_Torx_Bit_Depth: FloatProperty( - attr='bf_Torx_Bit_Depth', - name='Bit Depth', default=1.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Depth of the Torx Bit', - unit='LENGTH', - ) + attr='bf_Torx_Bit_Depth', + name='Bit Depth', default=1.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Depth of the Torx Bit', + unit='LENGTH', + ) bf_Hex_Head_Height: FloatProperty( - attr='bf_Hex_Head_Height', - name='Head Height', default=2, - min=0, soft_min=0, max=MAX_INPUT_NUMBER, - description='Height of the Hex Head', - unit='LENGTH', - ) + attr='bf_Hex_Head_Height', + name='Head Height', default=2, + min=0, soft_min=0, max=MAX_INPUT_NUMBER, + description='Height of the Hex Head', + unit='LENGTH', + ) bf_Hex_Head_Flat_Distance: FloatProperty( - attr='bf_Hex_Head_Flat_Distance', - name='Flat Dist', default=5.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Flat Distance of the Hex Head', - unit='LENGTH', - ) + attr='bf_Hex_Head_Flat_Distance', + name='Flat Dist', default=5.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Flat Distance of the Hex Head', + unit='LENGTH', + ) bf_12_Point_Head_Height: FloatProperty( - attr='bf_12_Point_Head_Height', - name='Head Height', default=3.0, - min=0, soft_min=0, max=MAX_INPUT_NUMBER, - description='Height of the 12 Point Head', - unit='LENGTH', - ) + attr='bf_12_Point_Head_Height', + name='Head Height', default=3.0, + min=0, soft_min=0, max=MAX_INPUT_NUMBER, + description='Height of the 12 Point Head', + unit='LENGTH', + ) bf_12_Point_Head_Flat_Distance: FloatProperty( - attr='bf_12_Point_Head_Flat_Distance', - name='Flat Dist', default=3.0, - min=0.001, soft_min=0, #limit to 0.001 to avoid calculation error - max=MAX_INPUT_NUMBER, - description='Flat Distance of the 12 Point Head', - unit='LENGTH', - ) + attr='bf_12_Point_Head_Flat_Distance', + name='Flat Dist', default=3.0, + min=0.001, soft_min=0, # limit to 0.001 to avoid calculation error + max=MAX_INPUT_NUMBER, + description='Flat Distance of the 12 Point Head', + unit='LENGTH', + ) bf_12_Point_Head_Flange_Dia: FloatProperty( - attr='bf_12_Point_Head_Flange_Dia', - name='12 Point Head Flange Dia', default=5.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Flange diameter of the 12 point Head', - unit='LENGTH', - ) + attr='bf_12_Point_Head_Flange_Dia', + name='12 Point Head Flange Dia', default=5.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Flange diameter of the 12 point Head', + unit='LENGTH', + ) bf_CounterSink_Head_Dia: FloatProperty( - attr='bf_CounterSink_Head_Dia', - name='Head Dia', default=6.300000190734863, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Diameter of the Counter Sink Head', - unit='LENGTH', - ) + attr='bf_CounterSink_Head_Dia', + name='Head Dia', default=6.300000190734863, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Diameter of the Counter Sink Head', + unit='LENGTH', + ) bf_Cap_Head_Height: FloatProperty( - attr='bf_Cap_Head_Height', - name='Head Height', default=3, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Height of the Cap Head', - unit='LENGTH', - ) + attr='bf_Cap_Head_Height', + name='Head Height', default=3, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Height of the Cap Head', + unit='LENGTH', + ) bf_Cap_Head_Dia: FloatProperty( - attr='bf_Cap_Head_Dia', - name='Head Dia', default=5.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Diameter of the Cap Head', - unit='LENGTH', - ) + attr='bf_Cap_Head_Dia', + name='Head Dia', default=5.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Diameter of the Cap Head', + unit='LENGTH', + ) bf_Dome_Head_Dia: FloatProperty( - attr='bf_Dome_Head_Dia', - name='Dome Head Dia', default=5.599999904632568, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Length of the unthreaded shank', - unit='LENGTH', - ) + attr='bf_Dome_Head_Dia', + name='Dome Head Dia', default=5.599999904632568, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Length of the unthreaded shank', + unit='LENGTH', + ) bf_Pan_Head_Dia: FloatProperty( - attr='bf_Pan_Head_Dia', - name='Pan Head Dia', default=5.599999904632568, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Diameter of the Pan Head', - unit='LENGTH', - ) + attr='bf_Pan_Head_Dia', + name='Pan Head Dia', default=5.599999904632568, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Diameter of the Pan Head', + unit='LENGTH', + ) bf_Philips_Bit_Dia: FloatProperty( - attr='bf_Philips_Bit_Dia', - name='Bit Dia', default=1.8199999332427979, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Diameter of the Philips Bit', - unit='LENGTH', - ) + attr='bf_Philips_Bit_Dia', + name='Bit Dia', default=1.8199999332427979, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Diameter of the Philips Bit', + unit='LENGTH', + ) bf_Thread_Length: FloatProperty( - attr='bf_Thread_Length', - name='Thread Length', default=6, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Length of the Thread', - unit='LENGTH', - ) + attr='bf_Thread_Length', + name='Thread Length', default=6, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Length of the Thread', + unit='LENGTH', + ) bf_Major_Dia: FloatProperty( - attr='bf_Major_Dia', - name='Major Dia', default=3, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Outside diameter of the Thread', - unit='LENGTH', - ) + attr='bf_Major_Dia', + name='Major Dia', default=3, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Outside diameter of the Thread', + unit='LENGTH', + ) bf_Pitch: FloatProperty( - attr='bf_Pitch', - name='Pitch', default=0.3499999940395355, - min=0.1, soft_min=0.1, - max=7.0, - description='Pitch if the thread', - unit='LENGTH', - ) + attr='bf_Pitch', + name='Pitch', default=0.3499999940395355, + min=0.1, soft_min=0.1, + max=7.0, + description='Pitch if the thread', + unit='LENGTH', + ) bf_Minor_Dia: FloatProperty( - attr='bf_Minor_Dia', - name='Minor Dia', default=2.6211137771606445, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Inside diameter of the Thread', - unit='LENGTH', - ) + attr='bf_Minor_Dia', + name='Minor Dia', default=2.6211137771606445, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Inside diameter of the Thread', + unit='LENGTH', + ) bf_Crest_Percent: IntProperty( - attr='bf_Crest_Percent', - name='Crest Percent', default=10, - min=1, soft_min=1, - max=90, - description='Percent of the pitch that makes up the Crest', - ) + attr='bf_Crest_Percent', + name='Crest Percent', default=10, + min=1, soft_min=1, + max=90, + description='Percent of the pitch that makes up the Crest', + ) bf_Root_Percent: IntProperty( - attr='bf_Root_Percent', - name='Root Percent', default=10, - min=1, soft_min=1, - max=90, - description='Percent of the pitch that makes up the Root', - ) + attr='bf_Root_Percent', + name='Root Percent', default=10, + min=1, soft_min=1, + max=90, + description='Percent of the pitch that makes up the Root', + ) bf_Div_Count: IntProperty( - attr='bf_Div_Count', - name='Div count', default=36, - min=4, soft_min=4, - max=4096, - description='Div count determine circle resolution', - ) + attr='bf_Div_Count', + name='Div count', default=36, + min=4, soft_min=4, + max=4096, + description='Div count determine circle resolution', + ) bf_Hex_Nut_Height: FloatProperty( - attr='bf_Hex_Nut_Height', - name='Hex Nut Height', default=2.4000000953674316, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Height of the Hex Nut', - unit='LENGTH', - ) + attr='bf_Hex_Nut_Height', + name='Hex Nut Height', default=2.4000000953674316, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Height of the Hex Nut', + unit='LENGTH', + ) bf_Hex_Nut_Flat_Distance: FloatProperty( - attr='bf_Hex_Nut_Flat_Distance', - name='Hex Nut Flat Dist', default=5.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Flat distance of the Hex Nut', - unit='LENGTH', - ) + attr='bf_Hex_Nut_Flat_Distance', + name='Hex Nut Flat Dist', default=5.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Flat distance of the Hex Nut', + unit='LENGTH', + ) bf_12_Point_Nut_Height: FloatProperty( - attr='bf_12_Point_Nut_Height', - name='12 Point Nut Height', default=2.4000000953674316, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Height of the 12 Point Nut', - unit='LENGTH', - ) + attr='bf_12_Point_Nut_Height', + name='12 Point Nut Height', default=2.4000000953674316, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Height of the 12 Point Nut', + unit='LENGTH', + ) bf_12_Point_Nut_Flat_Distance: FloatProperty( - attr='bf_12_Point_Nut_Flat_Distance', - name='12 Point Nut Flat Dist', default=3.0, - min=0.001, soft_min=0, #limit to 0.001 to avoid calculation error - max=MAX_INPUT_NUMBER, - description='Flat distance of the 12 point Nut', - unit='LENGTH', - ) + attr='bf_12_Point_Nut_Flat_Distance', + name='12 Point Nut Flat Dist', default=3.0, + min=0.001, soft_min=0, # limit to 0.001 to avoid calculation error + max=MAX_INPUT_NUMBER, + description='Flat distance of the 12 point Nut', + unit='LENGTH', + ) bf_12_Point_Nut_Flange_Dia: FloatProperty( - attr='bf_12_Point_Nut_Flange_Dia', - name='12 Point Nut Flange Dia', default=5.5, - min=0, soft_min=0, - max=MAX_INPUT_NUMBER, - description='Flange diameter of the 12 point Nut', - unit='LENGTH', - ) + attr='bf_12_Point_Nut_Flange_Dia', + name='12 Point Nut Flange Dia', default=5.5, + min=0, soft_min=0, + max=MAX_INPUT_NUMBER, + description='Flange diameter of the 12 point Nut', + unit='LENGTH', + ) + def draw(self, context): layout = self.layout col = layout.column() @@ -387,8 +387,6 @@ class add_mesh_bolt(Operator, AddObjectHelper): col.prop(self, 'bf_Hex_Nut_Height') col.prop(self, 'bf_Hex_Nut_Flat_Distance') - - # Thread col.label(text='Thread') if self.bf_Model_Type == 'bf_Model_Bolt': @@ -400,7 +398,7 @@ class add_mesh_bolt(Operator, AddObjectHelper): col.prop(self, 'bf_Root_Percent') col.prop(self, 'bf_Div_Count') - if self.change == False: + if not self.change: # generic transform props col.separator() col.prop(self, 'align') @@ -416,7 +414,7 @@ class add_mesh_bolt(Operator, AddObjectHelper): if bpy.context.mode == "OBJECT": if context.selected_objects != [] and context.active_object and \ (context.active_object.data is not None) and ('Bolt' in context.active_object.data.keys()) and \ - (self.change == True): + (self.change): obj = context.active_object use_smooth = bool(obj.data.polygons[0].use_smooth) # Copy value, do not take a reference @@ -468,6 +466,8 @@ class add_mesh_bolt(Operator, AddObjectHelper): return {'FINISHED'} # Register: + + def Bolt_contex_menu(self, context): bl_label = 'Change' @@ -481,18 +481,19 @@ def Bolt_contex_menu(self, context): setattr(props, prm, obj.data[prm]) layout.separator() + def menu_func_bolt(self, context): layout = self.layout layout.separator() oper = self.layout.operator(add_mesh_bolt.bl_idname, text="Bolt", icon="MOD_SCREW") oper.change = False + classes = ( add_mesh_bolt, ) - def register(): for cls in classes: bpy.utils.register_class(cls) @@ -506,35 +507,36 @@ def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls) + def BoltParameters(): BoltParameters = [ - "bf_Model_Type", - "bf_Head_Type", - "bf_Bit_Type", - "bf_Nut_Type", - "bf_Shank_Length", - "bf_Shank_Dia", - "bf_Phillips_Bit_Depth", - "bf_Allen_Bit_Depth", - "bf_Allen_Bit_Flat_Distance", - "bf_Torx_Bit_Depth", - "bf_Torx_Size_Type", - "bf_Hex_Head_Height", - "bf_Hex_Head_Flat_Distance", - "bf_CounterSink_Head_Dia", - "bf_Cap_Head_Height", - "bf_Cap_Head_Dia", - "bf_Dome_Head_Dia", - "bf_Pan_Head_Dia", - "bf_Philips_Bit_Dia", - "bf_Thread_Length", - "bf_Major_Dia", - "bf_Pitch", - "bf_Minor_Dia", - "bf_Crest_Percent", - "bf_Root_Percent", - "bf_Div_Count", - "bf_Hex_Nut_Height", - "bf_Hex_Nut_Flat_Distance", - ] + "bf_Model_Type", + "bf_Head_Type", + "bf_Bit_Type", + "bf_Nut_Type", + "bf_Shank_Length", + "bf_Shank_Dia", + "bf_Phillips_Bit_Depth", + "bf_Allen_Bit_Depth", + "bf_Allen_Bit_Flat_Distance", + "bf_Torx_Bit_Depth", + "bf_Torx_Size_Type", + "bf_Hex_Head_Height", + "bf_Hex_Head_Flat_Distance", + "bf_CounterSink_Head_Dia", + "bf_Cap_Head_Height", + "bf_Cap_Head_Dia", + "bf_Dome_Head_Dia", + "bf_Pan_Head_Dia", + "bf_Philips_Bit_Dia", + "bf_Thread_Length", + "bf_Major_Dia", + "bf_Pitch", + "bf_Minor_Dia", + "bf_Crest_Percent", + "bf_Root_Percent", + "bf_Div_Count", + "bf_Hex_Nut_Height", + "bf_Hex_Nut_Flat_Distance", + ] return BoltParameters diff --git a/source/__init__.py b/source/__init__.py index 169bc86..a7355ae 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -16,12 +16,10 @@ import bpy # ### REGISTER ### - def register(): Boltfactory.register() - def unregister(): Boltfactory.unregister() diff --git a/source/createMesh.py b/source/createMesh.py index 8ef9b87..bdc75f8 100644 --- a/source/createMesh.py +++ b/source/createMesh.py @@ -4,14 +4,14 @@ import bpy from mathutils import ( - Matrix, - Vector, - geometry, - ) + Matrix, + Vector, + geometry, +) from math import ( - sin, cos, - tan, radians,atan,degrees - ) + sin, cos, + tan, radians, atan, degrees +) from random import triangular from bpy_extras.object_utils import AddObjectHelper, object_data_add @@ -273,19 +273,21 @@ def Fill_Ring_Face(OFFSET, NUM, FACE_DOWN=0): return Ret # Returns a list of faces that makes up a fill pattern around the last vert + + def Fill_Fan_Face(OFFSET, NUM, FACE_DOWN=0): Ret = [] - Face = [NUM-1,0,1] + Face = [NUM - 1, 0, 1] TempFace = [0, 0, 0] A = 0 - #B = 1 unused + # B = 1 unused C = 2 if NUM < 3: return None for _i in range(NUM - 2): TempFace[0] = Face[A] TempFace[1] = Face[C] - TempFace[2] = Face[C]+1 + TempFace[2] = Face[C] + 1 if FACE_DOWN: Ret.append([OFFSET + Face[2], OFFSET + Face[1], OFFSET + Face[0]]) else: @@ -300,6 +302,7 @@ def Fill_Fan_Face(OFFSET, NUM, FACE_DOWN=0): # Create Allen Bit # #################################################################### + def Allen_Fill(OFFSET, FLIP=0): faces = [] Lookup = [[19, 1, 0], @@ -392,6 +395,7 @@ def Create_Allen_Bit(FLAT_DISTANCE, HEIGHT): # Create Torx Bit # #################################################################### + def Torx_Bit_Size_To_Point_Distance(Bit_Size): if Bit_Size == 'bf_Torx_T10': return 2.83 @@ -408,70 +412,71 @@ def Torx_Bit_Size_To_Point_Distance(Bit_Size): elif Bit_Size == 'bf_Torx_T55': return 8.94 else: - return 2.83 #default to M3 + return 2.83 # default to M3 + def Torx_Fill(OFFSET, FLIP=0): faces = [] - Lookup = [[0,10,11], - [0,11, 12], - [0,12,1], + Lookup = [[0, 10, 11], + [0, 11, 12], + [0, 12, 1], - [1, 12, 13], - [1, 13, 14], - [1, 14, 15], - [1, 15, 2], + [1, 12, 13], + [1, 13, 14], + [1, 14, 15], + [1, 15, 2], - [2, 15, 16], - [2, 16, 17], - [2, 17, 18], - [2, 18, 19], - [2, 19, 3], + [2, 15, 16], + [2, 16, 17], + [2, 17, 18], + [2, 18, 19], + [2, 19, 3], - [3, 19, 20], - [3, 20, 21], - [3, 21, 22], - [3, 22, 23], - [3, 23, 24], - [3, 24, 25], - [3, 25, 4], + [3, 19, 20], + [3, 20, 21], + [3, 21, 22], + [3, 22, 23], + [3, 23, 24], + [3, 24, 25], + [3, 25, 4], - [4, 25, 26], - [4, 26, 27], - [4, 27, 28], - [4, 28, 29], - [4, 29, 30], - [4, 30, 31], - [4, 31, 5], + [4, 25, 26], + [4, 26, 27], + [4, 27, 28], + [4, 28, 29], + [4, 29, 30], + [4, 30, 31], + [4, 31, 5], - [5, 31, 32], - [5, 32, 33], - [5, 33, 34], - [5, 34, 35], - [5, 35, 36], - [5, 36, 6], + [5, 31, 32], + [5, 32, 33], + [5, 33, 34], + [5, 34, 35], + [5, 35, 36], + [5, 36, 6], - [6, 36, 37], - [6, 37, 38], - [6, 38, 39], - [6, 39, 7], + [6, 36, 37], + [6, 37, 38], + [6, 38, 39], + [6, 39, 7], - [7, 39, 40], - [7, 40, 41], - [7, 41, 42], - [7, 42, 43], - [7, 43, 8], + [7, 39, 40], + [7, 40, 41], + [7, 41, 42], + [7, 42, 43], + [7, 43, 8], - [8, 43, 44], - [8, 44, 45], - [8, 45, 46], - [8, 46, 47], - [8, 47, 48], - [8, 48, 49], - [8, 49, 50], - [8, 50, 51], - [8, 51, 52], - [8, 52, 9], + [8, 43, 44], + [8, 44, 45], + [8, 45, 46], + [8, 46, 47], + [8, 47, 48], + [8, 48, 49], + [8, 49, 50], + [8, 50, 51], + [8, 51, 52], + [8, 52, 9], ] for i in Lookup: if FLIP: @@ -482,7 +487,6 @@ def Torx_Fill(OFFSET, FLIP=0): return faces - def Create_Torx_Bit(Point_Distance, HEIGHT): verts = [] faces = [] @@ -520,8 +524,8 @@ def Create_Torx_Bit(Point_Distance, HEIGHT): verts.append([POINT_2_X + x, POINT_2_Y + y, Curve_Height]) for i in range(340, 150 + 360, 10): - x = sin(radians(i%360)) * SMALL_RADIUS - y = cos(radians(i%360)) * SMALL_RADIUS + x = sin(radians(i % 360)) * SMALL_RADIUS + y = cos(radians(i % 360)) * SMALL_RADIUS verts.append([POINT_3_X + x, POINT_3_Y + y, Curve_Height]) for i in range(320, 260, -10): @@ -536,16 +540,16 @@ def Create_Torx_Bit(Point_Distance, HEIGHT): y = cos(radians(i)) * OUTTER_RADIUS verts.append([x, y, 0]) - FaceStart_Top_Curve= len(verts) + FaceStart_Top_Curve = len(verts) Do_Curve(0) faces.extend(Torx_Fill(FaceStart_Outside, 0)) - FaceStart_Bottom_Curve= len(verts) + FaceStart_Bottom_Curve = len(verts) Do_Curve(0 - HEIGHT) - faces.extend(Build_Face_List_Quads(FaceStart_Top_Curve,42 ,1 , True)) + faces.extend(Build_Face_List_Quads(FaceStart_Top_Curve, 42, 1, True)) - verts.append([0,0,0 - HEIGHT]) # add center point for fill Fan + verts.append([0, 0, 0 - HEIGHT]) # add center point for fill Fan faces.extend(Fill_Fan_Face(FaceStart_Bottom_Curve, 44)) M_Verts, M_Faces = Mirror_Verts_Faces(verts, faces, 'x') @@ -562,6 +566,7 @@ def Create_Torx_Bit(Point_Distance, HEIGHT): # Create Phillips Bit # #################################################################### + def Phillips_Fill(OFFSET, FLIP=0): faces = [] Lookup = [[0, 1, 10], @@ -1059,14 +1064,13 @@ def Create_Hex_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT): return Spin_Verts, Spin_Faces, 0 - (-HEIGHT) - -def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA): - FLANGE_HEIGHT = (1.89/8.0)*HEIGHT - FLAT_HEIGHT = (4.18/8.0)*HEIGHT +def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT, FLANGE_DIA): + FLANGE_HEIGHT = (1.89 / 8.0) * HEIGHT + FLAT_HEIGHT = (4.18 / 8.0) * HEIGHT # FLANGE_DIA = (13.27/8.0)*FLAT FLANGE_RADIUS = FLANGE_DIA * 0.5 - FLANGE_TAPPER_HEIGHT = HEIGHT - FLANGE_HEIGHT - FLAT_HEIGHT + FLANGE_TAPPER_HEIGHT = HEIGHT - FLANGE_HEIGHT - FLAT_HEIGHT # HOLE_DIA = 0.0 @@ -1120,8 +1124,6 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA): Row += 1 - - # bevel x = sin(radians(0)) * TopBevelRadius y = cos(radians(0)) * TopBevelRadius @@ -1160,41 +1162,40 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA): Row += 1 + # 45Deg bevel on the top - #45Deg bevel on the top - - #First we work out how far up the Y axis the vert is - v_origin = Vector([0.0,0.0,0.0]) # center of the model - v_15Deg_Point = Vector([tan(radians(15)) * Half_Flat,Half_Flat,0.0]) #Is a know point to work back from + # First we work out how far up the Y axis the vert is + v_origin = Vector([0.0, 0.0, 0.0]) # center of the model + v_15Deg_Point = Vector([tan(radians(15)) * Half_Flat, Half_Flat, 0.0]) # Is a know point to work back from x = tan(radians(0)) * Half_Flat - Point_Distance =(tan(radians(30)) * v_15Deg_Point.x)+Half_Flat + Point_Distance = (tan(radians(30)) * v_15Deg_Point.x) + Half_Flat dvec = vec1 - Vector([x, Point_Distance, 0.0]) verts.append([x, Point_Distance, -dvec.length]) v_0_Deg_Top_Point = Vector([x, Point_Distance, -dvec.length]) - v_0_Deg_Point = Vector([x, Point_Distance,0.0]) + v_0_Deg_Point = Vector([x, Point_Distance, 0.0]) v_5Deg_Line = Vector([tan(radians(5)) * Half_Flat, Half_Flat, 0.0]) v_5Deg_Line.length *= 2 # extende out the line on a 5 deg angle - #We cross 2 lines. One from the origin to the 0 Deg point - #and the second is from the origin extended out past the first line + # We cross 2 lines. One from the origin to the 0 Deg point + # and the second is from the origin extended out past the first line # This gives the cross point of the - v_Cross = geometry.intersect_line_line_2d(v_0_Deg_Point,v_15Deg_Point,v_origin,v_5Deg_Line) - dvec = vec2 - Vector([v_Cross.x,v_Cross.y,0.0]) - verts.append([v_Cross.x,v_Cross.y,-dvec.length]) - v_5_Deg_Top_Point = Vector([v_Cross.x,v_Cross.y,-dvec.length]) + v_Cross = geometry.intersect_line_line_2d(v_0_Deg_Point, v_15Deg_Point, v_origin, v_5Deg_Line) + dvec = vec2 - Vector([v_Cross.x, v_Cross.y, 0.0]) + verts.append([v_Cross.x, v_Cross.y, -dvec.length]) + v_5_Deg_Top_Point = Vector([v_Cross.x, v_Cross.y, -dvec.length]) v_10Deg_Line = Vector([tan(radians(10)) * Half_Flat, Half_Flat, 0.0]) v_10Deg_Line.length *= 2 # extende out the line - v_Cross = geometry.intersect_line_line_2d(v_0_Deg_Point,v_15Deg_Point,v_origin,v_10Deg_Line) - dvec = vec3 - Vector([v_Cross.x,v_Cross.y,0.0]) - verts.append([v_Cross.x,v_Cross.y,-dvec.length]) - v_10_Deg_Top_Point = Vector([v_Cross.x,v_Cross.y,-dvec.length]) + v_Cross = geometry.intersect_line_line_2d(v_0_Deg_Point, v_15Deg_Point, v_origin, v_10Deg_Line) + dvec = vec3 - Vector([v_Cross.x, v_Cross.y, 0.0]) + verts.append([v_Cross.x, v_Cross.y, -dvec.length]) + v_10_Deg_Top_Point = Vector([v_Cross.x, v_Cross.y, -dvec.length]) - #The remain points are stright forward because y is all the same y height (Half_Flat) + # The remain points are stright forward because y is all the same y height (Half_Flat) x = tan(radians(15)) * Half_Flat dvec = vec4 - Vector([x, Half_Flat, 0.0]) Lowest_Point = -dvec.length @@ -1220,16 +1221,13 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA): v_30_Deg_Top_Point = Vector([x, Half_Flat, -dvec.length]) Row += 1 - - #Down Bits + # Down Bits # print ("Point_Distance") # print (Point_Distance) - - - Flange_Adjacent = FLANGE_RADIUS - Point_Distance - if (Flange_Adjacent == 0.0): - Flange_Adjacent = 0.000001 + Flange_Adjacent = FLANGE_RADIUS - Point_Distance + if (Flange_Adjacent == 0.0): + Flange_Adjacent = 0.000001 Flange_Opposite = FLANGE_TAPPER_HEIGHT # print ("Flange_Opposite") @@ -1237,100 +1235,104 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA): # print ("Flange_Adjacent") # print (Flange_Adjacent) - FLANGE_ANGLE_RAD = atan(Flange_Opposite/Flange_Adjacent ) + FLANGE_ANGLE_RAD = atan(Flange_Opposite / Flange_Adjacent) # FLANGE_ANGLE_RAD = radians(45) # print("FLANGE_ANGLE_RAD") # print (degrees (FLANGE_ANGLE_RAD)) - - v_Extended_Flange_Edge = Vector([0.0,0.0,-HEIGHT + FLANGE_HEIGHT + (tan(FLANGE_ANGLE_RAD)* FLANGE_RADIUS) ]) + v_Extended_Flange_Edge = Vector([0.0, 0.0, -HEIGHT + FLANGE_HEIGHT + (tan(FLANGE_ANGLE_RAD) * FLANGE_RADIUS)]) # print("v_Extended_Flange_Edge") # print (v_Extended_Flange_Edge) - #0deg - v_Flange_Edge = Vector([sin(radians(0)) * FLANGE_RADIUS,cos(radians(0)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_0_Deg_Top_Point,Vector([v_0_Deg_Top_Point.x,v_0_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 0deg + v_Flange_Edge = Vector([sin(radians(0)) * FLANGE_RADIUS, cos(radians(0)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_0_Deg_Top_Point, Vector( + [v_0_Deg_Top_Point.x, v_0_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) - #5deg - v_Flange_Edge = Vector([sin(radians(5)) * FLANGE_RADIUS,cos(radians(5)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_5_Deg_Top_Point,Vector([v_5_Deg_Top_Point.x,v_5_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 5deg + v_Flange_Edge = Vector([sin(radians(5)) * FLANGE_RADIUS, cos(radians(5)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_5_Deg_Top_Point, Vector( + [v_5_Deg_Top_Point.x, v_5_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) - #10deg - v_Flange_Edge = Vector([sin(radians(10)) * FLANGE_RADIUS,cos(radians(10)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_10_Deg_Top_Point,Vector([v_10_Deg_Top_Point.x,v_10_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 10deg + v_Flange_Edge = Vector([sin(radians(10)) * FLANGE_RADIUS, cos(radians(10)) + * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_10_Deg_Top_Point, Vector( + [v_10_Deg_Top_Point.x, v_10_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) - #15deg - v_Flange_Edge = Vector([sin(radians(15)) * FLANGE_RADIUS,cos(radians(15)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_15_Deg_Top_Point,Vector([v_15_Deg_Top_Point.x,v_15_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 15deg + v_Flange_Edge = Vector([sin(radians(15)) * FLANGE_RADIUS, cos(radians(15)) + * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_15_Deg_Top_Point, Vector( + [v_15_Deg_Top_Point.x, v_15_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) - - #20deg - v_Flange_Edge = Vector([sin(radians(20)) * FLANGE_RADIUS,cos(radians(20)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_20_Deg_Top_Point,Vector([v_20_Deg_Top_Point.x,v_20_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 20deg + v_Flange_Edge = Vector([sin(radians(20)) * FLANGE_RADIUS, cos(radians(20)) + * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_20_Deg_Top_Point, Vector( + [v_20_Deg_Top_Point.x, v_20_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) - #25deg - v_Flange_Edge = Vector([sin(radians(25)) * FLANGE_RADIUS,cos(radians(25)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_25_Deg_Top_Point,Vector([v_25_Deg_Top_Point.x,v_25_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 25deg + v_Flange_Edge = Vector([sin(radians(25)) * FLANGE_RADIUS, cos(radians(25)) + * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_25_Deg_Top_Point, Vector( + [v_25_Deg_Top_Point.x, v_25_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) - - #30deg - v_Flange_Edge = Vector([sin(radians(30)) * FLANGE_RADIUS,cos(radians(30)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - v_Cross = geometry.intersect_line_line(v_30_Deg_Top_Point,Vector([v_30_Deg_Top_Point.x,v_30_Deg_Top_Point.y,-HEIGHT]),v_Flange_Edge,v_Extended_Flange_Edge) + # 30deg + v_Flange_Edge = Vector([sin(radians(30)) * FLANGE_RADIUS, cos(radians(30)) + * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + v_Cross = geometry.intersect_line_line(v_30_Deg_Top_Point, Vector( + [v_30_Deg_Top_Point.x, v_30_Deg_Top_Point.y, -HEIGHT]), v_Flange_Edge, v_Extended_Flange_Edge) verts.append(v_Cross[0]) Row += 1 - - - verts.append([sin(radians(0)) * FLANGE_RADIUS,cos(radians(0)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT ]) - verts.append([sin(radians(5)) * FLANGE_RADIUS,cos(radians(5)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT]) - verts.append([sin(radians(10)) * FLANGE_RADIUS,cos(radians(10)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT]) - verts.append([sin(radians(15)) * FLANGE_RADIUS,cos(radians(15)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT]) - verts.append([sin(radians(20)) * FLANGE_RADIUS,cos(radians(20)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT]) - verts.append([sin(radians(25)) * FLANGE_RADIUS,cos(radians(25)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT]) - verts.append([sin(radians(30)) * FLANGE_RADIUS,cos(radians(30)) * FLANGE_RADIUS,-HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(0)) * FLANGE_RADIUS, cos(radians(0)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(5)) * FLANGE_RADIUS, cos(radians(5)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(10)) * FLANGE_RADIUS, cos(radians(10)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(15)) * FLANGE_RADIUS, cos(radians(15)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(20)) * FLANGE_RADIUS, cos(radians(20)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(25)) * FLANGE_RADIUS, cos(radians(25)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) + verts.append([sin(radians(30)) * FLANGE_RADIUS, cos(radians(30)) * FLANGE_RADIUS, -HEIGHT + FLANGE_HEIGHT]) Row += 1 - verts.append([sin(radians(0)) * FLANGE_RADIUS,cos(radians(0)) * FLANGE_RADIUS,-HEIGHT]) - verts.append([sin(radians(5)) * FLANGE_RADIUS,cos(radians(5)) * FLANGE_RADIUS,-HEIGHT]) - verts.append([sin(radians(10)) * FLANGE_RADIUS,cos(radians(10)) * FLANGE_RADIUS,-HEIGHT]) - verts.append([sin(radians(15)) * FLANGE_RADIUS,cos(radians(15)) * FLANGE_RADIUS,-HEIGHT]) - verts.append([sin(radians(20)) * FLANGE_RADIUS,cos(radians(20)) * FLANGE_RADIUS,-HEIGHT]) - verts.append([sin(radians(25)) * FLANGE_RADIUS,cos(radians(25)) * FLANGE_RADIUS,-HEIGHT]) - verts.append([sin(radians(30)) * FLANGE_RADIUS,cos(radians(30)) * FLANGE_RADIUS,-HEIGHT]) + verts.append([sin(radians(0)) * FLANGE_RADIUS, cos(radians(0)) * FLANGE_RADIUS, -HEIGHT]) + verts.append([sin(radians(5)) * FLANGE_RADIUS, cos(radians(5)) * FLANGE_RADIUS, -HEIGHT]) + verts.append([sin(radians(10)) * FLANGE_RADIUS, cos(radians(10)) * FLANGE_RADIUS, -HEIGHT]) + verts.append([sin(radians(15)) * FLANGE_RADIUS, cos(radians(15)) * FLANGE_RADIUS, -HEIGHT]) + verts.append([sin(radians(20)) * FLANGE_RADIUS, cos(radians(20)) * FLANGE_RADIUS, -HEIGHT]) + verts.append([sin(radians(25)) * FLANGE_RADIUS, cos(radians(25)) * FLANGE_RADIUS, -HEIGHT]) + verts.append([sin(radians(30)) * FLANGE_RADIUS, cos(radians(30)) * FLANGE_RADIUS, -HEIGHT]) Row += 1 - - verts.append([sin(radians(0)) * SHANK_RADIUS,cos(radians(0)) * SHANK_RADIUS,-HEIGHT]) - verts.append([sin(radians(0)) * SHANK_RADIUS,cos(radians(0)) * SHANK_RADIUS,-HEIGHT]) - verts.append([sin(radians(10)) * SHANK_RADIUS,cos(radians(10)) * SHANK_RADIUS,-HEIGHT]) - verts.append([sin(radians(10)) * SHANK_RADIUS,cos(radians(10)) * SHANK_RADIUS,-HEIGHT]) - verts.append([sin(radians(20)) * SHANK_RADIUS,cos(radians(20)) * SHANK_RADIUS,-HEIGHT]) - verts.append([sin(radians(20)) * SHANK_RADIUS,cos(radians(20)) * SHANK_RADIUS,-HEIGHT]) - verts.append([sin(radians(30)) * SHANK_RADIUS,cos(radians(30)) * SHANK_RADIUS,-HEIGHT]) + verts.append([sin(radians(0)) * SHANK_RADIUS, cos(radians(0)) * SHANK_RADIUS, -HEIGHT]) + verts.append([sin(radians(0)) * SHANK_RADIUS, cos(radians(0)) * SHANK_RADIUS, -HEIGHT]) + verts.append([sin(radians(10)) * SHANK_RADIUS, cos(radians(10)) * SHANK_RADIUS, -HEIGHT]) + verts.append([sin(radians(10)) * SHANK_RADIUS, cos(radians(10)) * SHANK_RADIUS, -HEIGHT]) + verts.append([sin(radians(20)) * SHANK_RADIUS, cos(radians(20)) * SHANK_RADIUS, -HEIGHT]) + verts.append([sin(radians(20)) * SHANK_RADIUS, cos(radians(20)) * SHANK_RADIUS, -HEIGHT]) + verts.append([sin(radians(30)) * SHANK_RADIUS, cos(radians(30)) * SHANK_RADIUS, -HEIGHT]) Row += 1 - faces.extend(Build_Face_List_Quads(FaceStart, 6, Row - 1)) - Spin_Verts, Spin_Faces = SpinDup(verts, faces, 360,12, 'z') + Spin_Verts, Spin_Faces = SpinDup(verts, faces, 360, 12, 'z') return Spin_Verts, Spin_Faces, 0 - (-HEIGHT) -def Create_12_Point_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA): - #TODO add under head radius - return Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA) - +def Create_12_Point_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT, FLANGE_DIA): + # TODO add under head radius + return Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT, FLANGE_DIA) # #################################################################### @@ -1350,7 +1352,7 @@ def Thread_Start3(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, DIV_COUNT, Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 # thread start Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT) @@ -1476,7 +1478,7 @@ def Create_Thread_Start_Verts(INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT, Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT) @@ -1606,7 +1608,7 @@ def Create_Thread_Verts(INNER_DIA, OUTTER_DIA, PITCH, HEIGHT, Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 Height_Offset = Z_LOCATION @@ -1666,7 +1668,7 @@ def Create_Thread_End_Verts(INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT, Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 Row = 0 @@ -1749,27 +1751,27 @@ def Create_External_Thread(SHANK_DIA, SHANK_LENGTH, INNER_DIA, OUTTER_DIA, Offset = 0.0 Shank_Verts, Shank_Row, Offset = Create_Shank_Verts( - SHANK_DIA, OUTTER_DIA, SHANK_LENGTH, - Offset, DIV_COUNT - ) + SHANK_DIA, OUTTER_DIA, SHANK_LENGTH, + Offset, DIV_COUNT + ) Total_Row += Shank_Row Thread_Start_Verts, Thread_Start_Row, Offset = Create_Thread_Start_Verts( - INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT, - ROOT_PERCENT, Offset, DIV_COUNT - ) + INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT, + ROOT_PERCENT, Offset, DIV_COUNT + ) Total_Row += Thread_Start_Row Thread_Verts, Thread_Row, Offset = Create_Thread_Verts( - INNER_DIA, OUTTER_DIA, PITCH, LENGTH, - CREST_PERCENT, ROOT_PERCENT, Offset, DIV_COUNT - ) + INNER_DIA, OUTTER_DIA, PITCH, LENGTH, + CREST_PERCENT, ROOT_PERCENT, Offset, DIV_COUNT + ) Total_Row += Thread_Row Thread_End_Verts, Thread_End_Row, Offset, Lowest_Z_Vert = Create_Thread_End_Verts( - INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT, - ROOT_PERCENT, Offset, DIV_COUNT - ) + INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT, + ROOT_PERCENT, Offset, DIV_COUNT + ) Total_Row += Thread_End_Row verts.extend(Shank_Verts) @@ -1968,7 +1970,7 @@ def add_Nylon_Head(OUTSIDE_RADIUS, Z_LOCATION, DIV_COUNT): sVerts, sFaces = SpinDup(verts, faces, 360, DIV_COUNT, 'z') sVerts.extend(verts) # add the start verts to the Spin verts to complete the loop - faces.extend(Build_Face_List_Quads(FaceStart, Row - 1, DIV_COUNT,1)) + faces.extend(Build_Face_List_Quads(FaceStart, Row - 1, DIV_COUNT, 1)) return Move_Verts_Up_Z(sVerts, 0), faces, Lowest_Z_Vert @@ -2021,9 +2023,8 @@ def add_Nylon_Part(OUTSIDE_RADIUS, Z_LOCATION, DIV_COUNT): return sVerts, faces, 0 - Lowest_Z_Vert -def add_12_Point_Nut(FLAT, HOLE_DIA, HEIGHT,FLANGE_DIA): - return Create_12_Point(FLAT, HOLE_DIA,HOLE_DIA, HEIGHT,FLANGE_DIA) - +def add_12_Point_Nut(FLAT, HOLE_DIA, HEIGHT, FLANGE_DIA): + return Create_12_Point(FLAT, HOLE_DIA, HOLE_DIA, HEIGHT, FLANGE_DIA) # #################################################################### @@ -2045,7 +2046,7 @@ def Create_Internal_Thread_Start_Verts(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV) @@ -2116,7 +2117,7 @@ def Create_Internal_Thread_End_Verts(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT) @@ -2211,16 +2212,16 @@ def Create_Internal_Thread(INNER_DIA, OUTTER_DIA, PITCH, HEIGHT, Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100) Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100) Root_to_Crest_Height = Crest_to_Root_Height = \ - (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 + (float(PITCH) - (Crest_Height + Root_Height)) / 2.0 Height_Offset = 0 FaceStart = len(verts) Row_Inc, Height_Offset = Create_Internal_Thread_Start_Verts( - verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, - DIV_COUNT, CREST_PERCENT, ROOT_PERCENT, - Height_Offset - ) + verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, + DIV_COUNT, CREST_PERCENT, ROOT_PERCENT, + Height_Offset + ) Row += Row_Inc for j in range(Num): @@ -2254,10 +2255,10 @@ def Create_Internal_Thread(INNER_DIA, OUTTER_DIA, PITCH, HEIGHT, Row += 1 Row_Inc, Height_Offset = Create_Internal_Thread_End_Verts( - verts, INNER_RADIUS, OUTTER_RADIUS, - PITCH, CREST_PERCENT, - ROOT_PERCENT, Height_Offset, DIV_COUNT - ) + verts, INNER_RADIUS, OUTTER_RADIUS, + PITCH, CREST_PERCENT, + ROOT_PERCENT, Height_Offset, DIV_COUNT + ) Row += Row_Inc faces.extend(Build_Face_List_Quads(FaceStart, DIV_COUNT, Row - 1, FLIP=1)) @@ -2272,21 +2273,19 @@ def Nut_Mesh(props, context): Head_Verts = [] Head_Faces = [] - Face_Start = len(verts) - if props.bf_Nut_Type == 'bf_Nut_12Pnt': Nut_Height = props.bf_12_Point_Nut_Height else: Nut_Height = props.bf_Hex_Nut_Height Thread_Verts, Thread_Faces, New_Nut_Height = Create_Internal_Thread( - props.bf_Minor_Dia, props.bf_Major_Dia, - props.bf_Pitch, Nut_Height, - props.bf_Crest_Percent, props.bf_Root_Percent, - 1, props.bf_Div_Count - ) + props.bf_Minor_Dia, props.bf_Major_Dia, + props.bf_Pitch, Nut_Height, + props.bf_Crest_Percent, props.bf_Root_Percent, + 1, props.bf_Div_Count + ) verts.extend(Thread_Verts) faces.extend(Copy_Faces(Thread_Faces, Face_Start)) @@ -2294,16 +2293,16 @@ def Nut_Mesh(props, context): if props.bf_Nut_Type == 'bf_Nut_12Pnt': Head_Verts, Head_Faces, Lock_Nut_Rad = add_12_Point_Nut( - props.bf_12_Point_Nut_Flat_Distance, - props.bf_Major_Dia, New_Nut_Height, - #Limit the size of the Flange to avoid calculation error - max(props.bf_12_Point_Nut_Flange_Dia,props.bf_12_Point_Nut_Flat_Distance) - ) + props.bf_12_Point_Nut_Flat_Distance, + props.bf_Major_Dia, New_Nut_Height, + # Limit the size of the Flange to avoid calculation error + max(props.bf_12_Point_Nut_Flange_Dia, props.bf_12_Point_Nut_Flat_Distance) + ) else: Head_Verts, Head_Faces, Lock_Nut_Rad = add_Hex_Nut( - props.bf_Hex_Nut_Flat_Distance, - props.bf_Major_Dia, New_Nut_Height - ) + props.bf_Hex_Nut_Flat_Distance, + props.bf_Major_Dia, New_Nut_Height + ) verts.extend((Head_Verts)) faces.extend(Copy_Faces(Head_Faces, Face_Start)) @@ -2312,17 +2311,17 @@ def Nut_Mesh(props, context): if props.bf_Nut_Type == 'bf_Nut_Lock': Face_Start = len(verts) Nylon_Head_Verts, Nylon_Head_faces, LowZ = add_Nylon_Head( - Lock_Nut_Rad, 0 - New_Nut_Height, - props.bf_Div_Count - ) + Lock_Nut_Rad, 0 - New_Nut_Height, + props.bf_Div_Count + ) verts.extend((Nylon_Head_Verts)) faces.extend(Copy_Faces(Nylon_Head_faces, Face_Start)) Face_Start = len(verts) Nylon_Verts, Nylon_faces, Temp_LowZ = add_Nylon_Part( - Lock_Nut_Rad, 0 - New_Nut_Height, - props.bf_Div_Count - ) + Lock_Nut_Rad, 0 - New_Nut_Height, + props.bf_Div_Count + ) verts.extend((Nylon_Verts)) faces.extend(Copy_Faces(Nylon_faces, Face_Start)) @@ -2352,74 +2351,73 @@ def Bolt_Mesh(props, context): # need to size Allen bit if it is too big. if Allen_Bit_Dia(props.bf_Allen_Bit_Flat_Distance) > Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia): ReSized_Allen_Bit_Flat_Distance = Allen_Bit_Dia_To_Flat( - Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia) - ) + Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia) + ) ReSized_Allen_Bit_Flat_Distance -= ReSized_Allen_Bit_Flat_Distance * 0.05 # It looks better if it is just a bit smaller # print ("Resized Allen Bit Flat Distance to ",ReSized_Allen_Bit_Flat_Distance) # Bit Mesh if props.bf_Bit_Type == 'bf_Bit_Allen': Bit_Verts, Bit_Faces, Bit_Dia = Create_Allen_Bit( - ReSized_Allen_Bit_Flat_Distance, - props.bf_Allen_Bit_Depth - ) + ReSized_Allen_Bit_Flat_Distance, + props.bf_Allen_Bit_Depth + ) if props.bf_Bit_Type == 'bf_Bit_Torx': Bit_Verts, Bit_Faces, Bit_Dia = Create_Torx_Bit( - Torx_Bit_Size_To_Point_Distance(props.bf_Torx_Size_Type), - props.bf_Torx_Bit_Depth - ) - + Torx_Bit_Size_To_Point_Distance(props.bf_Torx_Size_Type), + props.bf_Torx_Bit_Depth + ) if props.bf_Bit_Type == 'bf_Bit_Philips': Bit_Verts, Bit_Faces, Bit_Dia = Create_Phillips_Bit( - props.bf_Philips_Bit_Dia, - props.bf_Philips_Bit_Dia * (0.5 / 1.82), - props.bf_Phillips_Bit_Depth - ) + props.bf_Philips_Bit_Dia, + props.bf_Philips_Bit_Dia * (0.5 / 1.82), + props.bf_Phillips_Bit_Depth + ) # Head Mesh if props.bf_Head_Type == 'bf_Head_Hex': Head_Verts, Head_Faces, Head_Height = Create_Hex_Head( - props.bf_Hex_Head_Flat_Distance, Bit_Dia, - props.bf_Shank_Dia, props.bf_Hex_Head_Height - ) + props.bf_Hex_Head_Flat_Distance, Bit_Dia, + props.bf_Shank_Dia, props.bf_Hex_Head_Height + ) elif props.bf_Head_Type == 'bf_Head_12Pnt': Head_Verts, Head_Faces, Head_Height = Create_12_Point_Head( - props.bf_12_Point_Head_Flat_Distance, Bit_Dia, - props.bf_Shank_Dia, props.bf_12_Point_Head_Height, - #Limit the size of the Flange to avoid calculation error - max(props.bf_12_Point_Head_Flange_Dia,props.bf_12_Point_Head_Flat_Distance) - ) + props.bf_12_Point_Head_Flat_Distance, Bit_Dia, + props.bf_Shank_Dia, props.bf_12_Point_Head_Height, + # Limit the size of the Flange to avoid calculation error + max(props.bf_12_Point_Head_Flange_Dia, props.bf_12_Point_Head_Flat_Distance) + ) elif props.bf_Head_Type == 'bf_Head_Cap': Head_Verts, Head_Faces, Head_Height = Create_Cap_Head( - Bit_Dia, props.bf_Cap_Head_Dia, - props.bf_Shank_Dia, props.bf_Cap_Head_Height, - props.bf_Cap_Head_Dia * (1.0 / 19.0), - props.bf_Cap_Head_Dia * (1.0 / 19.0), - props.bf_Div_Count - ) + Bit_Dia, props.bf_Cap_Head_Dia, + props.bf_Shank_Dia, props.bf_Cap_Head_Height, + props.bf_Cap_Head_Dia * (1.0 / 19.0), + props.bf_Cap_Head_Dia * (1.0 / 19.0), + props.bf_Div_Count + ) elif props.bf_Head_Type == 'bf_Head_Dome': Head_Verts, Head_Faces, Head_Height = Create_Dome_Head( - Bit_Dia, props.bf_Dome_Head_Dia, - props.bf_Shank_Dia, props.bf_Hex_Head_Height, - 1, 1, 0, props.bf_Div_Count - ) + Bit_Dia, props.bf_Dome_Head_Dia, + props.bf_Shank_Dia, props.bf_Hex_Head_Height, + 1, 1, 0, props.bf_Div_Count + ) elif props.bf_Head_Type == 'bf_Head_Pan': Head_Verts, Head_Faces, Head_Height = Create_Pan_Head( - Bit_Dia, props.bf_Pan_Head_Dia, - props.bf_Shank_Dia, - props.bf_Hex_Head_Height, 1, 1, 0, - props.bf_Div_Count - ) + Bit_Dia, props.bf_Pan_Head_Dia, + props.bf_Shank_Dia, + props.bf_Hex_Head_Height, 1, 1, 0, + props.bf_Div_Count + ) elif props.bf_Head_Type == 'bf_Head_CounterSink': Head_Verts, Head_Faces, Head_Height = Create_CounterSink_Head( - Bit_Dia, props.bf_CounterSink_Head_Dia, - props.bf_Shank_Dia, props.bf_CounterSink_Head_Dia, - props.bf_CounterSink_Head_Dia * (0.09 / 6.31), - props.bf_Div_Count - ) + Bit_Dia, props.bf_CounterSink_Head_Dia, + props.bf_Shank_Dia, props.bf_CounterSink_Head_Dia, + props.bf_CounterSink_Head_Dia * (0.09 / 6.31), + props.bf_Div_Count + ) Face_Start = len(verts) verts.extend(Move_Verts_Up_Z(Bit_Verts, Head_Height)) @@ -2431,12 +2429,12 @@ def Bolt_Mesh(props, context): Face_Start = len(verts) Thread_Verts, Thread_Faces, Thread_Height = Create_External_Thread( - props.bf_Shank_Dia, props.bf_Shank_Length, - props.bf_Minor_Dia, props.bf_Major_Dia, - props.bf_Pitch, props.bf_Thread_Length, - props.bf_Crest_Percent, - props.bf_Root_Percent, props.bf_Div_Count - ) + props.bf_Shank_Dia, props.bf_Shank_Length, + props.bf_Minor_Dia, props.bf_Major_Dia, + props.bf_Pitch, props.bf_Thread_Length, + props.bf_Crest_Percent, + props.bf_Root_Percent, props.bf_Div_Count + ) verts.extend(Move_Verts_Up_Z(Thread_Verts, 0)) faces.extend(Copy_Faces(Thread_Faces, Face_Start)) @@ -2444,12 +2442,6 @@ def Bolt_Mesh(props, context): return Move_Verts_Up_Z(verts, Thread_Height), faces - - - - - - def Create_New_Mesh(props, context): verts = [] -- 2.30.2 From fd94ab3159717e1c1c8a93fef560d4a394a63727 Mon Sep 17 00:00:00 2001 From: Loren Osborn Date: Tue, 16 Jul 2024 11:04:09 -0700 Subject: [PATCH 2/2] Fixed scale factor issue * BoltFactory was written with 1mm Blender Units in mind (Blender units are now officially 1m) * Addon already suppoted `GLOBAL_SCALE` constant, but assumed inputs would always be in millimeters. * Since input fields now show units (that are incorrect here) the input field units needed to be converted to Blender units first. * Then converted back to millimeters when constructing the mesh. * Then let the addon scale the result as it expected. --- source/Boltfactory.py | 110 +++++++++++++++++------------------ source/blender_manifest.toml | 2 +- source/createMesh.py | 82 +++++++++++++------------- 3 files changed, 99 insertions(+), 95 deletions(-) diff --git a/source/Boltfactory.py b/source/Boltfactory.py index 26141c2..f62ac76 100644 --- a/source/Boltfactory.py +++ b/source/Boltfactory.py @@ -26,7 +26,7 @@ class add_mesh_bolt(Operator, AddObjectHelper): bl_options = {'REGISTER', 'UNDO', 'PRESET'} bl_description = "Construct many types of Bolts" - MAX_INPUT_NUMBER = 50 + MAX_INPUT_NUMBER = 50 # mm Bolt: BoolProperty(name="Bolt", default=True, @@ -82,39 +82,39 @@ class add_mesh_bolt(Operator, AddObjectHelper): bf_Shank_Length: FloatProperty( attr='bf_Shank_Length', name='Shank Length', default=0, - min=0, soft_min=0, max=MAX_INPUT_NUMBER, + min=0, soft_min=0, max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Length of the unthreaded shank', unit='LENGTH', ) bf_Shank_Dia: FloatProperty( attr='bf_Shank_Dia', - name='Shank Dia', default=3, + name='Shank Dia', default=3 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Diameter of the shank', unit='LENGTH', ) bf_Phillips_Bit_Depth: FloatProperty( attr='bf_Phillips_Bit_Depth', - name='Bit Depth', default=1.1431535482406616, + name='Bit Depth', default=1.1431535482406616 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Depth of the Phillips Bit', unit='LENGTH', ) bf_Allen_Bit_Depth: FloatProperty( attr='bf_Allen_Bit_Depth', - name='Bit Depth', default=1.5, + name='Bit Depth', default=1.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Depth of the Allen Bit', unit='LENGTH', ) bf_Allen_Bit_Flat_Distance: FloatProperty( attr='bf_Allen_Bit_Flat_Distance', - name='Flat Dist', default=2.5, + name='Flat Dist', default=2.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flat Distance of the Allen Bit', unit='LENGTH', ) @@ -136,131 +136,131 @@ class add_mesh_bolt(Operator, AddObjectHelper): ) bf_Torx_Bit_Depth: FloatProperty( attr='bf_Torx_Bit_Depth', - name='Bit Depth', default=1.5, + name='Bit Depth', default=1.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Depth of the Torx Bit', unit='LENGTH', ) bf_Hex_Head_Height: FloatProperty( attr='bf_Hex_Head_Height', - name='Head Height', default=2, - min=0, soft_min=0, max=MAX_INPUT_NUMBER, + name='Head Height', default=2 * createMesh.GLOBAL_SCALE, + min=0, soft_min=0, max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Height of the Hex Head', unit='LENGTH', ) bf_Hex_Head_Flat_Distance: FloatProperty( attr='bf_Hex_Head_Flat_Distance', - name='Flat Dist', default=5.5, + name='Flat Dist', default=5.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flat Distance of the Hex Head', unit='LENGTH', ) bf_12_Point_Head_Height: FloatProperty( attr='bf_12_Point_Head_Height', - name='Head Height', default=3.0, - min=0, soft_min=0, max=MAX_INPUT_NUMBER, + name='Head Height', default=3.0 * createMesh.GLOBAL_SCALE, + min=0, soft_min=0, max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Height of the 12 Point Head', unit='LENGTH', ) bf_12_Point_Head_Flat_Distance: FloatProperty( attr='bf_12_Point_Head_Flat_Distance', - name='Flat Dist', default=3.0, - min=0.001, soft_min=0, # limit to 0.001 to avoid calculation error - max=MAX_INPUT_NUMBER, + name='Flat Dist', default=3.0 * createMesh.GLOBAL_SCALE, + min=0.001 * createMesh.GLOBAL_SCALE, soft_min=0, # limit to 0.001*createMesh.GLOBAL_SCALE to avoid calculation error + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flat Distance of the 12 Point Head', unit='LENGTH', ) bf_12_Point_Head_Flange_Dia: FloatProperty( attr='bf_12_Point_Head_Flange_Dia', - name='12 Point Head Flange Dia', default=5.5, + name='12 Point Head Flange Dia', default=5.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flange diameter of the 12 point Head', unit='LENGTH', ) bf_CounterSink_Head_Dia: FloatProperty( attr='bf_CounterSink_Head_Dia', - name='Head Dia', default=6.300000190734863, + name='Head Dia', default=6.300000190734863 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Diameter of the Counter Sink Head', unit='LENGTH', ) bf_Cap_Head_Height: FloatProperty( attr='bf_Cap_Head_Height', - name='Head Height', default=3, + name='Head Height', default=3 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Height of the Cap Head', unit='LENGTH', ) bf_Cap_Head_Dia: FloatProperty( attr='bf_Cap_Head_Dia', - name='Head Dia', default=5.5, + name='Head Dia', default=5.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Diameter of the Cap Head', unit='LENGTH', ) bf_Dome_Head_Dia: FloatProperty( attr='bf_Dome_Head_Dia', - name='Dome Head Dia', default=5.599999904632568, + name='Dome Head Dia', default=5.599999904632568 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Length of the unthreaded shank', unit='LENGTH', ) bf_Pan_Head_Dia: FloatProperty( attr='bf_Pan_Head_Dia', - name='Pan Head Dia', default=5.599999904632568, + name='Pan Head Dia', default=5.599999904632568 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Diameter of the Pan Head', unit='LENGTH', ) bf_Philips_Bit_Dia: FloatProperty( attr='bf_Philips_Bit_Dia', - name='Bit Dia', default=1.8199999332427979, + name='Bit Dia', default=1.8199999332427979 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Diameter of the Philips Bit', unit='LENGTH', ) bf_Thread_Length: FloatProperty( attr='bf_Thread_Length', - name='Thread Length', default=6, + name='Thread Length', default=6 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Length of the Thread', unit='LENGTH', ) bf_Major_Dia: FloatProperty( attr='bf_Major_Dia', - name='Major Dia', default=3, + name='Major Dia', default=3 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Outside diameter of the Thread', unit='LENGTH', ) bf_Pitch: FloatProperty( attr='bf_Pitch', - name='Pitch', default=0.3499999940395355, - min=0.1, soft_min=0.1, - max=7.0, + name='Pitch', default=0.3499999940395355 * createMesh.GLOBAL_SCALE, + min=0.1 * createMesh.GLOBAL_SCALE, soft_min=0.1 * createMesh.GLOBAL_SCALE, + max=7.0 * createMesh.GLOBAL_SCALE, description='Pitch if the thread', unit='LENGTH', ) bf_Minor_Dia: FloatProperty( attr='bf_Minor_Dia', - name='Minor Dia', default=2.6211137771606445, + name='Minor Dia', default=2.6211137771606445 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Inside diameter of the Thread', unit='LENGTH', ) @@ -287,42 +287,42 @@ class add_mesh_bolt(Operator, AddObjectHelper): ) bf_Hex_Nut_Height: FloatProperty( attr='bf_Hex_Nut_Height', - name='Hex Nut Height', default=2.4000000953674316, + name='Hex Nut Height', default=2.4000000953674316 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Height of the Hex Nut', unit='LENGTH', ) bf_Hex_Nut_Flat_Distance: FloatProperty( attr='bf_Hex_Nut_Flat_Distance', - name='Hex Nut Flat Dist', default=5.5, + name='Hex Nut Flat Dist', default=5.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flat distance of the Hex Nut', unit='LENGTH', ) bf_12_Point_Nut_Height: FloatProperty( attr='bf_12_Point_Nut_Height', - name='12 Point Nut Height', default=2.4000000953674316, + name='12 Point Nut Height', default=2.4000000953674316 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Height of the 12 Point Nut', unit='LENGTH', ) bf_12_Point_Nut_Flat_Distance: FloatProperty( attr='bf_12_Point_Nut_Flat_Distance', - name='12 Point Nut Flat Dist', default=3.0, - min=0.001, soft_min=0, # limit to 0.001 to avoid calculation error - max=MAX_INPUT_NUMBER, + name='12 Point Nut Flat Dist', default=3.0 * createMesh.GLOBAL_SCALE, + min=0.001 * createMesh.GLOBAL_SCALE, soft_min=0, # limit to 0.001 to avoid calculation error + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flat distance of the 12 point Nut', unit='LENGTH', ) bf_12_Point_Nut_Flange_Dia: FloatProperty( attr='bf_12_Point_Nut_Flange_Dia', - name='12 Point Nut Flange Dia', default=5.5, + name='12 Point Nut Flange Dia', default=5.5 * createMesh.GLOBAL_SCALE, min=0, soft_min=0, - max=MAX_INPUT_NUMBER, + max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE, description='Flange diameter of the 12 point Nut', unit='LENGTH', ) diff --git a/source/blender_manifest.toml b/source/blender_manifest.toml index 3fc7d57..10b1ea0 100644 --- a/source/blender_manifest.toml +++ b/source/blender_manifest.toml @@ -1,7 +1,7 @@ schema_version = "1.0.0" id = "boltfactory" name = "BoltFactory" -version = "0.4.0" +version = "0.4.1" tagline = "Add a bolt or nut" maintainer = "Community" type = "add-on" diff --git a/source/createMesh.py b/source/createMesh.py index bdc75f8..83d4355 100644 --- a/source/createMesh.py +++ b/source/createMesh.py @@ -18,7 +18,7 @@ from bpy_extras.object_utils import AddObjectHelper, object_data_add NARROW_UI = 180 MAX_INPUT_NUMBER = 50 -GLOBAL_SCALE = 1 # 1 blender unit = X mm +GLOBAL_SCALE = 0.001 # GLOBAL_SCALE blender unit = 1 mm # next two utility functions are stolen from import_obj.py @@ -2276,13 +2276,13 @@ def Nut_Mesh(props, context): Face_Start = len(verts) if props.bf_Nut_Type == 'bf_Nut_12Pnt': - Nut_Height = props.bf_12_Point_Nut_Height + Nut_Height = props.bf_12_Point_Nut_Height / GLOBAL_SCALE else: - Nut_Height = props.bf_Hex_Nut_Height + Nut_Height = props.bf_Hex_Nut_Height / GLOBAL_SCALE Thread_Verts, Thread_Faces, New_Nut_Height = Create_Internal_Thread( - props.bf_Minor_Dia, props.bf_Major_Dia, - props.bf_Pitch, Nut_Height, + props.bf_Minor_Dia / GLOBAL_SCALE, props.bf_Major_Dia / GLOBAL_SCALE, + props.bf_Pitch / GLOBAL_SCALE, Nut_Height, props.bf_Crest_Percent, props.bf_Root_Percent, 1, props.bf_Div_Count ) @@ -2293,15 +2293,15 @@ def Nut_Mesh(props, context): if props.bf_Nut_Type == 'bf_Nut_12Pnt': Head_Verts, Head_Faces, Lock_Nut_Rad = add_12_Point_Nut( - props.bf_12_Point_Nut_Flat_Distance, - props.bf_Major_Dia, New_Nut_Height, + props.bf_12_Point_Nut_Flat_Distance / GLOBAL_SCALE, + props.bf_Major_Dia / GLOBAL_SCALE, New_Nut_Height, # Limit the size of the Flange to avoid calculation error - max(props.bf_12_Point_Nut_Flange_Dia, props.bf_12_Point_Nut_Flat_Distance) + max(props.bf_12_Point_Nut_Flange_Dia / GLOBAL_SCALE, props.bf_12_Point_Nut_Flat_Distance / GLOBAL_SCALE) ) else: Head_Verts, Head_Faces, Lock_Nut_Rad = add_Hex_Nut( - props.bf_Hex_Nut_Flat_Distance, - props.bf_Major_Dia, New_Nut_Height + props.bf_Hex_Nut_Flat_Distance / GLOBAL_SCALE, + props.bf_Major_Dia / GLOBAL_SCALE, New_Nut_Height ) verts.extend((Head_Verts)) faces.extend(Copy_Faces(Head_Faces, Face_Start)) @@ -2343,15 +2343,19 @@ def Bolt_Mesh(props, context): Head_Faces = [] Head_Height = 0.0 - ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance # set default + ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance / GLOBAL_SCALE # set default - Head_Height = props.bf_Hex_Head_Height # will be changed by the Head Functions + Head_Height = props.bf_Hex_Head_Height / GLOBAL_SCALE # will be changed by the Head Functions if props.bf_Bit_Type == 'bf_Bit_Allen' and props.bf_Head_Type == 'bf_Head_Pan': # need to size Allen bit if it is too big. - if Allen_Bit_Dia(props.bf_Allen_Bit_Flat_Distance) > Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia): + if Allen_Bit_Dia( + props.bf_Allen_Bit_Flat_Distance / + GLOBAL_SCALE) > Max_Pan_Bit_Dia( + props.bf_Pan_Head_Dia / + GLOBAL_SCALE): ReSized_Allen_Bit_Flat_Distance = Allen_Bit_Dia_To_Flat( - Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia) + Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia / GLOBAL_SCALE) ) ReSized_Allen_Bit_Flat_Distance -= ReSized_Allen_Bit_Flat_Distance * 0.05 # It looks better if it is just a bit smaller # print ("Resized Allen Bit Flat Distance to ",ReSized_Allen_Bit_Flat_Distance) @@ -2360,62 +2364,62 @@ def Bolt_Mesh(props, context): if props.bf_Bit_Type == 'bf_Bit_Allen': Bit_Verts, Bit_Faces, Bit_Dia = Create_Allen_Bit( ReSized_Allen_Bit_Flat_Distance, - props.bf_Allen_Bit_Depth + props.bf_Allen_Bit_Depth / GLOBAL_SCALE ) if props.bf_Bit_Type == 'bf_Bit_Torx': Bit_Verts, Bit_Faces, Bit_Dia = Create_Torx_Bit( Torx_Bit_Size_To_Point_Distance(props.bf_Torx_Size_Type), - props.bf_Torx_Bit_Depth + props.bf_Torx_Bit_Depth / GLOBAL_SCALE ) if props.bf_Bit_Type == 'bf_Bit_Philips': Bit_Verts, Bit_Faces, Bit_Dia = Create_Phillips_Bit( - props.bf_Philips_Bit_Dia, - props.bf_Philips_Bit_Dia * (0.5 / 1.82), - props.bf_Phillips_Bit_Depth + props.bf_Philips_Bit_Dia / GLOBAL_SCALE, + props.bf_Philips_Bit_Dia / GLOBAL_SCALE * (0.5 / 1.82), + props.bf_Phillips_Bit_Depth / GLOBAL_SCALE ) # Head Mesh if props.bf_Head_Type == 'bf_Head_Hex': Head_Verts, Head_Faces, Head_Height = Create_Hex_Head( - props.bf_Hex_Head_Flat_Distance, Bit_Dia, - props.bf_Shank_Dia, props.bf_Hex_Head_Height + props.bf_Hex_Head_Flat_Distance / GLOBAL_SCALE, Bit_Dia, + props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Hex_Head_Height / GLOBAL_SCALE ) elif props.bf_Head_Type == 'bf_Head_12Pnt': Head_Verts, Head_Faces, Head_Height = Create_12_Point_Head( - props.bf_12_Point_Head_Flat_Distance, Bit_Dia, - props.bf_Shank_Dia, props.bf_12_Point_Head_Height, + props.bf_12_Point_Head_Flat_Distance / GLOBAL_SCALE, Bit_Dia, + props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_12_Point_Head_Height / GLOBAL_SCALE, # Limit the size of the Flange to avoid calculation error - max(props.bf_12_Point_Head_Flange_Dia, props.bf_12_Point_Head_Flat_Distance) + max(props.bf_12_Point_Head_Flange_Dia / GLOBAL_SCALE, props.bf_12_Point_Head_Flat_Distance / GLOBAL_SCALE) ) elif props.bf_Head_Type == 'bf_Head_Cap': Head_Verts, Head_Faces, Head_Height = Create_Cap_Head( - Bit_Dia, props.bf_Cap_Head_Dia, - props.bf_Shank_Dia, props.bf_Cap_Head_Height, - props.bf_Cap_Head_Dia * (1.0 / 19.0), - props.bf_Cap_Head_Dia * (1.0 / 19.0), + Bit_Dia, props.bf_Cap_Head_Dia / GLOBAL_SCALE, + props.bf_Shank_Dia, props.bf_Cap_Head_Height / GLOBAL_SCALE, + props.bf_Cap_Head_Dia / GLOBAL_SCALE * (1.0 / 19.0), + props.bf_Cap_Head_Dia / GLOBAL_SCALE * (1.0 / 19.0), props.bf_Div_Count ) elif props.bf_Head_Type == 'bf_Head_Dome': Head_Verts, Head_Faces, Head_Height = Create_Dome_Head( - Bit_Dia, props.bf_Dome_Head_Dia, - props.bf_Shank_Dia, props.bf_Hex_Head_Height, + Bit_Dia, props.bf_Dome_Head_Dia / GLOBAL_SCALE, + props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Hex_Head_Height / GLOBAL_SCALE, 1, 1, 0, props.bf_Div_Count ) elif props.bf_Head_Type == 'bf_Head_Pan': Head_Verts, Head_Faces, Head_Height = Create_Pan_Head( - Bit_Dia, props.bf_Pan_Head_Dia, - props.bf_Shank_Dia, - props.bf_Hex_Head_Height, 1, 1, 0, + Bit_Dia, props.bf_Pan_Head_Dia / GLOBAL_SCALE, + props.bf_Shank_Dia / GLOBAL_SCALE, + props.bf_Hex_Head_Height / GLOBAL_SCALE, 1, 1, 0, props.bf_Div_Count ) elif props.bf_Head_Type == 'bf_Head_CounterSink': Head_Verts, Head_Faces, Head_Height = Create_CounterSink_Head( - Bit_Dia, props.bf_CounterSink_Head_Dia, - props.bf_Shank_Dia, props.bf_CounterSink_Head_Dia, - props.bf_CounterSink_Head_Dia * (0.09 / 6.31), + Bit_Dia, props.bf_CounterSink_Head_Dia / GLOBAL_SCALE, + props.bf_Shank_Dia, props.bf_CounterSink_Head_Dia / GLOBAL_SCALE, + props.bf_CounterSink_Head_Dia / GLOBAL_SCALE * (0.09 / 6.31), props.bf_Div_Count ) @@ -2429,9 +2433,9 @@ def Bolt_Mesh(props, context): Face_Start = len(verts) Thread_Verts, Thread_Faces, Thread_Height = Create_External_Thread( - props.bf_Shank_Dia, props.bf_Shank_Length, - props.bf_Minor_Dia, props.bf_Major_Dia, - props.bf_Pitch, props.bf_Thread_Length, + props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Shank_Length / GLOBAL_SCALE, + props.bf_Minor_Dia / GLOBAL_SCALE, props.bf_Major_Dia / GLOBAL_SCALE, + props.bf_Pitch / GLOBAL_SCALE, props.bf_Thread_Length / GLOBAL_SCALE, props.bf_Crest_Percent, props.bf_Root_Percent, props.bf_Div_Count ) -- 2.30.2