Sun position: remove unused prop in HDRI mode
[blender-addons.git] / add_mesh_BoltFactory / Boltfactory.py
blobf2646704467b1a757ae1a516ac6a67bacf347109
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 #####
20 import bpy
21 from mathutils import Matrix
22 from bpy.types import Operator
23 from bpy_extras.object_utils import AddObjectHelper
24 from bpy.props import (
25 BoolProperty,
26 EnumProperty,
27 FloatProperty,
28 IntProperty,
29 FloatVectorProperty,
30 StringProperty,
32 from . import createMesh
33 from bpy_extras import object_utils
36 class add_mesh_bolt(Operator, AddObjectHelper):
37 bl_idname = "mesh.bolt_add"
38 bl_label = "Add Bolt"
39 bl_options = {'REGISTER', 'UNDO', 'PRESET'}
40 bl_description = "Construct many types of Bolts"
43 MAX_INPUT_NUMBER = 50
45 Bolt : BoolProperty(name = "Bolt",
46 default = True,
47 description = "Bolt")
48 change : BoolProperty(name = "Change",
49 default = False,
50 description = "change Bolt")
52 # Model Types
53 Model_Type_List = [('bf_Model_Bolt', 'BOLT', 'Bolt Model'),
54 ('bf_Model_Nut', 'NUT', 'Nut Model')]
55 bf_Model_Type: EnumProperty(
56 attr='bf_Model_Type',
57 name='Model',
58 description='Choose the type off model you would like',
59 items=Model_Type_List, default='bf_Model_Bolt'
61 # Head Types
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(
69 attr='bf_Head_Type',
70 name='Head',
71 description='Choose the type off Head you would like',
72 items=Model_Type_List, default='bf_Head_Hex'
74 # Bit Types
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(
80 attr='bf_Bit_Type',
81 name='Bit Type',
82 description='Choose the type of bit to you would like',
83 items=Bit_Type_List, default='bf_Bit_None'
85 # Nut Types
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(
90 attr='bf_Nut_Type',
91 name='Nut Type',
92 description='Choose the type of nut you would like',
93 items=Nut_Type_List, default='bf_Nut_Hex'
95 # Shank Types
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',
101 unit='LENGTH',
103 bf_Shank_Dia: FloatProperty(
104 attr='bf_Shank_Dia',
105 name='Shank Dia', default=3,
106 min=0, soft_min=0,
107 max=MAX_INPUT_NUMBER,
108 description='Diameter of the shank',
109 unit='LENGTH',
111 bf_Phillips_Bit_Depth: FloatProperty(
112 attr='bf_Phillips_Bit_Depth',
113 name='Bit Depth', default=1.1431535482406616,
114 min=0, soft_min=0,
115 max=MAX_INPUT_NUMBER,
116 description='Depth of the Phillips Bit',
117 unit='LENGTH',
119 bf_Allen_Bit_Depth: FloatProperty(
120 attr='bf_Allen_Bit_Depth',
121 name='Bit Depth', default=1.5,
122 min=0, soft_min=0,
123 max=MAX_INPUT_NUMBER,
124 description='Depth of the Allen Bit',
125 unit='LENGTH',
127 bf_Allen_Bit_Flat_Distance: FloatProperty(
128 attr='bf_Allen_Bit_Flat_Distance',
129 name='Flat Dist', default=2.5,
130 min=0, soft_min=0,
131 max=MAX_INPUT_NUMBER,
132 description='Flat Distance of the Allen Bit',
133 unit='LENGTH',
135 # Torx Size Types
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',
147 name='Torx Size',
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,
154 min=0, soft_min=0,
155 max=MAX_INPUT_NUMBER,
156 description='Depth of the Torx Bit',
157 unit='LENGTH',
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',
164 unit='LENGTH',
166 bf_Hex_Head_Flat_Distance: FloatProperty(
167 attr='bf_Hex_Head_Flat_Distance',
168 name='Flat Dist', default=5.5,
169 min=0, soft_min=0,
170 max=MAX_INPUT_NUMBER,
171 description='Flat Distance of the Hex Head',
172 unit='LENGTH',
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',
179 unit='LENGTH',
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',
187 unit='LENGTH',
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,
192 min=0, soft_min=0,
193 max=MAX_INPUT_NUMBER,
194 description='Flange diameter of the 12 point Head',
195 unit='LENGTH',
197 bf_CounterSink_Head_Dia: FloatProperty(
198 attr='bf_CounterSink_Head_Dia',
199 name='Head Dia', default=6.300000190734863,
200 min=0, soft_min=0,
201 max=MAX_INPUT_NUMBER,
202 description='Diameter of the Counter Sink Head',
203 unit='LENGTH',
205 bf_Cap_Head_Height: FloatProperty(
206 attr='bf_Cap_Head_Height',
207 name='Head Height', default=3,
208 min=0, soft_min=0,
209 max=MAX_INPUT_NUMBER,
210 description='Height of the Cap Head',
211 unit='LENGTH',
213 bf_Cap_Head_Dia: FloatProperty(
214 attr='bf_Cap_Head_Dia',
215 name='Head Dia', default=5.5,
216 min=0, soft_min=0,
217 max=MAX_INPUT_NUMBER,
218 description='Diameter of the Cap Head',
219 unit='LENGTH',
221 bf_Dome_Head_Dia: FloatProperty(
222 attr='bf_Dome_Head_Dia',
223 name='Dome Head Dia', default=5.599999904632568,
224 min=0, soft_min=0,
225 max=MAX_INPUT_NUMBER,
226 description='Length of the unthreaded shank',
227 unit='LENGTH',
229 bf_Pan_Head_Dia: FloatProperty(
230 attr='bf_Pan_Head_Dia',
231 name='Pan Head Dia', default=5.599999904632568,
232 min=0, soft_min=0,
233 max=MAX_INPUT_NUMBER,
234 description='Diameter of the Pan Head',
235 unit='LENGTH',
238 bf_Philips_Bit_Dia: FloatProperty(
239 attr='bf_Philips_Bit_Dia',
240 name='Bit Dia', default=1.8199999332427979,
241 min=0, soft_min=0,
242 max=MAX_INPUT_NUMBER,
243 description='Diameter of the Philips Bit',
244 unit='LENGTH',
247 bf_Thread_Length: FloatProperty(
248 attr='bf_Thread_Length',
249 name='Thread Length', default=6,
250 min=0, soft_min=0,
251 max=MAX_INPUT_NUMBER,
252 description='Length of the Thread',
253 unit='LENGTH',
256 bf_Major_Dia: FloatProperty(
257 attr='bf_Major_Dia',
258 name='Major Dia', default=3,
259 min=0, soft_min=0,
260 max=MAX_INPUT_NUMBER,
261 description='Outside diameter of the Thread',
262 unit='LENGTH',
265 bf_Pitch: FloatProperty(
266 attr='bf_Pitch',
267 name='Pitch', default=0.3499999940395355,
268 min=0.1, soft_min=0.1,
269 max=7.0,
270 description='Pitch if the thread',
271 unit='LENGTH',
273 bf_Minor_Dia: FloatProperty(
274 attr='bf_Minor_Dia',
275 name='Minor Dia', default=2.6211137771606445,
276 min=0, soft_min=0,
277 max=MAX_INPUT_NUMBER,
278 description='Inside diameter of the Thread',
279 unit='LENGTH',
281 bf_Crest_Percent: IntProperty(
282 attr='bf_Crest_Percent',
283 name='Crest Percent', default=10,
284 min=1, soft_min=1,
285 max=90,
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,
291 min=1, soft_min=1,
292 max=90,
293 description='Percent of the pitch that makes up the Root',
295 bf_Div_Count: IntProperty(
296 attr='bf_Div_Count',
297 name='Div count', default=36,
298 min=4, soft_min=4,
299 max=4096,
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,
305 min=0, soft_min=0,
306 max=MAX_INPUT_NUMBER,
307 description='Height of the Hex Nut',
308 unit='LENGTH',
310 bf_Hex_Nut_Flat_Distance: FloatProperty(
311 attr='bf_Hex_Nut_Flat_Distance',
312 name='Hex Nut Flat Dist', default=5.5,
313 min=0, soft_min=0,
314 max=MAX_INPUT_NUMBER,
315 description='Flat distance of the Hex Nut',
316 unit='LENGTH',
318 bf_12_Point_Nut_Height: FloatProperty(
319 attr='bf_12_Point_Nut_Height',
320 name='12 Point Nut Height', default=2.4000000953674316,
321 min=0, soft_min=0,
322 max=MAX_INPUT_NUMBER,
323 description='Height of the 12 Point Nut',
324 unit='LENGTH',
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',
333 unit='LENGTH',
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,
338 min=0, soft_min=0,
339 max=MAX_INPUT_NUMBER,
340 description='Flange diameter of the 12 point Nut',
341 unit='LENGTH',
343 def draw(self, context):
344 layout = self.layout
345 col = layout.column()
347 # ENUMS
348 col.prop(self, 'bf_Model_Type')
349 col.separator()
351 # Bit
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':
355 pass
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')
365 col.separator()
366 # Head
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')
385 col.separator()
386 # Shank
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')
391 col.separator()
392 # Nut
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')
399 else:
400 col.prop(self, 'bf_Hex_Nut_Height')
401 col.prop(self, 'bf_Hex_Nut_Flat_Distance')
405 # Thread
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
418 col.separator()
419 col.prop(self, 'align')
420 col.prop(self, 'location')
421 col.prop(self, 'rotation')
423 @classmethod
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
434 oldmesh = obj.data
435 oldmeshname = obj.data.name
436 mesh = createMesh.Create_New_Mesh(self, context)
437 obj.data = mesh
438 try:
439 bpy.ops.object.vertex_group_remove(all=True)
440 except:
441 pass
443 for material in oldmesh.materials:
444 obj.data.materials.append(material)
446 bpy.data.meshes.remove(oldmesh)
447 obj.data.name = oldmeshname
448 else:
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)
464 obj.select_set(True)
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')
470 return {'FINISHED'}
472 def invoke(self, context, event):
473 self.execute(context)
475 return {'FINISHED'}
477 # Register:
478 def Bolt_contex_menu(self, context):
479 bl_label = 'Change'
481 obj = context.object
482 layout = self.layout
484 if obj.data is not None and 'Bolt' in obj.data.keys():
485 props = layout.operator("mesh.bolt_add", text="Change Bolt")
486 props.change = True
487 for prm in BoltParameters():
488 setattr(props, prm, obj.data[prm])
489 layout.separator()
491 def menu_func_bolt(self, context):
492 layout = self.layout
493 layout.separator()
494 oper = self.layout.operator(add_mesh_bolt.bl_idname, text="Bolt", icon="MOD_SCREW")
495 oper.change = False
497 classes = (
498 add_mesh_bolt,
503 def register():
504 for cls in classes:
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)
510 def unregister():
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():
517 BoltParameters = [
518 "bf_Model_Type",
519 "bf_Head_Type",
520 "bf_Bit_Type",
521 "bf_Nut_Type",
522 "bf_Shank_Length",
523 "bf_Shank_Dia",
524 "bf_Phillips_Bit_Depth",
525 "bf_Allen_Bit_Depth",
526 "bf_Allen_Bit_Flat_Distance",
527 "bf_Torx_Bit_Depth",
528 "bf_Torx_Size_Type",
529 "bf_Hex_Head_Height",
530 "bf_Hex_Head_Flat_Distance",
531 "bf_CounterSink_Head_Dia",
532 "bf_Cap_Head_Height",
533 "bf_Cap_Head_Dia",
534 "bf_Dome_Head_Dia",
535 "bf_Pan_Head_Dia",
536 "bf_Philips_Bit_Dia",
537 "bf_Thread_Length",
538 "bf_Major_Dia",
539 "bf_Pitch",
540 "bf_Minor_Dia",
541 "bf_Crest_Percent",
542 "bf_Root_Percent",
543 "bf_Div_Count",
544 "bf_Hex_Nut_Height",
545 "bf_Hex_Nut_Flat_Distance",
547 return BoltParameters