Newer
Older
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
from bpy.types import Operator
from bpy.props import (
BoolProperty,
EnumProperty,
FloatProperty,
IntProperty,
StringProperty,
from bpy_extras import object_utils
bl_idname = "mesh.bolt_add"
bl_description = "Construct many types of Bolts"
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')]
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_Cap', 'CAP', 'Cap Head'),
('bf_Head_Dome', 'DOME', 'Dome Head'),
('bf_Head_Pan', 'PAN', 'Pan Head'),
('bf_Head_CounterSink', 'COUNTER SINK', 'Counter Sink Head')]
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_Philips', 'PHILLIPS', 'Phillips 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')]
name='Nut Type',
description='Choose the type of nut you would like',
items=Nut_Type_List, default='bf_Nut_Hex'
)
# Shank Types
attr='bf_Shank_Length',
name='Shank Length', default=0,
min=0, soft_min=0, max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Length of the unthreaded shank',
unit='LENGTH',
attr='bf_Shank_Dia',
name='Shank Dia', default=3,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
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,
Spivak Vladimir (cwolf3d)
committed
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,
Spivak Vladimir (cwolf3d)
committed
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,
Spivak Vladimir (cwolf3d)
committed
description='Flat Distance of the Allen 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,
Spivak Vladimir (cwolf3d)
committed
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,
Spivak Vladimir (cwolf3d)
committed
description='Flat Distance of the Hex Head',
unit='LENGTH',
bf_CounterSink_Head_Dia: FloatProperty(
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Diameter of the Counter Sink Head',
unit='LENGTH',
bf_Cap_Head_Height: FloatProperty(
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Height of the Cap Head',
unit='LENGTH',
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Diameter of the Cap Head',
unit='LENGTH',
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Length of the unthreaded shank',
unit='LENGTH',
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
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,
Spivak Vladimir (cwolf3d)
committed
description='Diameter of the Philips Bit',
unit='LENGTH',
)
attr='bf_Thread_Length',
name='Thread Length', default=6,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Length of the Thread',
unit='LENGTH',
)
attr='bf_Major_Dia',
name='Major Dia', default=3,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Outside diameter of the Thread',
unit='LENGTH',
)
min=0.1, soft_min=0.1,
max=7.0,
Spivak Vladimir (cwolf3d)
committed
description='Pitch if the thread',
unit='LENGTH',
attr='bf_Minor_Dia',
name='Minor Dia', default=2.6211137771606445,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
description='Inside diameter of the Thread',
unit='LENGTH',
attr='bf_Crest_Percent',
name='Crest Percent', default=10,
min=1, soft_min=1,
max=90,
Spivak Vladimir (cwolf3d)
committed
description='Percent of the pitch that makes up the Crest',
attr='bf_Root_Percent',
name='Root Percent', default=10,
min=1, soft_min=1,
max=90,
Spivak Vladimir (cwolf3d)
committed
description='Percent of the pitch that makes up the Root',
attr='bf_Div_Count',
name='Div count', default=36,
min=4, soft_min=4,
max=4096,
Spivak Vladimir (cwolf3d)
committed
description='Div count determine circle resolution',
bf_Hex_Nut_Height: FloatProperty(
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
Spivak Vladimir (cwolf3d)
committed
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,
Spivak Vladimir (cwolf3d)
committed
description='Flat distance of the Hex Nut',
unit='LENGTH',
def draw(self, context):
layout = self.layout
col = layout.column()
Campbell Barton
committed
col.prop(self, 'bf_Model_Type')
Thomas Dinges
committed
if self.bf_Model_Type == 'bf_Model_Bolt':
Campbell Barton
committed
col.prop(self, 'bf_Bit_Type')
Thomas Dinges
committed
if self.bf_Bit_Type == 'bf_Bit_None':
Thomas Dinges
committed
elif self.bf_Bit_Type == 'bf_Bit_Allen':
Campbell Barton
committed
col.prop(self, 'bf_Allen_Bit_Depth')
col.prop(self, 'bf_Allen_Bit_Flat_Distance')
Thomas Dinges
committed
elif self.bf_Bit_Type == 'bf_Bit_Philips':
Campbell Barton
committed
col.prop(self, 'bf_Phillips_Bit_Depth')
col.prop(self, 'bf_Philips_Bit_Dia')
Thomas Dinges
committed
if self.bf_Model_Type == 'bf_Model_Bolt':
Campbell Barton
committed
col.prop(self, 'bf_Head_Type')
Thomas Dinges
committed
if self.bf_Head_Type == 'bf_Head_Hex':
Campbell Barton
committed
col.prop(self, 'bf_Hex_Head_Height')
col.prop(self, 'bf_Hex_Head_Flat_Distance')
Thomas Dinges
committed
elif self.bf_Head_Type == 'bf_Head_Cap':
Campbell Barton
committed
col.prop(self, 'bf_Cap_Head_Height')
col.prop(self, 'bf_Cap_Head_Dia')
Thomas Dinges
committed
elif self.bf_Head_Type == 'bf_Head_Dome':
Campbell Barton
committed
col.prop(self, 'bf_Dome_Head_Dia')
Thomas Dinges
committed
elif self.bf_Head_Type == 'bf_Head_Pan':
Campbell Barton
committed
col.prop(self, 'bf_Pan_Head_Dia')
Thomas Dinges
committed
elif self.bf_Head_Type == 'bf_Head_CounterSink':
Campbell Barton
committed
col.prop(self, 'bf_CounterSink_Head_Dia')
Thomas Dinges
committed
if self.bf_Model_Type == 'bf_Model_Bolt':
Campbell Barton
committed
col.prop(self, 'bf_Shank_Length')
col.prop(self, 'bf_Shank_Dia')
Thomas Dinges
committed
if self.bf_Model_Type == 'bf_Model_Nut':
Campbell Barton
committed
col.prop(self, 'bf_Nut_Type')
col.prop(self, 'bf_Hex_Nut_Height')
col.prop(self, 'bf_Hex_Nut_Flat_Distance')
Thomas Dinges
committed
if self.bf_Model_Type == 'bf_Model_Bolt':
Campbell Barton
committed
col.prop(self, 'bf_Thread_Length')
col.prop(self, 'bf_Major_Dia')
col.prop(self, 'bf_Minor_Dia')
col.prop(self, 'bf_Pitch')
col.prop(self, 'bf_Crest_Percent')
col.prop(self, 'bf_Root_Percent')
col.prop(self, 'bf_Div_Count')
if self.change == False:
# generic transform props
col.separator()
col.prop(self, 'align')
col.prop(self, 'location')
col.prop(self, 'rotation')
@classmethod
def poll(cls, context):
return context.scene is not None
if bpy.context.mode == "OBJECT":
if context.selected_objects != [] and context.active_object and \
('Bolt' in context.active_object.data.keys()) and (self.change == True):
obj = context.active_object
oldmesh = obj.data
oldmeshname = obj.data.name
mesh = createMesh.Create_New_Mesh(self, context)
obj.data = mesh
try:
bpy.ops.object.vertex_group_remove(all=True)
except:
pass
for material in oldmesh.materials:
obj.data.materials.append(material)
bpy.data.meshes.remove(oldmesh)
obj.data.name = oldmeshname
else:
mesh = createMesh.Create_New_Mesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.data["Bolt"] = True
obj.data["change"] = False
for prm in BoltParameters():
obj.data[prm] = getattr(self, prm)
if bpy.context.mode == "EDIT_MESH":
active_object = context.active_object
name_active_object = active_object.name
bpy.ops.object.mode_set(mode='OBJECT')
mesh = createMesh.Create_New_Mesh(self, context)
obj = object_utils.object_data_add(context, mesh, operator=self)
obj.select_set(True)
active_object.select_set(True)
bpy.ops.object.join()
context.active_object.name = name_active_object
bpy.ops.object.mode_set(mode='EDIT')
def invoke(self, context, event):
self.execute(context)
return {'FINISHED'}
def Bolt_contex_menu(self, context):
bl_label = 'Change'
obj = context.object
layout = self.layout
if 'Bolt' in obj.data.keys():
props = layout.operator("mesh.bolt_add", text="Change Bolt")
props.change = True
for prm in BoltParameters():
setattr(props, prm, obj.data[prm])
layout.separator()
layout = self.layout
layout.separator()
oper = self.layout.operator(add_mesh_bolt.bl_idname, text="Bolt", icon="MOD_SCREW")
oper.change = False
bpy.utils.register_class(cls)
bpy.types.VIEW3D_MT_object_context_menu.prepend(Bolt_contex_menu)
bpy.types.VIEW3D_MT_object_context_menu.remove(Bolt_contex_menu)
bpy.types.VIEW3D_MT_mesh_add.remove(menu_func_bolt)
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
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_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