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",
49 #### change properties
50 name
: StringProperty(name
= "Name",
53 change
: BoolProperty(name
= "Change",
55 description
= "change Bolt")
58 Model_Type_List
= [('bf_Model_Bolt', 'BOLT', 'Bolt Model'),
59 ('bf_Model_Nut', 'NUT', 'Nut Model')]
60 bf_Model_Type
: EnumProperty(
63 description
='Choose the type off model you would like',
64 items
=Model_Type_List
, default
='bf_Model_Bolt'
67 Model_Type_List
= [('bf_Head_Hex', 'HEX', 'Hex Head'),
68 ('bf_Head_Cap', 'CAP', 'Cap Head'),
69 ('bf_Head_Dome', 'DOME', 'Dome Head'),
70 ('bf_Head_Pan', 'PAN', 'Pan Head'),
71 ('bf_Head_CounterSink', 'COUNTER SINK', 'Counter Sink Head')]
72 bf_Head_Type
: EnumProperty(
75 description
='Choose the type off Head you would like',
76 items
=Model_Type_List
, default
='bf_Head_Hex'
79 Bit_Type_List
= [('bf_Bit_None', 'NONE', 'No Bit Type'),
80 ('bf_Bit_Allen', 'ALLEN', 'Allen Bit Type'),
81 ('bf_Bit_Philips', 'PHILLIPS', 'Phillips Bit Type')]
82 bf_Bit_Type
: EnumProperty(
85 description
='Choose the type of bit to you would like',
86 items
=Bit_Type_List
, default
='bf_Bit_None'
89 Nut_Type_List
= [('bf_Nut_Hex', 'HEX', 'Hex Nut'),
90 ('bf_Nut_Lock', 'LOCK', 'Lock Nut')]
91 bf_Nut_Type
: EnumProperty(
94 description
='Choose the type of nut you would like',
95 items
=Nut_Type_List
, default
='bf_Nut_Hex'
98 bf_Shank_Length
: FloatProperty(
99 attr
='bf_Shank_Length',
100 name
='Shank Length', default
=0,
101 min=0, soft_min
=0, max=MAX_INPUT_NUMBER
,
102 description
='Length of the unthreaded shank',
105 bf_Shank_Dia
: FloatProperty(
107 name
='Shank Dia', default
=3,
109 max=MAX_INPUT_NUMBER
,
110 description
='Diameter of the shank',
113 bf_Phillips_Bit_Depth
: FloatProperty(
114 attr
='bf_Phillips_Bit_Depth',
115 name
='Bit Depth', default
=1.1431535482406616,
117 max=MAX_INPUT_NUMBER
,
118 description
='Depth of the Phillips Bit',
121 bf_Allen_Bit_Depth
: FloatProperty(
122 attr
='bf_Allen_Bit_Depth',
123 name
='Bit Depth', default
=1.5,
125 max=MAX_INPUT_NUMBER
,
126 description
='Depth of the Allen Bit',
129 bf_Allen_Bit_Flat_Distance
: FloatProperty(
130 attr
='bf_Allen_Bit_Flat_Distance',
131 name
='Flat Dist', default
=2.5,
133 max=MAX_INPUT_NUMBER
,
134 description
='Flat Distance of the Allen Bit',
137 bf_Hex_Head_Height
: FloatProperty(
138 attr
='bf_Hex_Head_Height',
139 name
='Head Height', default
=2,
140 min=0, soft_min
=0, max=MAX_INPUT_NUMBER
,
141 description
='Height of the Hex Head',
144 bf_Hex_Head_Flat_Distance
: FloatProperty(
145 attr
='bf_Hex_Head_Flat_Distance',
146 name
='Flat Dist', default
=5.5,
148 max=MAX_INPUT_NUMBER
,
149 description
='Flat Distance of the Hex Head',
152 bf_CounterSink_Head_Dia
: FloatProperty(
153 attr
='bf_CounterSink_Head_Dia',
154 name
='Head Dia', default
=6.300000190734863,
156 max=MAX_INPUT_NUMBER
,
157 description
='Diameter of the Counter Sink Head',
160 bf_Cap_Head_Height
: FloatProperty(
161 attr
='bf_Cap_Head_Height',
162 name
='Head Height', default
=3,
164 max=MAX_INPUT_NUMBER
,
165 description
='Height of the Cap Head',
168 bf_Cap_Head_Dia
: FloatProperty(
169 attr
='bf_Cap_Head_Dia',
170 name
='Head Dia', default
=5.5,
172 max=MAX_INPUT_NUMBER
,
173 description
='Diameter of the Cap Head',
176 bf_Dome_Head_Dia
: FloatProperty(
177 attr
='bf_Dome_Head_Dia',
178 name
='Dome Head Dia', default
=5.599999904632568,
180 max=MAX_INPUT_NUMBER
,
181 description
='Length of the unthreaded shank',
184 bf_Pan_Head_Dia
: FloatProperty(
185 attr
='bf_Pan_Head_Dia',
186 name
='Pan Head Dia', default
=5.599999904632568,
188 max=MAX_INPUT_NUMBER
,
189 description
='Diameter of the Pan Head',
193 bf_Philips_Bit_Dia
: FloatProperty(
194 attr
='bf_Philips_Bit_Dia',
195 name
='Bit Dia', default
=1.8199999332427979,
197 max=MAX_INPUT_NUMBER
,
198 description
='Diameter of the Philips Bit',
202 bf_Thread_Length
: FloatProperty(
203 attr
='bf_Thread_Length',
204 name
='Thread Length', default
=6,
206 max=MAX_INPUT_NUMBER
,
207 description
='Length of the Thread',
211 bf_Major_Dia
: FloatProperty(
213 name
='Major Dia', default
=3,
215 max=MAX_INPUT_NUMBER
,
216 description
='Outside diameter of the Thread',
220 bf_Pitch
: FloatProperty(
222 name
='Pitch', default
=0.3499999940395355,
223 min=0.1, soft_min
=0.1,
225 description
='Pitch if the thread',
228 bf_Minor_Dia
: FloatProperty(
230 name
='Minor Dia', default
=2.6211137771606445,
232 max=MAX_INPUT_NUMBER
,
233 description
='Inside diameter of the Thread',
236 bf_Crest_Percent
: IntProperty(
237 attr
='bf_Crest_Percent',
238 name
='Crest Percent', default
=10,
241 description
='Percent of the pitch that makes up the Crest',
243 bf_Root_Percent
: IntProperty(
244 attr
='bf_Root_Percent',
245 name
='Root Percent', default
=10,
248 description
='Percent of the pitch that makes up the Root',
250 bf_Div_Count
: IntProperty(
252 name
='Div count', default
=36,
255 description
='Div count determine circle resolution',
257 bf_Hex_Nut_Height
: FloatProperty(
258 attr
='bf_Hex_Nut_Height',
259 name
='Hex Nut Height', default
=2.4000000953674316,
261 max=MAX_INPUT_NUMBER
,
262 description
='Height of the Hex Nut',
265 bf_Hex_Nut_Flat_Distance
: FloatProperty(
266 attr
='bf_Hex_Nut_Flat_Distance',
267 name
='Hex Nut Flat Dist', default
=5.5,
269 max=MAX_INPUT_NUMBER
,
270 description
='Flat distance of the Hex Nut',
274 def draw(self
, context
):
276 col
= layout
.column()
279 col
.prop(self
, 'bf_Model_Type')
283 if self
.bf_Model_Type
== 'bf_Model_Bolt':
284 col
.prop(self
, 'bf_Bit_Type')
285 if self
.bf_Bit_Type
== 'bf_Bit_None':
287 elif self
.bf_Bit_Type
== 'bf_Bit_Allen':
288 col
.prop(self
, 'bf_Allen_Bit_Depth')
289 col
.prop(self
, 'bf_Allen_Bit_Flat_Distance')
290 elif self
.bf_Bit_Type
== 'bf_Bit_Philips':
291 col
.prop(self
, 'bf_Phillips_Bit_Depth')
292 col
.prop(self
, 'bf_Philips_Bit_Dia')
295 if self
.bf_Model_Type
== 'bf_Model_Bolt':
296 col
.prop(self
, 'bf_Head_Type')
297 if self
.bf_Head_Type
== 'bf_Head_Hex':
298 col
.prop(self
, 'bf_Hex_Head_Height')
299 col
.prop(self
, 'bf_Hex_Head_Flat_Distance')
300 elif self
.bf_Head_Type
== 'bf_Head_Cap':
301 col
.prop(self
, 'bf_Cap_Head_Height')
302 col
.prop(self
, 'bf_Cap_Head_Dia')
303 elif self
.bf_Head_Type
== 'bf_Head_Dome':
304 col
.prop(self
, 'bf_Dome_Head_Dia')
305 elif self
.bf_Head_Type
== 'bf_Head_Pan':
306 col
.prop(self
, 'bf_Pan_Head_Dia')
307 elif self
.bf_Head_Type
== 'bf_Head_CounterSink':
308 col
.prop(self
, 'bf_CounterSink_Head_Dia')
311 if self
.bf_Model_Type
== 'bf_Model_Bolt':
312 col
.label(text
='Shank')
313 col
.prop(self
, 'bf_Shank_Length')
314 col
.prop(self
, 'bf_Shank_Dia')
317 if self
.bf_Model_Type
== 'bf_Model_Nut':
318 col
.prop(self
, 'bf_Nut_Type')
319 col
.prop(self
, 'bf_Hex_Nut_Height')
320 col
.prop(self
, 'bf_Hex_Nut_Flat_Distance')
322 col
.label(text
='Thread')
323 if self
.bf_Model_Type
== 'bf_Model_Bolt':
324 col
.prop(self
, 'bf_Thread_Length')
325 col
.prop(self
, 'bf_Major_Dia')
326 col
.prop(self
, 'bf_Minor_Dia')
327 col
.prop(self
, 'bf_Pitch')
328 col
.prop(self
, 'bf_Crest_Percent')
329 col
.prop(self
, 'bf_Root_Percent')
330 col
.prop(self
, 'bf_Div_Count')
332 # generic transform props
334 col
.prop(self
, 'align')
335 col
.prop(self
, 'location')
336 col
.prop(self
, 'rotation')
339 def poll(cls
, context
):
340 return context
.scene
is not None
342 def execute(self
, context
):
344 if bpy
.context
.mode
== "OBJECT":
345 if context
.selected_objects
!= [] and context
.active_object
and \
346 ('Bolt' in context
.active_object
.data
.keys()) and (self
.change
== True):
347 obj
= context
.active_object
349 oldmeshname
= obj
.data
.name
350 mesh
= createMesh
.Create_New_Mesh(self
, context
)
353 bpy
.ops
.object.vertex_group_remove(all
=True)
357 for material
in oldmesh
.materials
:
358 obj
.data
.materials
.append(material
)
360 bpy
.data
.meshes
.remove(oldmesh
)
361 obj
.data
.name
= oldmeshname
363 mesh
= createMesh
.Create_New_Mesh(self
, context
)
364 obj
= object_utils
.object_data_add(context
, mesh
, operator
=None)
366 obj
.data
["Bolt"] = True
367 obj
.data
["change"] = False
368 for prm
in BoltParameters():
369 obj
.data
[prm
] = getattr(self
, prm
)
371 if bpy
.context
.mode
== "EDIT_MESH":
372 active_object
= context
.active_object
373 name_active_object
= active_object
.name
374 bpy
.ops
.object.mode_set(mode
='OBJECT')
375 mesh
= createMesh
.Create_New_Mesh(self
, context
)
376 obj
= object_utils
.object_data_add(context
, mesh
, operator
=None)
379 active_object
.select_set(True)
380 bpy
.ops
.object.join()
381 context
.active_object
.name
= name_active_object
382 bpy
.ops
.object.mode_set(mode
='EDIT')
386 def invoke(self
, context
, event
):
387 self
.execute(context
)
392 def Bolt_contex_menu(self
, context
):
398 if 'Bolt' in obj
.data
.keys():
399 props
= layout
.operator("mesh.bolt_add", text
="Change Bolt")
401 for prm
in BoltParameters():
402 setattr(props
, prm
, obj
.data
[prm
])
405 def menu_func_bolt(self
, context
):
408 oper
= self
.layout
.operator(add_mesh_bolt
.bl_idname
, text
="Bolt", icon
="MOD_SCREW")
419 bpy
.utils
.register_class(cls
)
420 bpy
.types
.VIEW3D_MT_mesh_add
.append(menu_func_bolt
)
421 bpy
.types
.VIEW3D_MT_object_context_menu
.prepend(Bolt_contex_menu
)
425 bpy
.types
.VIEW3D_MT_object_context_menu
.remove(Bolt_contex_menu
)
426 bpy
.types
.VIEW3D_MT_mesh_add
.remove(menu_func_bolt
)
427 for cls
in reversed(classes
):
428 bpy
.utils
.unregister_class(cls
)
430 def BoltParameters():
438 "bf_Phillips_Bit_Depth",
439 "bf_Allen_Bit_Depth",
440 "bf_Allen_Bit_Flat_Distance",
441 "bf_Hex_Head_Height",
442 "bf_Hex_Head_Flat_Distance",
443 "bf_CounterSink_Head_Dia",
444 "bf_Cap_Head_Height",
448 "bf_Philips_Bit_Dia",
457 "bf_Hex_Nut_Flat_Distance",
459 return BoltParameters