WIP: white space changes to BoltFactory to fix flake8 #105083

Draft
sw-tya wants to merge 3 commits from sw-tya/blender-addons:flake8_bolts into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 237 additions and 246 deletions

View File

@ -26,7 +26,6 @@ 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",
@ -327,6 +326,7 @@ class add_mesh_bolt(Operator, AddObjectHelper):
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':
@ -467,6 +465,7 @@ class add_mesh_bolt(Operator, AddObjectHelper):
return {'FINISHED'}
# Register:
def Bolt_contex_menu(self, context):
bl_label = 'Change'
@ -481,18 +480,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,6 +506,7 @@ def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
def BoltParameters():
BoltParameters = [
"bf_Model_Type",

View File

@ -28,12 +28,10 @@ import bpy
# ### REGISTER ###
def register():
Boltfactory.register()
def unregister():
Boltfactory.unregister()

View File

@ -272,6 +272,7 @@ def Fill_Ring_Face(OFFSET, NUM, FACE_DOWN=0):
Face[2] = TempFace[2]
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 = []
@ -296,10 +297,10 @@ def Fill_Fan_Face(OFFSET, NUM, FACE_DOWN=0):
Face[2] = TempFace[2]
return Ret
# ####################################################################
# Create Allen Bit
# ####################################################################
def Allen_Fill(OFFSET, FLIP=0):
faces = []
Lookup = [[19, 1, 0],
@ -388,10 +389,11 @@ def Create_Allen_Bit(FLAT_DISTANCE, HEIGHT):
faces.extend(M_Faces)
return verts, faces, OUTTER_RADIUS * 2.0
# ####################################################################
# Create Torx Bit
# ####################################################################
def Torx_Bit_Size_To_Point_Distance(Bit_Size):
if Bit_Size == 'bf_Torx_T10':
return 2.83
@ -410,6 +412,7 @@ def Torx_Bit_Size_To_Point_Distance(Bit_Size):
else:
return 2.83 # default to M3
def Torx_Fill(OFFSET, FLIP=0):
faces = []
Lookup = [[0, 10, 11],
@ -435,7 +438,6 @@ def Torx_Fill(OFFSET, FLIP=0):
[3, 24, 25],
[3, 25, 4],
[4, 25, 26],
[4, 26, 27],
[4, 27, 28],
@ -482,7 +484,6 @@ def Torx_Fill(OFFSET, FLIP=0):
return faces
def Create_Torx_Bit(Point_Distance, HEIGHT):
verts = []
faces = []
@ -558,10 +559,10 @@ def Create_Torx_Bit(Point_Distance, HEIGHT):
return verts, faces, OUTTER_RADIUS * 2.0
# ####################################################################
# Create Phillips Bit
# ####################################################################
def Phillips_Fill(OFFSET, FLIP=0):
faces = []
Lookup = [[0, 1, 10],
@ -640,7 +641,6 @@ def Create_Phillips_Bit(FLAT_DIA, FLAT_WIDTH, HEIGHT):
# ####################################################################
# Create Head Types
# ####################################################################
def Max_Pan_Bit_Dia(HEAD_DIA):
HEAD_RADIUS = HEAD_DIA * 0.5
XRad = HEAD_RADIUS * 1.976
@ -1059,7 +1059,6 @@ 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
@ -1120,8 +1119,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,12 +1157,12 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA):
Row += 1
# 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
v_15Deg_Point = Vector([tan(radians(15)) * Half_Flat, Half_Flat, 0.0])
# This is a known point to work back from
x = tan(radians(0)) * Half_Flat
Point_Distance = (tan(radians(30)) * v_15Deg_Point.x) + Half_Flat
@ -1220,13 +1217,10 @@ 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
# print ("Point_Distance")
# print (Point_Distance)
Flange_Adjacent = FLANGE_RADIUS - Point_Distance
if (Flange_Adjacent == 0.0):
Flange_Adjacent = 0.000001
@ -1242,52 +1236,68 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA):
# 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)])
# 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)
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)
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)
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)
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)
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)
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)
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])
@ -1308,7 +1318,6 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA):
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])
@ -1319,7 +1328,6 @@ def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA):
Row += 1
faces.extend(Build_Face_List_Quads(FaceStart, 6, Row - 1))
Spin_Verts, Spin_Faces = SpinDup(verts, faces, 360, 12, 'z')
@ -1332,12 +1340,9 @@ def Create_12_Point_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT,FLANGE_DIA):
return Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT, FLANGE_DIA)
# ####################################################################
# Create External Thread
# ####################################################################
def Thread_Start3(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, DIV_COUNT,
CREST_PERCENT, ROOT_PERCENT, Height_Offset):
@ -1349,8 +1354,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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
# thread start
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT)
@ -1475,8 +1479,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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT)
@ -1605,8 +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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Height_Offset = Z_LOCATION
@ -1665,8 +1667,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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Row = 0
@ -2025,11 +2026,9 @@ def add_12_Point_Nut(FLAT, HOLE_DIA, HEIGHT,FLANGE_DIA):
return Create_12_Point(FLAT, HOLE_DIA, HOLE_DIA, HEIGHT, FLANGE_DIA)
# ####################################################################
# Create Internal Thread
# ####################################################################
def Create_Internal_Thread_Start_Verts(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, DIV,
CREST_PERCENT, ROOT_PERCENT, Height_Offset):
@ -2044,8 +2043,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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV)
@ -2115,8 +2113,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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT)
@ -2210,8 +2207,7 @@ 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
Root_to_Crest_Height = Crest_to_Root_Height = (float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Height_Offset = 0
FaceStart = len(verts)
@ -2272,10 +2268,8 @@ 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:
@ -2297,7 +2291,8 @@ def Nut_Mesh(props, context):
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)
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(
@ -2354,7 +2349,8 @@ def Bolt_Mesh(props, context):
ReSized_Allen_Bit_Flat_Distance = Allen_Bit_Dia_To_Flat(
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
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
@ -2370,7 +2366,6 @@ def Bolt_Mesh(props, context):
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,
@ -2389,7 +2384,8 @@ def Bolt_Mesh(props, context):
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)
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(
@ -2444,12 +2440,8 @@ def Bolt_Mesh(props, context):
return Move_Verts_Up_Z(verts, Thread_Height), faces
# ###### New Mesh
#
def Create_New_Mesh(props, context):
verts = []