1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 from mathutils
import Matrix
22 from bpy
.types
import Operator
23 from bpy_extras
.object_utils
import AddObjectHelper
24 from bpy
.props
import (
32 from . import createMesh
33 from bpy_extras
import object_utils
36 class add_mesh_bolt(Operator
, AddObjectHelper
):
37 bl_idname
= "mesh.bolt_add"
39 bl_options
= {'REGISTER', 'UNDO', 'PRESET'}
40 bl_description
= "Construct many types of Bolts"
45 Bolt
: BoolProperty(name
= "Bolt",
48 change
: BoolProperty(name
= "Change",
50 description
= "change Bolt")
53 Model_Type_List
= [('bf_Model_Bolt', 'BOLT', 'Bolt Model'),
54 ('bf_Model_Nut', 'NUT', 'Nut Model')]
55 bf_Model_Type
: EnumProperty(
58 description
='Choose the type off model you would like',
59 items
=Model_Type_List
, default
='bf_Model_Bolt'
62 Model_Type_List
= [('bf_Head_Hex', 'HEX', 'Hex Head'),
63 ('bf_Head_12Pnt', '12 POINT', '12 Point Head'),
64 ('bf_Head_Cap', 'CAP', 'Cap Head'),
65 ('bf_Head_Dome', 'DOME', 'Dome Head'),
66 ('bf_Head_Pan', 'PAN', 'Pan Head'),
67 ('bf_Head_CounterSink', 'COUNTER SINK', 'Counter Sink Head')]
68 bf_Head_Type
: EnumProperty(
71 description
='Choose the type off Head you would like',
72 items
=Model_Type_List
, default
='bf_Head_Hex'
75 Bit_Type_List
= [('bf_Bit_None', 'NONE', 'No Bit Type'),
76 ('bf_Bit_Allen', 'ALLEN', 'Allen Bit Type'),
77 ('bf_Bit_Torx', 'TORX', 'Torx Bit Type'),
78 ('bf_Bit_Philips', 'PHILLIPS', 'Phillips Bit Type')]
79 bf_Bit_Type
: EnumProperty(
82 description
='Choose the type of bit to you would like',
83 items
=Bit_Type_List
, default
='bf_Bit_None'
86 Nut_Type_List
= [('bf_Nut_Hex', 'HEX', 'Hex Nut'),
87 ('bf_Nut_Lock', 'LOCK', 'Lock Nut'),
88 ('bf_Nut_12Pnt', '12 POINT', '12 Point Nut')]
89 bf_Nut_Type
: EnumProperty(
92 description
='Choose the type of nut you would like',
93 items
=Nut_Type_List
, default
='bf_Nut_Hex'
96 bf_Shank_Length
: FloatProperty(
97 attr
='bf_Shank_Length',
98 name
='Shank Length', default
=0,
99 min=0, soft_min
=0, max=MAX_INPUT_NUMBER
,
100 description
='Length of the unthreaded shank',
103 bf_Shank_Dia
: FloatProperty(
105 name
='Shank Dia', default
=3,
107 max=MAX_INPUT_NUMBER
,
108 description
='Diameter of the shank',
111 bf_Phillips_Bit_Depth
: FloatProperty(
112 attr
='bf_Phillips_Bit_Depth',
113 name
='Bit Depth', default
=1.1431535482406616,
115 max=MAX_INPUT_NUMBER
,
116 description
='Depth of the Phillips Bit',
119 bf_Allen_Bit_Depth
: FloatProperty(
120 attr
='bf_Allen_Bit_Depth',
121 name
='Bit Depth', default
=1.5,
123 max=MAX_INPUT_NUMBER
,
124 description
='Depth of the Allen Bit',
127 bf_Allen_Bit_Flat_Distance
: FloatProperty(
128 attr
='bf_Allen_Bit_Flat_Distance',
129 name
='Flat Dist', default
=2.5,
131 max=MAX_INPUT_NUMBER
,
132 description
='Flat Distance of the Allen Bit',
136 Torx_Size_Type_List
= [('bf_Torx_T10', 'T10', 'T10'),
137 ('bf_Torx_T20', 'T20', 'T20'),
138 ('bf_Torx_T25', 'T25', 'T25'),
139 ('bf_Torx_T30', 'T30', 'T30'),
140 ('bf_Torx_T40', 'T40', 'T40'),
141 ('bf_Torx_T50', 'T50', 'T50'),
142 ('bf_Torx_T55', 'T55', 'T55'),
145 bf_Torx_Size_Type
: EnumProperty(
146 attr
='bf_Torx_Size_Type',
148 description
='Size of the Torx Bit',
149 items
=Torx_Size_Type_List
, default
='bf_Torx_T20'
151 bf_Torx_Bit_Depth
: FloatProperty(
152 attr
='bf_Torx_Bit_Depth',
153 name
='Bit Depth', default
=1.5,
155 max=MAX_INPUT_NUMBER
,
156 description
='Depth of the Torx Bit',
159 bf_Hex_Head_Height
: FloatProperty(
160 attr
='bf_Hex_Head_Height',
161 name
='Head Height', default
=2,
162 min=0, soft_min
=0, max=MAX_INPUT_NUMBER
,
163 description
='Height of the Hex Head',
166 bf_Hex_Head_Flat_Distance
: FloatProperty(
167 attr
='bf_Hex_Head_Flat_Distance',
168 name
='Flat Dist', default
=5.5,
170 max=MAX_INPUT_NUMBER
,
171 description
='Flat Distance of the Hex Head',
174 bf_12_Point_Head_Height
: FloatProperty(
175 attr
='bf_12_Point_Head_Height',
176 name
='Head Height', default
=3.0,
177 min=0, soft_min
=0, max=MAX_INPUT_NUMBER
,
178 description
='Height of the 12 Point Head',
181 bf_12_Point_Head_Flat_Distance
: FloatProperty(
182 attr
='bf_12_Point_Head_Flat_Distance',
183 name
='Flat Dist', default
=3.0,
184 min=0.001, soft_min
=0, #limit to 0.001 to avoid calculation error
185 max=MAX_INPUT_NUMBER
,
186 description
='Flat Distance of the 12 Point Head',
189 bf_12_Point_Head_Flange_Dia
: FloatProperty(
190 attr
='bf_12_Point_Head_Flange_Dia',
191 name
='12 Point Head Flange Dia', default
=5.5,
193 max=MAX_INPUT_NUMBER
,
194 description
='Flange diameter of the 12 point Head',
197 bf_CounterSink_Head_Dia
: FloatProperty(
198 attr
='bf_CounterSink_Head_Dia',
199 name
='Head Dia', default
=6.300000190734863,
201 max=MAX_INPUT_NUMBER
,
202 description
='Diameter of the Counter Sink Head',
205 bf_Cap_Head_Height
: FloatProperty(
206 attr
='bf_Cap_Head_Height',
207 name
='Head Height', default
=3,
209 max=MAX_INPUT_NUMBER
,
210 description
='Height of the Cap Head',
213 bf_Cap_Head_Dia
: FloatProperty(
214 attr
='bf_Cap_Head_Dia',
215 name
='Head Dia', default
=5.5,
217 max=MAX_INPUT_NUMBER
,
218 description
='Diameter of the Cap Head',
221 bf_Dome_Head_Dia
: FloatProperty(
222 attr
='bf_Dome_Head_Dia',
223 name
='Dome Head Dia', default
=5.599999904632568,
225 max=MAX_INPUT_NUMBER
,
226 description
='Length of the unthreaded shank',
229 bf_Pan_Head_Dia
: FloatProperty(
230 attr
='bf_Pan_Head_Dia',
231 name
='Pan Head Dia', default
=5.599999904632568,
233 max=MAX_INPUT_NUMBER
,
234 description
='Diameter of the Pan Head',
238 bf_Philips_Bit_Dia
: FloatProperty(
239 attr
='bf_Philips_Bit_Dia',
240 name
='Bit Dia', default
=1.8199999332427979,
242 max=MAX_INPUT_NUMBER
,
243 description
='Diameter of the Philips Bit',
247 bf_Thread_Length
: FloatProperty(
248 attr
='bf_Thread_Length',
249 name
='Thread Length', default
=6,
251 max=MAX_INPUT_NUMBER
,
252 description
='Length of the Thread',
256 bf_Major_Dia
: FloatProperty(
258 name
='Major Dia', default
=3,
260 max=MAX_INPUT_NUMBER
,
261 description
='Outside diameter of the Thread',
265 bf_Pitch
: FloatProperty(
267 name
='Pitch', default
=0.3499999940395355,
268 min=0.1, soft_min
=0.1,
270 description
='Pitch if the thread',
273 bf_Minor_Dia
: FloatProperty(
275 name
='Minor Dia', default
=2.6211137771606445,
277 max=MAX_INPUT_NUMBER
,
278 description
='Inside diameter of the Thread',
281 bf_Crest_Percent
: IntProperty(
282 attr
='bf_Crest_Percent',
283 name
='Crest Percent', default
=10,
286 description
='Percent of the pitch that makes up the Crest',
288 bf_Root_Percent
: IntProperty(
289 attr
='bf_Root_Percent',
290 name
='Root Percent', default
=10,
293 description
='Percent of the pitch that makes up the Root',
295 bf_Div_Count
: IntProperty(
297 name
='Div count', default
=36,
300 description
='Div count determine circle resolution',
302 bf_Hex_Nut_Height
: FloatProperty(
303 attr
='bf_Hex_Nut_Height',
304 name
='Hex Nut Height', default
=2.4000000953674316,
306 max=MAX_INPUT_NUMBER
,
307 description
='Height of the Hex Nut',
310 bf_Hex_Nut_Flat_Distance
: FloatProperty(
311 attr
='bf_Hex_Nut_Flat_Distance',
312 name
='Hex Nut Flat Dist', default
=5.5,
314 max=MAX_INPUT_NUMBER
,
315 description
='Flat distance of the Hex Nut',
318 bf_12_Point_Nut_Height
: FloatProperty(
319 attr
='bf_12_Point_Nut_Height',
320 name
='12 Point Nut Height', default
=2.4000000953674316,
322 max=MAX_INPUT_NUMBER
,
323 description
='Height of the 12 Point Nut',
327 bf_12_Point_Nut_Flat_Distance
: FloatProperty(
328 attr
='bf_12_Point_Nut_Flat_Distance',
329 name
='12 Point Nut Flat Dist', default
=3.0,
330 min=0.001, soft_min
=0, #limit to 0.001 to avoid calculation error
331 max=MAX_INPUT_NUMBER
,
332 description
='Flat distance of the 12 point Nut',
335 bf_12_Point_Nut_Flange_Dia
: FloatProperty(
336 attr
='bf_12_Point_Nut_Flange_Dia',
337 name
='12 Point Nut Flange Dia', default
=5.5,
339 max=MAX_INPUT_NUMBER
,
340 description
='Flange diameter of the 12 point Nut',
343 def draw(self
, context
):
345 col
= layout
.column()
348 col
.prop(self
, 'bf_Model_Type')
352 if self
.bf_Model_Type
== 'bf_Model_Bolt':
353 col
.prop(self
, 'bf_Bit_Type')
354 if self
.bf_Bit_Type
== 'bf_Bit_None':
356 elif self
.bf_Bit_Type
== 'bf_Bit_Allen':
357 col
.prop(self
, 'bf_Allen_Bit_Depth')
358 col
.prop(self
, 'bf_Allen_Bit_Flat_Distance')
359 elif self
.bf_Bit_Type
== 'bf_Bit_Torx':
360 col
.prop(self
, 'bf_Torx_Bit_Depth')
361 col
.prop(self
, 'bf_Torx_Size_Type')
362 elif self
.bf_Bit_Type
== 'bf_Bit_Philips':
363 col
.prop(self
, 'bf_Phillips_Bit_Depth')
364 col
.prop(self
, 'bf_Philips_Bit_Dia')
367 if self
.bf_Model_Type
== 'bf_Model_Bolt':
368 col
.prop(self
, 'bf_Head_Type')
369 if self
.bf_Head_Type
== 'bf_Head_Hex':
370 col
.prop(self
, 'bf_Hex_Head_Height')
371 col
.prop(self
, 'bf_Hex_Head_Flat_Distance')
372 elif self
.bf_Head_Type
== 'bf_Head_12Pnt':
373 col
.prop(self
, 'bf_12_Point_Head_Height')
374 col
.prop(self
, 'bf_12_Point_Head_Flat_Distance')
375 col
.prop(self
, 'bf_12_Point_Head_Flange_Dia')
376 elif self
.bf_Head_Type
== 'bf_Head_Cap':
377 col
.prop(self
, 'bf_Cap_Head_Height')
378 col
.prop(self
, 'bf_Cap_Head_Dia')
379 elif self
.bf_Head_Type
== 'bf_Head_Dome':
380 col
.prop(self
, 'bf_Dome_Head_Dia')
381 elif self
.bf_Head_Type
== 'bf_Head_Pan':
382 col
.prop(self
, 'bf_Pan_Head_Dia')
383 elif self
.bf_Head_Type
== 'bf_Head_CounterSink':
384 col
.prop(self
, 'bf_CounterSink_Head_Dia')
387 if self
.bf_Model_Type
== 'bf_Model_Bolt':
388 col
.label(text
='Shank')
389 col
.prop(self
, 'bf_Shank_Length')
390 col
.prop(self
, 'bf_Shank_Dia')
393 if self
.bf_Model_Type
== 'bf_Model_Nut':
394 col
.prop(self
, 'bf_Nut_Type')
395 if self
.bf_Nut_Type
== "bf_Nut_12Pnt":
396 col
.prop(self
, 'bf_12_Point_Nut_Height')
397 col
.prop(self
, 'bf_12_Point_Nut_Flat_Distance')
398 col
.prop(self
, 'bf_12_Point_Nut_Flange_Dia')
400 col
.prop(self
, 'bf_Hex_Nut_Height')
401 col
.prop(self
, 'bf_Hex_Nut_Flat_Distance')
406 col
.label(text
='Thread')
407 if self
.bf_Model_Type
== 'bf_Model_Bolt':
408 col
.prop(self
, 'bf_Thread_Length')
409 col
.prop(self
, 'bf_Major_Dia')
410 col
.prop(self
, 'bf_Minor_Dia')
411 col
.prop(self
, 'bf_Pitch')
412 col
.prop(self
, 'bf_Crest_Percent')
413 col
.prop(self
, 'bf_Root_Percent')
414 col
.prop(self
, 'bf_Div_Count')
416 if self
.change
== False:
417 # generic transform props
419 col
.prop(self
, 'align')
420 col
.prop(self
, 'location')
421 col
.prop(self
, 'rotation')
424 def poll(cls
, context
):
425 return context
.scene
is not None
427 def execute(self
, context
):
429 if bpy
.context
.mode
== "OBJECT":
430 if context
.selected_objects
!= [] and context
.active_object
and \
431 (context
.active_object
.data
is not None) and ('Bolt' in context
.active_object
.data
.keys()) and \
432 (self
.change
== True):
433 obj
= context
.active_object
435 oldmeshname
= obj
.data
.name
436 mesh
= createMesh
.Create_New_Mesh(self
, context
)
439 bpy
.ops
.object.vertex_group_remove(all
=True)
443 for material
in oldmesh
.materials
:
444 obj
.data
.materials
.append(material
)
446 bpy
.data
.meshes
.remove(oldmesh
)
447 obj
.data
.name
= oldmeshname
449 mesh
= createMesh
.Create_New_Mesh(self
, context
)
450 obj
= object_utils
.object_data_add(context
, mesh
, operator
=self
)
452 obj
.data
["Bolt"] = True
453 obj
.data
["change"] = False
454 for prm
in BoltParameters():
455 obj
.data
[prm
] = getattr(self
, prm
)
457 if bpy
.context
.mode
== "EDIT_MESH":
458 active_object
= context
.active_object
459 name_active_object
= active_object
.name
460 bpy
.ops
.object.mode_set(mode
='OBJECT')
461 mesh
= createMesh
.Create_New_Mesh(self
, context
)
462 obj
= object_utils
.object_data_add(context
, mesh
, operator
=self
)
465 active_object
.select_set(True)
466 bpy
.ops
.object.join()
467 context
.active_object
.name
= name_active_object
468 bpy
.ops
.object.mode_set(mode
='EDIT')
472 def invoke(self
, context
, event
):
473 self
.execute(context
)
478 def Bolt_contex_menu(self
, context
):
484 if obj
.data
is not None and 'Bolt' in obj
.data
.keys():
485 props
= layout
.operator("mesh.bolt_add", text
="Change Bolt")
487 for prm
in BoltParameters():
488 setattr(props
, prm
, obj
.data
[prm
])
491 def menu_func_bolt(self
, context
):
494 oper
= self
.layout
.operator(add_mesh_bolt
.bl_idname
, text
="Bolt", icon
="MOD_SCREW")
505 bpy
.utils
.register_class(cls
)
506 bpy
.types
.VIEW3D_MT_mesh_add
.append(menu_func_bolt
)
507 bpy
.types
.VIEW3D_MT_object_context_menu
.prepend(Bolt_contex_menu
)
511 bpy
.types
.VIEW3D_MT_object_context_menu
.remove(Bolt_contex_menu
)
512 bpy
.types
.VIEW3D_MT_mesh_add
.remove(menu_func_bolt
)
513 for cls
in reversed(classes
):
514 bpy
.utils
.unregister_class(cls
)
516 def BoltParameters():
524 "bf_Phillips_Bit_Depth",
525 "bf_Allen_Bit_Depth",
526 "bf_Allen_Bit_Flat_Distance",
529 "bf_Hex_Head_Height",
530 "bf_Hex_Head_Flat_Distance",
531 "bf_CounterSink_Head_Dia",
532 "bf_Cap_Head_Height",
536 "bf_Philips_Bit_Dia",
545 "bf_Hex_Nut_Flat_Distance",
547 return BoltParameters