Newer
Older
#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)
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))
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)
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)
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))
#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*(1.0/19.0))
Face_Start = len(verts)
verts.extend(Move_Verts_Up_Z(Bit_Verts,Head_Height))
faces.extend(Copy_Faces(Bit_Faces,Face_Start))
Face_Start = len(verts)
verts.extend(Move_Verts_Up_Z(Head_Verts,Head_Height))
faces.extend(Copy_Faces(Head_Faces,Face_Start))
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)
verts.extend(Move_Verts_Up_Z(Thread_Verts,00))
faces.extend(Copy_Faces(Thread_Faces,Face_Start))
return Move_Verts_Up_Z(verts,Thread_Height),faces
# calculates the matrix for the new object
# depending on user pref
def align_matrix(context):
loc = Matrix.Translation(context.scene.cursor_location)
obj_align = context.user_preferences.edit.object_align
if (context.space_data.type == 'VIEW_3D'
and obj_align == 'VIEW'):
rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
else:
rot = Matrix()
align_matrix = loc * rot
return align_matrix
# Create a new mesh (object) from verts/edges/faces.
# verts/edges/faces ... List of vertices/edges/faces for the
# new mesh (as used in from_pydata).
# name ... Name of the new mesh (& object).
# edit ... Replace existing mesh data.
# Note: Using "edit" will destroy/delete existing mesh data.
def create_mesh_object(context, verts, edges, faces, name, edit, align_matrix):
scene = context.scene
obj_act = scene.objects.active
# Can't edit anything, unless we have an active obj.
if edit and not obj_act:
return None
# Create new mesh
mesh = bpy.data.meshes.new(name)
# Make a mesh from a list of verts/edges/faces.
mesh.from_pydata(verts, edges, faces)
# Update mesh geometry after adding stuff.
mesh.update()
# Deselect all objects when in object mode
if bpy.ops.object.select_all.poll():
bpy.ops.object.select_all(action='DESELECT')
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
if edit:
# Replace geometry of existing object
# Use the active obj and select it.
ob_new = obj_act
ob_new.select = True
if obj_act.mode == 'OBJECT':
# Get existing mesh datablock.
old_mesh = ob_new.data
# Set object data to nothing
ob_new.data = None
# Clear users of existing mesh datablock.
old_mesh.user_clear()
# Remove old mesh datablock if no users are left.
if (old_mesh.users == 0):
bpy.data.meshes.remove(old_mesh)
# Assign new mesh datablock.
ob_new.data = mesh
else:
# Create new object
ob_new = bpy.data.objects.new(name, mesh)
# Link new object to the given scene and select it.
scene.objects.link(ob_new)
ob_new.select = True
# Place the object at the 3D cursor location.
# apply viewRotaion
ob_new.matrix_world = align_matrix
if obj_act and obj_act.mode == 'EDIT':
if not edit:
# We are in EditMode, switch to ObjectMode.
bpy.ops.object.mode_set(mode='OBJECT')
# Select the active object as well.
obj_act.select = True
# Apply location of new object.
scene.update()
# Join new object into the active.
bpy.ops.object.join()
# Switching back to EditMode.
bpy.ops.object.mode_set(mode='EDIT')
ob_new = obj_act
else:
# We are in ObjectMode.
# Make the new object the active one.
scene.objects.active = ob_new
return ob_new
def Create_New_Mesh(props, context, align_matrix):
verts = []
faces = []
sObjName =''
if props.bf_Model_Type == 'bf_Model_Bolt':
#print('Create Bolt')
verts, faces = Bolt_Mesh(props, context)
sObjName = 'Bolt'
if props.bf_Model_Type == 'bf_Model_Nut':
#print('Create Nut')
verts, faces = Nut_Mesh(props, context)
sObjName = 'Nut'
verts, faces = RemoveDoubles(verts, faces)
verts = Scale_Mesh_Verts(verts,GLOBAL_SCALE)
obj = create_mesh_object(context, verts, [], faces,sObjName,
props.edit, align_matrix)