├── README.md ├── fastener_holes_icon.svg └── fastener_holes.FCMacro /README.md: -------------------------------------------------------------------------------- 1 | # FreeCAD_Fastener_holes 2 | This macro creates shapes to act as holes when cut to other shapes. It makes easy and fast the creation and tweaking of all needed parts. It may be very useful when designing parts for 3D printing and others. 3 | 4 | ## Example 5 | 6 | Base part: 7 | 8 |  9 | 10 | Creating holes with the macro by preselecting faces, edges and points to easily place them: 11 | 12 |  13 | 14 | Selecting the holes and creating a boolean operation into the base part: 15 | 16 |  17 | 18 | Finally, using [Fasteners workbench](https://www.freecadweb.org/wiki/Fasteners_Workbench) you can easily add the fasteners themselves: 19 | 20 |  21 | 22 | More information here: https://www.freecadweb.org/wiki/Fastener_holes 23 | 24 | ## LICENSE 25 | Copyright (c) 2020 Pablo Gil Fernández 26 | 27 | This work is licensed under GNU Lesser General Public License (LGPL). 28 | To view a copy of this license, visit https://www.gnu.org/licenses/lgpl-3.0.html 29 | -------------------------------------------------------------------------------- /fastener_holes_icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 332 | -------------------------------------------------------------------------------- /fastener_holes.FCMacro: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # ==================================================================================== 5 | # ==================================================================================== 6 | # == == 7 | # == Fastener holes == 8 | # == == 9 | # ==================================================================================== 10 | # ==================================================================================== 11 | # ABOUT 12 | # ==================================================================================== 13 | # Macro developed for FreeCAD (https://www.freecadweb.org/). 14 | # This macro creates shapes to act as holes when cut to other shapes. 15 | # It makes easy and fast the creation and tweaking of all needed parts. 16 | # It may be very useful when designing parts for 3D printing and others. 17 | # 18 | # LICENSE 19 | # ==================================================================================== 20 | # Copyright (c) 2020 Pablo Gil Fernandez 21 | # 22 | # This work is licensed under GNU Lesser General Public License (LGPL). 23 | # To view a copy of this license, visit https://www.gnu.org/licenses/lgpl-3.0.html 24 | # 25 | # ==================================================================================== 26 | __title__ = "Fastener holes" 27 | __author__ = "Pablo Gil Fernández" 28 | __version__ = "11.00" 29 | __date__ = "20/02/2020" 30 | 31 | __Comment__ = "This macro creates shapes to act as holes when cut to other shapes. It makes easy and fast the creation and tweaking of all needed parts. It may be very useful when designing parts for 3D printing and others." 32 | 33 | __Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Fastener_holes" 34 | __Help__ = "" 35 | __Status__ = "stable" 36 | __Requires__ = "freecad 0.17" 37 | 38 | import FreeCAD, FreeCADGui, Draft, Part, PartGui, math, PartDesignGui 39 | from FreeCAD import Base 40 | from PySide import QtGui, QtCore 41 | from math import cos, radians 42 | from pivy import coin 43 | import sys 44 | App = FreeCAD 45 | Gui = FreeCADGui 46 | 47 | ##-------------------------------------------------------------------------------------- 48 | def a_clear_console(): 49 | #clearing previous messages 50 | mw=FreeCADGui.getMainWindow() 51 | # c=mw.findChild(QtGui.QPlainTextEdit, "Python console") 52 | # c.clear() 53 | r=mw.findChild(QtGui.QTextEdit, "Report view") 54 | r.clear() 55 | #if not Mod_ENABLED: 56 | a_clear_console() 57 | 58 | sizeX = 360 59 | sizeY = 370 60 | 61 | def close_dock(): 62 | #def closeEvent(self, e): 63 | ALGDockWidget.close() 64 | #self.setWindowState(QtCore.Qt.WindowActive) 65 | doc=FreeCAD.ActiveDocument 66 | if doc is not None: 67 | FreeCAD.setActiveDocument(doc.Name) 68 | #FreeCAD.ActiveDocument=FreeCAD.getDocument(doc.Label) 69 | #FreeCADGui.ActiveDocument=FreeCADGui.getDocument(doc.Label) 70 | 71 | def Alg_undock(): 72 | ALGDockWidget.setFloating(True) #undock 73 | ALGDockWidget.resize(sizeX,sizeY) 74 | ALGDockWidget.activateWindow() 75 | ALGDockWidget.raise_() 76 | #AlgWidget.resize(QtCore.QSize(300,100).expandedTo(AlgWidget.maximumSize())) # sets size of the widget 77 | #AlgWidget.setFloating(False) #dock 78 | #say ("now!") 79 | 80 | def Alg_minimz(): 81 | #clear_console() 82 | ALGDockWidget.setFloating(True) #undock 83 | # AlgWidget.hide(); 84 | # AlgWidget.setWindowState(QtCore.Qt.WindowMinimized) 85 | #AlgWidget.resize(500, 500) 86 | ALGDockWidget.resize(sizeX,sizeY) 87 | ALGDockWidget.activateWindow() 88 | ALGDockWidget.raise_() 89 | 90 | def pointAt(normal, up): 91 | z = normal 92 | y = up 93 | x = y.cross(z) 94 | y = z.cross(x) 95 | 96 | rot = App.Matrix() 97 | rot.A11 = x.x 98 | rot.A21 = x.y 99 | rot.A31 = x.z 100 | 101 | rot.A12 = y.x 102 | rot.A22 = y.y 103 | rot.A32 = y.z 104 | 105 | rot.A13 = z.x 106 | rot.A23 = z.y 107 | rot.A33 = z.z 108 | 109 | return App.Placement(rot).Rotation 110 | 111 | 112 | # ############################################################## 113 | # global initial_placement, last_selection 114 | # global moving, rotating 115 | # global objs_moved, plc_moved 116 | # 117 | # #init 118 | # initial_placement = FreeCAD.Placement(App.Vector(0,0,0), App.Rotation(0,0,0), App.Vector(0,0,0)) #Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)] 119 | # moving = [] #[App.Vector(0,0,0)] 120 | # rotating = [] #[0, App.Vector(0,0,0), App.Vector(0,0,0)] 121 | # objs_moved = [] 122 | # plc_moved = [] 123 | # #Draft.rotate(objs[j],-rot_angle,rot_center,rot_axis) 124 | # #rotating=[rot_angle,rot_center,rot_axis] 125 | # 126 | # last_selection = [] 127 | # 128 | # ################################################################# 129 | 130 | def say(msg): 131 | FreeCAD.Console.PrintMessage(msg) 132 | FreeCAD.Console.PrintMessage('\n') 133 | 134 | def sayw(msg): 135 | FreeCAD.Console.PrintWarning(msg) 136 | FreeCAD.Console.PrintWarning('\n') 137 | 138 | def sayerr(msg): 139 | FreeCAD.Console.PrintError(msg) 140 | FreeCAD.Console.PrintWarning('\n') 141 | 142 | def make_string(input): 143 | if (sys.version_info > (3, 0)): #py3 144 | if isinstance(input, str): 145 | return input 146 | else: 147 | input = input.encode('utf-8') 148 | return input 149 | else: #py2 150 | if type(input) == unicode: 151 | input = input.encode('utf-8') 152 | return input 153 | else: 154 | return input 155 | 156 | #sayw("Fastener holes v" + str(__version__)) 157 | 158 | ############################################################################################################### 159 | class Ui_DockWidget(object): 160 | def setupUi(self, DockWidget): 161 | infoIcon = ['16 16 3 1', 162 | ' c None', 163 | '+ c #444444', 164 | '. c #e6e6e6', 165 | ' ...... ', 166 | ' .......... ', 167 | ' ......++.... ', 168 | ' .......++.....', 169 | ' ..............', 170 | '.....+++++......', 171 | '....+++++.......', 172 | '.......++.......', 173 | '.......++.......', 174 | '.......+........', 175 | '......++........', 176 | ' .....++.+.....', 177 | ' .....++++.....', 178 | ' .....++..... ', 179 | ' .......... ', 180 | ' ...... '] 181 | 182 | # Hide/show "to column" label and spinbox based on mode type 183 | def disableWidget(currentIndex): 184 | 185 | 186 | 187 | if self.d2.currentText() == "Hole": 188 | iN4.hide() 189 | self.d4.setEnabled(False) 190 | iN5.hide() 191 | self.d5.setEnabled(False) 192 | iN10.show() 193 | self.d10.setEnabled(True) 194 | if self.d10.isChecked(): 195 | # iN11.show() 196 | self.d11.setEnabled(True) 197 | else: 198 | # iN11.hide() 199 | self.d11.setEnabled(False) 200 | elif self.d2.currentText() == "Bolt": 201 | iN3.show() 202 | self.d3.setEnabled(True) 203 | iN4.hide() 204 | self.d4.setEnabled(False) 205 | iN5.hide() 206 | self.d5.setEnabled(False) 207 | iN10.show() 208 | self.d10.setEnabled(True) 209 | if self.d10.isChecked(): 210 | # iN11.show() 211 | self.d11.setEnabled(True) 212 | else: 213 | # iN11.hide() 214 | self.d11.setEnabled(False) 215 | elif self.d2.currentText() == "Bolt and nut": 216 | iN3.show() 217 | self.d3.setEnabled(True) 218 | iN4.hide() 219 | self.d4.setEnabled(False) 220 | iN5.show() 221 | self.d5.setEnabled(True) 222 | iN10.show() 223 | self.d10.setEnabled(True) 224 | if self.d10.isChecked(): 225 | # iN11.show() 226 | self.d11.setEnabled(True) 227 | else: 228 | # iN11.hide() 229 | self.d11.setEnabled(False) 230 | elif self.d2.currentText() == "Bolt and grooved nut": 231 | iN3.show() 232 | self.d3.setEnabled(True) 233 | iN4.show() 234 | self.d4.setEnabled(True) 235 | iN5.show() 236 | self.d5.setEnabled(True) 237 | iN10.hide() 238 | self.d10.setChecked(False) 239 | self.d10.setEnabled(False) 240 | # iN11.hide() 241 | self.d11.setEnabled(False) 242 | elif self.d2.currentText() == "Bolt and washer": 243 | iN3.show() 244 | self.d3.setEnabled(True) 245 | iN4.hide() 246 | self.d4.setEnabled(False) 247 | iN5.hide() 248 | self.d5.setEnabled(False) 249 | iN10.show() 250 | self.d10.setEnabled(True) 251 | if self.d10.isChecked(): 252 | # iN11.show() 253 | self.d11.setEnabled(True) 254 | else: 255 | # iN11.hide() 256 | self.d11.setEnabled(False) 257 | elif self.d2.currentText() == "Bolt and large washer": 258 | iN3.show() 259 | self.d3.setEnabled(True) 260 | iN4.hide() 261 | self.d4.setEnabled(False) 262 | iN5.hide() 263 | self.d5.setEnabled(False) 264 | iN10.show() 265 | self.d10.setEnabled(True) 266 | if self.d10.isChecked(): 267 | # iN11.show() 268 | self.d11.setEnabled(True) 269 | else: 270 | # iN11.hide() 271 | self.d11.setEnabled(False) 272 | elif self.d2.currentText() == "Bolt, nut and washer": 273 | iN3.show() 274 | self.d3.setEnabled(True) 275 | iN4.hide() 276 | self.d4.setEnabled(False) 277 | iN5.show() 278 | self.d5.setEnabled(True) 279 | iN10.show() 280 | self.d10.setEnabled(True) 281 | if self.d10.isChecked(): 282 | # iN11.show() 283 | self.d11.setEnabled(True) 284 | else: 285 | # iN11.hide() 286 | self.d11.setEnabled(False) 287 | elif self.d2.currentText() == "Bolt, nut and large washer": 288 | iN3.show() 289 | self.d3.setEnabled(True) 290 | iN4.hide() 291 | self.d4.setEnabled(False) 292 | iN5.show() 293 | self.d5.setEnabled(True) 294 | iN10.show() 295 | self.d10.setEnabled(True) 296 | if self.d10.isChecked(): 297 | # iN11.show() 298 | self.d11.setEnabled(True) 299 | else: 300 | # iN11.hide() 301 | self.d11.setEnabled(False) 302 | elif self.d2.currentText() == "Bolt, grooved nut and washer": 303 | iN3.show() 304 | self.d3.setEnabled(True) 305 | iN4.show() 306 | self.d4.setEnabled(True) 307 | iN5.show() 308 | self.d5.setEnabled(True) 309 | iN10.hide() 310 | self.d10.setChecked(False) 311 | self.d10.setEnabled(False) 312 | # iN11.hide() 313 | self.d11.setEnabled(False) 314 | elif self.d2.currentText() == "Bolt, grooved nut and large washer": 315 | iN3.show() 316 | self.d3.setEnabled(True) 317 | iN4.show() 318 | self.d4.setEnabled(True) 319 | iN5.show() 320 | self.d5.setEnabled(True) 321 | iN10.hide() 322 | self.d10.setChecked(False) 323 | self.d10.setEnabled(False) 324 | # iN11.hide() 325 | self.d11.setEnabled(False) 326 | elif self.d2.currentText() == "Nut": 327 | iN3.hide() 328 | self.d3.setEnabled(False) 329 | iN4.hide() 330 | self.d4.setEnabled(False) 331 | iN5.hide() 332 | self.d5.setEnabled(False) 333 | iN10.show() 334 | self.d10.setEnabled(True) 335 | if self.d10.isChecked(): 336 | # iN11.show() 337 | self.d11.setEnabled(True) 338 | else: 339 | # iN11.hide() 340 | self.d11.setEnabled(False) 341 | elif self.d2.currentText() == "Grooved nut": 342 | iN3.hide() 343 | self.d3.setEnabled(False) 344 | iN4.show() 345 | self.d4.setEnabled(True) 346 | iN5.hide() 347 | self.d5.setEnabled(False) 348 | iN10.hide() 349 | self.d10.setChecked(False) 350 | self.d10.setEnabled(False) 351 | # iN11.hide() 352 | self.d11.setEnabled(False) 353 | elif self.d2.currentText() == "Nut and washer": 354 | iN3.hide() 355 | self.d3.setEnabled(False) 356 | iN4.hide() 357 | self.d4.setEnabled(False) 358 | iN5.hide() 359 | self.d5.setEnabled(False) 360 | iN10.show() 361 | self.d10.setEnabled(True) 362 | if self.d10.isChecked(): 363 | # iN11.show() 364 | self.d11.setEnabled(True) 365 | else: 366 | # iN11.hide() 367 | self.d11.setEnabled(False) 368 | elif self.d2.currentText() == "Nut and large washer": 369 | iN3.hide() 370 | self.d3.setEnabled(False) 371 | iN4.hide() 372 | self.d4.setEnabled(False) 373 | iN5.hide() 374 | self.d5.setEnabled(False) 375 | elif self.d2.currentText() == "Grooved nut and washer": 376 | iN3.hide() 377 | self.d3.setEnabled(False) 378 | iN4.show() 379 | self.d4.setEnabled(True) 380 | iN5.hide() 381 | self.d5.setEnabled(False) 382 | iN10.hide() 383 | self.d10.setChecked(False) 384 | self.d10.setEnabled(False) 385 | # iN11.hide() 386 | self.d11.setEnabled(False) 387 | elif self.d2.currentText() == "Grooved nut and large washer": 388 | iN3.hide() 389 | self.d3.setEnabled(False) 390 | iN4.show() 391 | self.d4.setEnabled(True) 392 | iN5.hide() 393 | self.d5.setEnabled(False) 394 | iN10.hide() 395 | self.d10.setChecked(False) 396 | self.d10.setEnabled(False) 397 | # iN11.hide() 398 | self.d11.setEnabled(False) 399 | else: 400 | iN3.hide() 401 | self.d3.setEnabled(False) 402 | iN4.hide() 403 | self.d4.setEnabled(False) 404 | iN5.hide() 405 | self.d5.setEnabled(False) 406 | iN10.hide() 407 | self.d10.setChecked(False) 408 | self.d10.setEnabled(False) 409 | # iN11.hide() 410 | self.d11.setEnabled(False) 411 | 412 | DockWidget.setObjectName("DockWidget") 413 | DockWidget.resize(sizeX, sizeY) 414 | DockWidget.setLayoutDirection(QtCore.Qt.LeftToRight) 415 | # DockWidget.setToolTip("") 416 | DockWidget.setFloating(True) 417 | DockWidget.setFeatures(QtGui.QDockWidget.DockWidgetFloatable|QtGui.QDockWidget.DockWidgetMovable|QtGui.QDockWidget.DockWidgetClosable) 418 | DockWidget.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea|QtCore.Qt.RightDockWidgetArea) 419 | self.dockWidgetContents = QtGui.QWidget() 420 | self.dockWidgetContents.setMaximumWidth(sizeX) 421 | self.dockWidgetContents.setMaximumHeight(sizeY) 422 | self.dockWidgetContents.setObjectName("dockWidgetContents") 423 | 424 | self.grid = QtGui.QGridLayout(DockWidget) 425 | self.grid.setSpacing(10) 426 | 427 | iN1 = QtGui.QLabel("Metric size") 428 | iN1.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 429 | self.d1 = QtGui.QComboBox() 430 | self.d1.addItem("M2") 431 | self.d1.addItem("M3") 432 | self.d1.addItem("M4") 433 | self.d1.addItem("M5") 434 | self.d1.addItem("M6") 435 | self.d1.addItem("M8") 436 | self.d1.setCurrentIndex(1) # set M3 as default 437 | 438 | iN2 = QtGui.QLabel("Type") 439 | iN2.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 440 | self.d2 = QtGui.QComboBox() 441 | self.d2.addItem("Hole") 442 | self.d2.addItem("Bolt") 443 | self.d2.addItem("Bolt and nut") 444 | self.d2.addItem("Bolt and grooved nut") 445 | self.d2.addItem("Bolt and washer") 446 | self.d2.addItem("Bolt and large washer") 447 | self.d2.addItem("Bolt, nut and washer") 448 | self.d2.addItem("Bolt, nut and large washer") 449 | self.d2.addItem("Bolt, grooved nut and washer") 450 | self.d2.addItem("Bolt, grooved nut and large washer") 451 | self.d2.addItem("Nut") 452 | self.d2.addItem("Grooved nut") 453 | self.d2.addItem("Nut and washer") 454 | self.d2.addItem("Nut and large washer") 455 | self.d2.addItem("Grooved nut and washer") 456 | self.d2.addItem("Grooved nut and large washer") 457 | self.d2.setCurrentIndex(1) # set "Bolt" as default 458 | self.d2.currentIndexChanged['QString'].connect(disableWidget) 459 | 460 | iN10 = QtGui.QLabel("Slot (range)") 461 | iN10.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 462 | self.d10 = QtGui.QCheckBox() 463 | self.d10.setToolTip("Turn the hole into a slot") 464 | self.d10.stateChanged.connect(disableWidget) 465 | 466 | # iN11 = QtGui.QLabel("Sliding range") 467 | # iN11.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 468 | self.d11 = QtGui.QDoubleSpinBox() 469 | self.d11.setValue(10.0) 470 | self.d11.setSingleStep(1.0) 471 | self.d11.setToolTip("Sliding range in with the fastener is able to move") 472 | self.d11.setEnabled(False) 473 | 474 | iN3 = QtGui.QLabel("Length") 475 | iN3.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 476 | self.d3 = QtGui.QDoubleSpinBox() 477 | self.d3.setValue(20.0) 478 | self.d3.setSingleStep(1.0) 479 | 480 | iN4 = QtGui.QLabel("Groove length") 481 | iN4.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 482 | iN4.hide() # set initial state hidden because "Bolt" mode is set 483 | self.d4 = QtGui.QDoubleSpinBox() 484 | self.d4.setValue(20.0) 485 | self.d4.setSingleStep(5.0) 486 | self.d4.setEnabled(False) # set initial state hidden because "Bolt" mode is set 487 | 488 | iN5 = QtGui.QLabel("Nut displacement") 489 | iN5.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 490 | iN5.hide() # set initial state hidden because "Bolt" mode is set 491 | self.d5 = QtGui.QDoubleSpinBox() 492 | self.d5.setValue(10.0) 493 | self.d5.setSingleStep(1.0) 494 | self.d5.setEnabled(False) # set initial state hidden because "Bolt" mode is set 495 | 496 | iN6 = QtGui.QLabel("Tolerance") 497 | iN6.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 498 | self.d6 = QtGui.QDoubleSpinBox() 499 | self.d6.setValue(0.2) 500 | self.d6.setSingleStep(0.1) 501 | 502 | iN7 = QtGui.QLabel("Color") 503 | iN7.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 504 | self.d7 = QtGui.QComboBox() 505 | self.d7.addItem("Default") 506 | self.d7.addItem("Red") 507 | self.d7.addItem("Yellow") 508 | self.d7.addItem("Green") 509 | self.d7.addItem("Blue") 510 | self.d7.setCurrentIndex(1) # set "Red" as default 511 | 512 | iN8 = QtGui.QLabel("Transparency") 513 | iN8.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 514 | self.d8 = QtGui.QSpinBox() 515 | self.d8.setValue(50) #Default value 516 | self.d8.setMaximum(100) 517 | self.d8.setSingleStep(10) 518 | 519 | iN9 = QtGui.QLabel("Group name") 520 | iN9.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) 521 | self.d9 = QtGui.QLineEdit() 522 | self.d9.setText("Holes") #Default value 523 | 524 | separator = QtGui.QFrame() 525 | separator.setFrameShape(QtGui.QFrame.HLine) 526 | separator.setLineWidth(5) 527 | 528 | # self.close = QtGui.QPushButton() 529 | # self.close.setText("Close") 530 | # self.close.setObjectName("close") 531 | 532 | self.createHole = QtGui.QPushButton() 533 | self.createHole.setText("Create hole") 534 | self.createHole.setObjectName("create") 535 | 536 | self.help = QtGui.QPushButton() 537 | self.help.setIcon(QtGui.QIcon(QtGui.QPixmap(infoIcon))) 538 | self.help.setFixedWidth(40) 539 | self.help.setObjectName("help") 540 | 541 | self.grid.addWidget(iN1, 0, 0) 542 | self.grid.addWidget(self.d1, 0, 1, 1, 2) 543 | self.grid.addWidget(iN2, 1, 0) 544 | self.grid.addWidget(self.d2, 1, 1, 1, 2) 545 | self.grid.addWidget(iN10, 2, 0) 546 | self.grid.addWidget(self.d10, 2, 1) 547 | # self.grid.addWidget(iN11, 3, 0) 548 | self.grid.addWidget(self.d11, 2, 2) 549 | self.grid.addWidget(iN3, 3, 0) 550 | self.grid.addWidget(self.d3, 3, 1, 1, 2) 551 | self.grid.addWidget(iN4, 4, 0) 552 | self.grid.addWidget(self.d4, 4, 1, 1, 2) 553 | self.grid.addWidget(iN5, 5, 0) 554 | self.grid.addWidget(self.d5, 5, 1, 1, 2) 555 | self.grid.addWidget(iN6, 6, 0) 556 | self.grid.addWidget(self.d6, 6, 1, 1, 2) 557 | self.grid.addWidget(iN7, 7, 0) 558 | self.grid.addWidget(self.d7, 7, 1, 1, 2) 559 | self.grid.addWidget(iN8, 8, 0) 560 | self.grid.addWidget(self.d8, 8, 1, 1, 2) 561 | self.grid.addWidget(iN9, 9, 0) 562 | self.grid.addWidget(self.d9, 9, 1, 1, 2) 563 | self.grid.addWidget(separator, 10, 0) 564 | self.grid.addWidget(self.help, 11, 0) 565 | self.grid.addWidget(self.createHole, 11, 1, 1, 2) 566 | 567 | 568 | # Fixed label widths 569 | iN1.setFixedWidth(120) 570 | 571 | self.dockWidgetContents.setLayout(self.grid) 572 | 573 | # # Set Tab order (not needed anymore because of enabling/disabling spinboxes) 574 | # self.dockWidgetContents.setTabOrder(self.createHole, self.d1) 575 | # self.dockWidgetContents.setTabOrder(self.d1, self.d2) 576 | # self.dockWidgetContents.setTabOrder(self.d2, self.d3) 577 | # self.dockWidgetContents.setTabOrder(self.d3, self.d4) 578 | # self.dockWidgetContents.setTabOrder(self.d4, self.d5) 579 | # self.dockWidgetContents.setTabOrder(self.d5, self.d6) 580 | # self.dockWidgetContents.setTabOrder(self.d6, self.d7) 581 | # self.dockWidgetContents.setTabOrder(self.d7, self.d8) 582 | # self.dockWidgetContents.setTabOrder(self.d8, self.createHole) 583 | 584 | DockWidget.setWidget(self.dockWidgetContents) 585 | 586 | 587 | # self.close.clicked.connect(close_dock) 588 | self.createHole.clicked.connect(self.onCreate) 589 | self.help.clicked.connect(self.onHelp) 590 | 591 | self.retranslateUi(DockWidget) 592 | QtCore.QMetaObject.connectSlotsByName(DockWidget) 593 | 594 | ## retraslateUi Qt5 compatibility ########################################################## 595 | def retranslateUi(self, DockWidget): 596 | DockWidget.setWindowTitle("Fastener holes") 597 | # self.close.setToolTip("Close window") 598 | self.help.setToolTip("More information") 599 | 600 | ### ------------------------------------------------------------------------------------ ### 601 | ### ---------code to be inserted and remove from new generation------------------------- ### 602 | ### ------------------------------------------------------------------------------------ ### 603 | 604 | ## 605 | def onHelp(self): 606 | msg="""
version """ + __version__ + """
This macro helps creating holes with tolerances so that metric fasteners can be inserted in final parts. In other words, it creates negative volumes (or holes) so that they can be use to cut another body. It makes easy and fast the creation, placement and tweaking of all needed holes.
It is very useful when designing parts for 3D printing and prototyping.
Copyright 2019 Pablo Gil Fernández
This work is licensed under GNU Lesser General Public License (LGPL). To view a copy of this license, visit https://www.gnu.org/licenses/lgpl-3.0.html
""" 607 | # QtGui.qApp.restoreOverrideCursor() 608 | # res='' 609 | # QtGui.qApp.restoreOverrideCursor() 610 | res = QtGui.QMessageBox.question(None,"Help",msg,QtGui.QMessageBox.Ok) 611 | 612 | def onCreate(self): 613 | a_clear_console() 614 | 615 | # ===== Variables ============================================== 616 | #print ("\n****** Create hole ********") 617 | 618 | selection = Gui.Selection.getSelection() 619 | selectionEx = Gui.Selection.getSelectionEx() 620 | 621 | if len(selectionEx) == 0: 622 | #print ("\n-- No selection --") 623 | originX = 0.0 624 | originY = 0.0 625 | originZ = 0.0 626 | dir = App.Vector(0.0,0.0,1.0) 627 | rot = pointAt(dir, App.Vector(0.0,0.0,1.0)) 628 | 629 | elif len(selectionEx) == 1: 630 | #print ("\n-- 1 element selected --") 631 | # ------ SELECTION TYPE -------- 632 | if selectionEx[0].SubObjects[0].ShapeType == "Vertex": 633 | #print ("Vertex") 634 | a = selection[0].Placement.inverse() 635 | b = selection[0].getGlobalPlacement().multiply(a) 636 | c = selectionEx[0].SubObjects[0].Point 637 | value = b.multVec(c) 638 | originX = value.x 639 | originY = value.y 640 | originZ = value.z 641 | dir = App.Vector(0.0,0.0,1.0) 642 | rot = pointAt(dir, App.Vector(0.0,0.0,1.0)) 643 | 644 | elif selectionEx[0].SubObjects[0].ShapeType == "Edge": 645 | #print ("Line or curve") 646 | a = selection[0].Placement.inverse() 647 | b = selection[0].getGlobalPlacement().multiply(a) 648 | c = selectionEx[0].SubObjects[0].CenterOfMass 649 | value = b.multVec(c) 650 | originX = value.x 651 | originY = value.y 652 | originZ = value.z 653 | dir = App.Vector(0.0,0.0,1.0) 654 | rot = pointAt(dir, App.Vector(0.0,0.0,1.0)) 655 | 656 | elif selectionEx[0].SubObjects[0].ShapeType == "Face": 657 | #print ("Face") 658 | a = selection[0].Placement.inverse() 659 | b = selection[0].getGlobalPlacement().multiply(a) 660 | c = selectionEx[0].SubObjects[0].CenterOfMass 661 | value = b.multVec(c) 662 | originX = value.x 663 | originY = value.y 664 | originZ = value.z 665 | 666 | dir = selectionEx[0].SubObjects[0].normalAt(0,0) 667 | 668 | if dir.z == 1 : 669 | rot = pointAt(dir, App.Vector(0.0,1.0,0.0)) 670 | elif dir.z == -1 : 671 | rot = pointAt(dir, App.Vector(0.0,1.0,0.0)) 672 | else : 673 | rot = pointAt(dir, App.Vector(0.0,0.0,1.0)) 674 | #else: 675 | #print ("\nUnknown element selected") 676 | else: 677 | #print ("\n-- More than one element selected --") 678 | originX = 0.0 679 | originY = 0.0 680 | originZ = 0.0 681 | dir = App.Vector(0.0,0.0,1.0) 682 | rot = pointAt(dir, App.Vector(0.0,0.0,1.0)) 683 | 684 | #print ("\noriginX = " + str(originX)) 685 | #print ("originY = " + str(originY)) 686 | #print ("originZ = " + str(originZ)) 687 | 688 | rodH = self.d3.value() 689 | grooveLength = self.d4.value() 690 | nutDisplacement = self.d5.value() 691 | tolerance = self.d6.value() 692 | bodyTransparency = self.d8.value() 693 | groupName = self.d9.text() 694 | 695 | if self.d10.isChecked(): 696 | slot = True 697 | else: 698 | slot = False 699 | 700 | slotWidth = self.d11.value() 701 | 702 | #print (groupName) 703 | 704 | #print (str(self.d7.currentText())) 705 | if self.d7.currentText() == "Default": 706 | bodyColor = (0.80,0.80,0.80) 707 | if self.d7.currentText() == "Red": 708 | bodyColor = (0.67,0.00,0.00) 709 | if self.d7.currentText() == "Yellow": 710 | bodyColor = (1.00,0.92,0.03) 711 | if self.d7.currentText() == "Green": 712 | bodyColor = (0.33,0.67,0.00) 713 | if self.d7.currentText() == "Blue": 714 | bodyColor = (0.00,0.33,1.00) 715 | 716 | #print (str(self.d1.currentText())) 717 | if self.d1.currentText() == "M2": 718 | headR = 1.90 + tolerance 719 | headH = 2.20 + tolerance 720 | bodyR = 1.00 + tolerance 721 | bodyH = rodH + tolerance 722 | nutH = 1.80 + tolerance 723 | nutWidth = 4.00 + tolerance * 2 724 | washerR = 2.45 + tolerance 725 | washerH = 0.30 + tolerance 726 | washerLargeR = rodH + tolerance # does not exist 727 | washerLargeH = rodH + tolerance # does not exist 728 | if self.d1.currentText() == "M3": 729 | headR = 2.80 + tolerance 730 | headH = 3.20 + tolerance 731 | bodyR = 1.50 + tolerance 732 | bodyH = rodH + tolerance 733 | nutH = 2.50 + tolerance 734 | nutWidth = 5.40 + tolerance * 2 735 | washerR = 3.40 + tolerance 736 | washerH = 0.40 + tolerance 737 | washerLargeR = 4.50 + tolerance 738 | washerLargeH = 0.70 + tolerance 739 | if self.d1.currentText() == "M4": 740 | headR = 3.60 + tolerance 741 | headH = 4.20 + tolerance 742 | bodyR = 2.00 + tolerance 743 | bodyH = rodH + tolerance 744 | nutH = 3.20 + tolerance 745 | nutWidth = 6.90 + tolerance * 2 746 | washerR = 4.50 + tolerance 747 | washerH = 0.80 + tolerance 748 | washerLargeR = 5.90 + tolerance 749 | washerLargeH = 1.00 + tolerance 750 | if self.d1.currentText() == "M5": 751 | headR = 4.40 + tolerance 752 | headH = 5.20 + tolerance 753 | bodyR = 2.50 + tolerance 754 | bodyH = rodH + tolerance 755 | nutH = 4.20 + tolerance 756 | nutWidth = 8.00 + tolerance * 2 757 | washerR = 4.90 + tolerance 758 | washerH = 0.90 + tolerance 759 | washerLargeR = 7.35 + tolerance 760 | washerLargeH = 1.25 + tolerance 761 | if self.d1.currentText() == "M6": 762 | headR = 5.20 + tolerance 763 | headH = 6.20 + tolerance 764 | bodyR = 3.0 + tolerance 765 | bodyH = rodH + tolerance 766 | nutH = 4.90 + tolerance 767 | nutWidth = 10.00 + tolerance * 2 768 | washerR = 6.00 + tolerance 769 | washerH = 1.80 + tolerance 770 | washerLargeR = 9.00 + tolerance 771 | washerLargeH = 1.80 + tolerance 772 | if self.d1.currentText() == "M8": 773 | headR = 6.75 + tolerance 774 | headH = 8.20 + tolerance 775 | bodyR = 4.00 + tolerance 776 | bodyH = rodH + tolerance 777 | nutH = 7.20 + tolerance 778 | nutWidth = 13.00 + tolerance * 2 779 | washerR = 8.00 + tolerance 780 | washerH = 1.80 + tolerance 781 | washerLargeR = 12.00 + tolerance 782 | washerLargeH = 2.20 + tolerance 783 | 784 | # Creates group called "Holes" if it doesn't exist 785 | if len(App.ActiveDocument.getObjectsByLabel(groupName)) == 0: 786 | App.ActiveDocument.addObject("App::DocumentObjectGroup",groupName) 787 | 788 | # ===== Hole ============================================== 789 | if self.d2.currentText() == "Hole" and slot == False: 790 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Hole') 791 | Gui.activeView().setActiveObject('pdbody', body) 792 | App.ActiveDocument.recompute() 793 | 794 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 795 | body.addObject(cylinder1) 796 | cylinder1.Radius = bodyR 797 | cylinder1.Height = rodH 798 | cylinder1.Label = "Hole" 799 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 800 | cylinder1.MapReversed = True 801 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 802 | cylinder1.MapMode = 'FlatFace' 803 | 804 | body.Placement.Base = App.Vector(originX, originY, originZ) 805 | body.Placement.Rotation = rot.Q 806 | 807 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 808 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 809 | Gui.activeView().setActiveObject('pdbody', None) 810 | App.ActiveDocument.getObject(groupName).addObject(body) 811 | App.ActiveDocument.recompute() 812 | 813 | #print ("\n" + self.d1.currentText() + " Hole created") 814 | 815 | # ===== Hole (slot)============================================== 816 | if self.d2.currentText() == "Hole" and slot == True: 817 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Hole with slot') 818 | Gui.activeView().setActiveObject('pdbody', body) 819 | App.ActiveDocument.recompute() 820 | 821 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 822 | body.addObject(cylinder1) 823 | cylinder1.Radius = bodyR 824 | cylinder1.Height = rodH 825 | cylinder1.Label = "Hole" 826 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 827 | cylinder1.MapReversed = True 828 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 829 | cylinder1.MapMode = 'FlatFace' 830 | 831 | cube = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 832 | body.addObject(cube) 833 | cube.Length = slotWidth 834 | cube.Width = bodyR*2 835 | cube.Height = rodH 836 | cube.Label = "slot" 837 | cube.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -rodH), App.Rotation(0.0, 0.0, 0.0)) 838 | cube.MapReversed = False 839 | cube.Support = [(App.activeDocument().XY_Plane,'')] 840 | cube.MapMode = 'FlatFace' 841 | 842 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 843 | body.addObject(cylinder2) 844 | cylinder2.Radius = bodyR 845 | cylinder2.Height = rodH 846 | cylinder2.Label = "Hole" 847 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 848 | cylinder2.MapReversed = True 849 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 850 | cylinder2.MapMode = 'FlatFace' 851 | 852 | body.Placement.Base = App.Vector(originX, originY, originZ) 853 | body.Placement.Rotation = rot.Q 854 | 855 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 856 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 857 | 858 | Gui.activeDocument().activeObject().Visibility = False 859 | Gui.activeDocument().activeObject().Visibility = True 860 | Gui.activeView().setActiveObject('pdbody', None) 861 | App.ActiveDocument.getObject(groupName).addObject(body) 862 | App.ActiveDocument.recompute() 863 | 864 | #print ("\n" + self.d1.currentText() + " Hole created") 865 | 866 | # ===== Bolt ============================================== 867 | if self.d2.currentText() == "Bolt" and slot == False: 868 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt') 869 | Gui.activeView().setActiveObject('pdbody', body) 870 | 871 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 872 | body.addObject(cylinder1) 873 | cylinder1.Radius = headR 874 | cylinder1.Height = headH 875 | cylinder1.Label = "Head" 876 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 877 | cylinder1.MapReversed = False 878 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 879 | cylinder1.MapMode = 'FlatFace' 880 | 881 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 882 | body.addObject(cylinder2) 883 | cylinder2.Radius = bodyR 884 | cylinder2.Height = bodyH + headH 885 | cylinder2.Label = "Body" 886 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 887 | cylinder2.MapReversed = False 888 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 889 | cylinder2.MapMode = 'FlatFace' 890 | 891 | body.Placement.Base = App.Vector(originX, originY, originZ) 892 | body.Placement.Rotation = rot.Q 893 | 894 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 895 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 896 | 897 | Gui.activeDocument().activeObject().Visibility = False 898 | Gui.activeDocument().activeObject().Visibility = True 899 | Gui.activeView().setActiveObject('pdbody', None) 900 | App.ActiveDocument.getObject(groupName).addObject(body) 901 | App.ActiveDocument.recompute() 902 | 903 | #print ("\n" + self.d1.currentText() + " Bolt created") 904 | 905 | # ===== Bolt (slot) ============================================== 906 | if self.d2.currentText() == "Bolt" and slot == True: 907 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt with slot') 908 | Gui.activeView().setActiveObject('pdbody', body) 909 | App.ActiveDocument.recompute() 910 | 911 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 912 | body.addObject(cylinder1) 913 | cylinder1.Radius = headR 914 | cylinder1.Height = headH 915 | cylinder1.Label = "Head-left" 916 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 917 | cylinder1.MapReversed = True 918 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 919 | cylinder1.MapMode = 'FlatFace' 920 | 921 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 922 | body.addObject(cube1) 923 | cube1.Length = slotWidth 924 | cube1.Width = headR*2 925 | cube1.Height = headH 926 | cube1.Label = "Head-center" 927 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -headR, -headH), App.Rotation(0.0, 0.0, 0.0)) 928 | cube1.MapReversed = False 929 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 930 | cube1.MapMode = 'FlatFace' 931 | 932 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 933 | body.addObject(cylinder2) 934 | cylinder2.Radius = headR 935 | cylinder2.Height = headH 936 | cylinder2.Label = "Head-right" 937 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 938 | cylinder2.MapReversed = True 939 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 940 | cylinder2.MapMode = 'FlatFace' 941 | 942 | cylinder3 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 943 | body.addObject(cylinder3) 944 | cylinder3.Radius = bodyR 945 | cylinder3.Height = bodyH + headH 946 | cylinder3.Label = "Body-left" 947 | cylinder3.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 948 | cylinder3.MapReversed = True 949 | cylinder3.Support = [(App.activeDocument().XY_Plane,'')] 950 | cylinder3.MapMode = 'FlatFace' 951 | 952 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 953 | body.addObject(cube2) 954 | cube2.Length = slotWidth 955 | cube2.Width = bodyR*2 956 | cube2.Height = bodyH + headH 957 | cube2.Label = "Body-center" 958 | cube2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -bodyH - headH), App.Rotation(0.0, 0.0, 0.0)) 959 | cube2.MapReversed = False 960 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 961 | cube2.MapMode = 'FlatFace' 962 | 963 | cylinder4 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 964 | body.addObject(cylinder4) 965 | cylinder4.Radius = bodyR 966 | cylinder4.Height = bodyH + headH 967 | cylinder4.Label = "Body-right" 968 | cylinder4.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 969 | cylinder4.MapReversed = True 970 | cylinder4.Support = [(App.activeDocument().XY_Plane,'')] 971 | cylinder4.MapMode = 'FlatFace' 972 | 973 | body.Placement.Base = App.Vector(originX, originY, originZ) 974 | body.Placement.Rotation = rot.Q 975 | 976 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 977 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 978 | 979 | Gui.activeDocument().activeObject().Visibility = False 980 | Gui.activeDocument().activeObject().Visibility = True 981 | Gui.activeView().setActiveObject('pdbody', None) 982 | App.ActiveDocument.getObject(groupName).addObject(body) 983 | App.ActiveDocument.recompute() 984 | 985 | #print ("\n" + self.d1.currentText() + " Bolt created") 986 | 987 | # ===== Bolt and nut ============================================== 988 | elif self.d2.currentText() == "Bolt and nut" and slot == False: 989 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and nut') 990 | Gui.activeView().setActiveObject('pdbody', body) 991 | 992 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 993 | body.addObject(cylinder1) 994 | cylinder1.Radius = headR 995 | cylinder1.Height = headH 996 | cylinder1.Label = "Head" 997 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 998 | cylinder1.MapReversed = False 999 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1000 | cylinder1.MapMode = 'FlatFace' 1001 | 1002 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1003 | body.addObject(cylinder2) 1004 | cylinder2.Radius = bodyR 1005 | cylinder2.Height = bodyH + headH 1006 | cylinder2.Label = "Body" 1007 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1008 | cylinder2.MapReversed = False 1009 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1010 | cylinder2.MapMode = 'FlatFace' 1011 | 1012 | prism = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1013 | body.addObject(prism) 1014 | prism.Polygon = 6 1015 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1016 | prism.Height = nutH 1017 | prism.Label = "Nut" 1018 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1019 | prism.MapReversed = False 1020 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1021 | prism.MapMode = 'FlatFace' 1022 | 1023 | body.Placement.Base = App.Vector(originX, originY, originZ) 1024 | body.Placement.Rotation = rot.Q 1025 | 1026 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1027 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1028 | 1029 | Gui.activeDocument().activeObject().Visibility = False 1030 | Gui.activeDocument().activeObject().Visibility = True 1031 | Gui.activeView().setActiveObject('pdbody', None) 1032 | App.ActiveDocument.getObject(groupName).addObject(body) 1033 | App.ActiveDocument.recompute() 1034 | 1035 | print ("\n" + self.d1.currentText() + " Bolt and nut created") 1036 | 1037 | # ===== Bolt and nut (slot)============================================== 1038 | if self.d2.currentText() == "Bolt and nut" and slot == True: 1039 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and nut with slot') 1040 | Gui.activeView().setActiveObject('pdbody', body) 1041 | App.ActiveDocument.recompute() 1042 | 1043 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1044 | body.addObject(cylinder1) 1045 | cylinder1.Radius = headR 1046 | cylinder1.Height = headH 1047 | cylinder1.Label = "Head-left" 1048 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1049 | cylinder1.MapReversed = True 1050 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1051 | cylinder1.MapMode = 'FlatFace' 1052 | 1053 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1054 | body.addObject(cube1) 1055 | cube1.Length = slotWidth 1056 | cube1.Width = headR*2 1057 | cube1.Height = headH 1058 | cube1.Label = "Head-center" 1059 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -headR, -headH), App.Rotation(0.0, 0.0, 0.0)) 1060 | cube1.MapReversed = False 1061 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 1062 | cube1.MapMode = 'FlatFace' 1063 | 1064 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1065 | body.addObject(cylinder2) 1066 | cylinder2.Radius = headR 1067 | cylinder2.Height = headH 1068 | cylinder2.Label = "Head-right" 1069 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1070 | cylinder2.MapReversed = True 1071 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1072 | cylinder2.MapMode = 'FlatFace' 1073 | 1074 | cylinder3 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1075 | body.addObject(cylinder3) 1076 | cylinder3.Radius = bodyR 1077 | cylinder3.Height = bodyH + headH 1078 | cylinder3.Label = "Body-left" 1079 | cylinder3.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1080 | cylinder3.MapReversed = True 1081 | cylinder3.Support = [(App.activeDocument().XY_Plane,'')] 1082 | cylinder3.MapMode = 'FlatFace' 1083 | 1084 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1085 | body.addObject(cube2) 1086 | cube2.Length = slotWidth 1087 | cube2.Width = bodyR*2 1088 | cube2.Height = bodyH + headH 1089 | cube2.Label = "Body-center" 1090 | cube2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -bodyH - headH), App.Rotation(0.0, 0.0, 0.0)) 1091 | cube2.MapReversed = False 1092 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 1093 | cube2.MapMode = 'FlatFace' 1094 | 1095 | cylinder4 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1096 | body.addObject(cylinder4) 1097 | cylinder4.Radius = bodyR 1098 | cylinder4.Height = bodyH + headH 1099 | cylinder4.Label = "Body-right" 1100 | cylinder4.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1101 | cylinder4.MapReversed = True 1102 | cylinder4.Support = [(App.activeDocument().XY_Plane,'')] 1103 | cylinder4.MapMode = 'FlatFace' 1104 | 1105 | prism1 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1106 | body.addObject(prism1) 1107 | prism1.Polygon = 6 1108 | prism1.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1109 | prism1.Height = nutH 1110 | prism1.Label = "Nut-left" 1111 | prism1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1112 | prism1.MapReversed = False 1113 | prism1.Support = [(App.activeDocument().XY_Plane,'')] 1114 | prism1.MapMode = 'FlatFace' 1115 | 1116 | cube3 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1117 | body.addObject(cube3) 1118 | cube3.Length = slotWidth 1119 | cube3.Width = nutWidth 1120 | cube3.Height = nutH 1121 | cube3.Label = "Nut-center" 1122 | cube3.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -nutWidth/2, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1123 | cube3.MapReversed = False 1124 | cube3.Support = [(App.activeDocument().XY_Plane,'')] 1125 | cube3.MapMode = 'FlatFace' 1126 | 1127 | prism2 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1128 | body.addObject(prism2) 1129 | prism2.Polygon = 6 1130 | prism2.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1131 | prism2.Height = nutH 1132 | prism2.Label = "Nut-right" 1133 | prism2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1134 | prism2.MapReversed = False 1135 | prism2.Support = [(App.activeDocument().XY_Plane,'')] 1136 | prism2.MapMode = 'FlatFace' 1137 | 1138 | body.Placement.Base = App.Vector(originX, originY, originZ) 1139 | body.Placement.Rotation = rot.Q 1140 | 1141 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1142 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1143 | 1144 | Gui.activeDocument().activeObject().Visibility = False 1145 | Gui.activeDocument().activeObject().Visibility = True 1146 | Gui.activeView().setActiveObject('pdbody', None) 1147 | App.ActiveDocument.getObject(groupName).addObject(body) 1148 | App.ActiveDocument.recompute() 1149 | 1150 | #print ("\n" + self.d1.currentText() + " Bolt and nut with slot created") 1151 | 1152 | # ===== Bolt and grooved nut ============================================== 1153 | elif self.d2.currentText() == "Bolt and grooved nut" and slot == False: 1154 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and nut') 1155 | Gui.activeView().setActiveObject('pdbody', body) 1156 | 1157 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1158 | body.addObject(cylinder1) 1159 | cylinder1.Radius = headR 1160 | cylinder1.Height = headH 1161 | cylinder1.Label = "Head" 1162 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1163 | cylinder1.MapReversed = False 1164 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1165 | cylinder1.MapMode = 'FlatFace' 1166 | 1167 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1168 | body.addObject(cylinder2) 1169 | cylinder2.Radius = bodyR 1170 | cylinder2.Height = bodyH + headH 1171 | cylinder2.Label = "Body" 1172 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1173 | cylinder2.MapReversed = False 1174 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1175 | cylinder2.MapMode = 'FlatFace' 1176 | 1177 | cube = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1178 | body.addObject(cube) 1179 | cube.Length = grooveLength 1180 | cube.Width = nutWidth 1181 | cube.Height = nutH 1182 | cube.Label = "Groove" 1183 | cube.AttachmentOffset = App.Placement(App.Vector(0.0, -cube.Width/2,-nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1184 | cube.MapReversed = False 1185 | cube.Support = [(App.activeDocument().XY_Plane,'')] 1186 | cube.MapMode = 'FlatFace' 1187 | 1188 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1189 | body.addObject(prism) 1190 | prism.Polygon = 6 1191 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1192 | prism.Height = nutH 1193 | prism.Label = "Nut" 1194 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1195 | prism.MapReversed = False 1196 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1197 | prism.MapMode = 'FlatFace' 1198 | 1199 | body.Placement.Base = App.Vector(originX, originY, originZ) 1200 | body.Placement.Rotation = rot.Q 1201 | 1202 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1203 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1204 | 1205 | Gui.activeDocument().activeObject().Visibility = False 1206 | Gui.activeDocument().activeObject().Visibility = True 1207 | Gui.activeView().setActiveObject('pdbody', None) 1208 | App.ActiveDocument.getObject(groupName).addObject(body) 1209 | App.ActiveDocument.recompute() 1210 | 1211 | print ("\n" + self.d1.currentText() + " Bolt and grooved nut created") 1212 | 1213 | # ===== Bolt and washer ============================================== 1214 | elif self.d2.currentText() == "Bolt and washer" and slot == False: 1215 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and washer') 1216 | Gui.activeView().setActiveObject('pdbody', body) 1217 | 1218 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1219 | body.addObject(cylinder1) 1220 | cylinder1.Radius = washerR 1221 | cylinder1.Height = headH + washerH 1222 | cylinder1.Label = "Head" 1223 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1224 | cylinder1.MapReversed = False 1225 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1226 | cylinder1.MapMode = 'FlatFace' 1227 | 1228 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1229 | body.addObject(cylinder2) 1230 | cylinder2.Radius = bodyR 1231 | cylinder2.Height = bodyH + headH + washerH 1232 | cylinder2.Label = "Body" 1233 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1234 | cylinder2.MapReversed = False 1235 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1236 | cylinder2.MapMode = 'FlatFace' 1237 | 1238 | body.Placement.Base = App.Vector(originX, originY, originZ) 1239 | body.Placement.Rotation = rot.Q 1240 | 1241 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1242 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1243 | 1244 | Gui.activeDocument().activeObject().Visibility = False 1245 | Gui.activeDocument().activeObject().Visibility = True 1246 | Gui.activeView().setActiveObject('pdbody', None) 1247 | App.ActiveDocument.getObject(groupName).addObject(body) 1248 | App.ActiveDocument.recompute() 1249 | 1250 | print ("\n" + self.d1.currentText() + " Bolt and washer created") 1251 | 1252 | # ===== Bolt and washer (slot) ============================================== 1253 | if self.d2.currentText() == "Bolt and washer" and slot == True: 1254 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and washer with slot') 1255 | Gui.activeView().setActiveObject('pdbody', body) 1256 | App.ActiveDocument.recompute() 1257 | 1258 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1259 | body.addObject(cylinder1) 1260 | cylinder1.Radius = washerR 1261 | cylinder1.Height = headH + washerH 1262 | cylinder1.Label = "Head-left" 1263 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1264 | cylinder1.MapReversed = True 1265 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1266 | cylinder1.MapMode = 'FlatFace' 1267 | 1268 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1269 | body.addObject(cube1) 1270 | cube1.Length = slotWidth 1271 | cube1.Width = washerR*2 1272 | cube1.Height = headH + washerH 1273 | cube1.Label = "Head-center" 1274 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -washerR, -headH -washerH), App.Rotation(0.0, 0.0, 0.0)) 1275 | cube1.MapReversed = False 1276 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 1277 | cube1.MapMode = 'FlatFace' 1278 | 1279 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1280 | body.addObject(cylinder2) 1281 | cylinder2.Radius = washerR 1282 | cylinder2.Height = headH + washerH 1283 | cylinder2.Label = "Head-right" 1284 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1285 | cylinder2.MapReversed = True 1286 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1287 | cylinder2.MapMode = 'FlatFace' 1288 | 1289 | cylinder3 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1290 | body.addObject(cylinder3) 1291 | cylinder3.Radius = bodyR 1292 | cylinder3.Height = bodyH + headH + washerH 1293 | cylinder3.Label = "Body-left" 1294 | cylinder3.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1295 | cylinder3.MapReversed = True 1296 | cylinder3.Support = [(App.activeDocument().XY_Plane,'')] 1297 | cylinder3.MapMode = 'FlatFace' 1298 | 1299 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1300 | body.addObject(cube2) 1301 | cube2.Length = slotWidth 1302 | cube2.Width = bodyR*2 1303 | cube2.Height = bodyH + headH + washerH 1304 | cube2.Label = "Body-center" 1305 | cube2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -bodyH - headH - washerH), App.Rotation(0.0, 0.0, 0.0)) 1306 | cube2.MapReversed = False 1307 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 1308 | cube2.MapMode = 'FlatFace' 1309 | 1310 | cylinder4 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1311 | body.addObject(cylinder4) 1312 | cylinder4.Radius = bodyR 1313 | cylinder4.Height = bodyH + headH + washerH 1314 | cylinder4.Label = "Body-right" 1315 | cylinder4.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1316 | cylinder4.MapReversed = True 1317 | cylinder4.Support = [(App.activeDocument().XY_Plane,'')] 1318 | cylinder4.MapMode = 'FlatFace' 1319 | 1320 | body.Placement.Base = App.Vector(originX, originY, originZ) 1321 | body.Placement.Rotation = rot.Q 1322 | 1323 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1324 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1325 | 1326 | Gui.activeDocument().activeObject().Visibility = False 1327 | Gui.activeDocument().activeObject().Visibility = True 1328 | Gui.activeView().setActiveObject('pdbody', None) 1329 | App.ActiveDocument.getObject(groupName).addObject(body) 1330 | App.ActiveDocument.recompute() 1331 | 1332 | #print ("\n" + self.d1.currentText() + " Bolt and washer with slot created") 1333 | 1334 | # ===== Bolt and large washer ============================================== 1335 | elif self.d2.currentText() == "Bolt and large washer" and slot == False: 1336 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and large washer') 1337 | Gui.activeView().setActiveObject('pdbody', body) 1338 | 1339 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1340 | body.addObject(cylinder1) 1341 | cylinder1.Radius = washerLargeR 1342 | cylinder1.Height = headH + washerLargeH 1343 | cylinder1.Label = "Head" 1344 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1345 | cylinder1.MapReversed = False 1346 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1347 | cylinder1.MapMode = 'FlatFace' 1348 | 1349 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1350 | body.addObject(cylinder2) 1351 | cylinder2.Radius = bodyR 1352 | cylinder2.Height = bodyH + headH + washerLargeH 1353 | cylinder2.Label = "Body" 1354 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1355 | cylinder2.MapReversed = False 1356 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1357 | cylinder2.MapMode = 'FlatFace' 1358 | 1359 | body.Placement.Base = App.Vector(originX, originY, originZ) 1360 | body.Placement.Rotation = rot.Q 1361 | 1362 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1363 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1364 | 1365 | Gui.activeDocument().activeObject().Visibility = False 1366 | Gui.activeDocument().activeObject().Visibility = True 1367 | Gui.activeView().setActiveObject('pdbody', None) 1368 | App.ActiveDocument.getObject(groupName).addObject(body) 1369 | App.ActiveDocument.recompute() 1370 | 1371 | print ("\n" + self.d1.currentText() + " Bolt and large washer created") 1372 | 1373 | # ===== Bolt and large washer (slot) ============================================== 1374 | if self.d2.currentText() == "Bolt and large washer" and slot == True: 1375 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt and large washer with slot') 1376 | Gui.activeView().setActiveObject('pdbody', body) 1377 | App.ActiveDocument.recompute() 1378 | 1379 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1380 | body.addObject(cylinder1) 1381 | cylinder1.Radius = washerLargeR 1382 | cylinder1.Height = headH + washerLargeH 1383 | cylinder1.Label = "Head-left" 1384 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1385 | cylinder1.MapReversed = True 1386 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1387 | cylinder1.MapMode = 'FlatFace' 1388 | 1389 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1390 | body.addObject(cube1) 1391 | cube1.Length = slotWidth 1392 | cube1.Width = washerLargeR*2 1393 | cube1.Height = headH + washerLargeH 1394 | cube1.Label = "Head-center" 1395 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -washerLargeR, -headH -washerLargeH), App.Rotation(0.0, 0.0, 0.0)) 1396 | cube1.MapReversed = False 1397 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 1398 | cube1.MapMode = 'FlatFace' 1399 | 1400 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1401 | body.addObject(cylinder2) 1402 | cylinder2.Radius = washerLargeR 1403 | cylinder2.Height = headH + washerLargeH 1404 | cylinder2.Label = "Head-right" 1405 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1406 | cylinder2.MapReversed = True 1407 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1408 | cylinder2.MapMode = 'FlatFace' 1409 | 1410 | cylinder3 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1411 | body.addObject(cylinder3) 1412 | cylinder3.Radius = bodyR 1413 | cylinder3.Height = bodyH + headH + washerLargeH 1414 | cylinder3.Label = "Body-left" 1415 | cylinder3.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1416 | cylinder3.MapReversed = True 1417 | cylinder3.Support = [(App.activeDocument().XY_Plane,'')] 1418 | cylinder3.MapMode = 'FlatFace' 1419 | 1420 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1421 | body.addObject(cube2) 1422 | cube2.Length = slotWidth 1423 | cube2.Width = bodyR*2 1424 | cube2.Height = bodyH + headH + washerLargeH 1425 | cube2.Label = "Body-center" 1426 | cube2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -bodyH - headH - washerLargeH), App.Rotation(0.0, 0.0, 0.0)) 1427 | cube2.MapReversed = False 1428 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 1429 | cube2.MapMode = 'FlatFace' 1430 | 1431 | cylinder4 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1432 | body.addObject(cylinder4) 1433 | cylinder4.Radius = bodyR 1434 | cylinder4.Height = bodyH + headH + washerLargeH 1435 | cylinder4.Label = "Body-right" 1436 | cylinder4.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1437 | cylinder4.MapReversed = True 1438 | cylinder4.Support = [(App.activeDocument().XY_Plane,'')] 1439 | cylinder4.MapMode = 'FlatFace' 1440 | 1441 | body.Placement.Base = App.Vector(originX, originY, originZ) 1442 | body.Placement.Rotation = rot.Q 1443 | 1444 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1445 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1446 | 1447 | Gui.activeDocument().activeObject().Visibility = False 1448 | Gui.activeDocument().activeObject().Visibility = True 1449 | Gui.activeView().setActiveObject('pdbody', None) 1450 | App.ActiveDocument.getObject(groupName).addObject(body) 1451 | App.ActiveDocument.recompute() 1452 | 1453 | #print ("\n" + self.d1.currentText() + " Bolt and large washer with slot created") 1454 | 1455 | # ===== Bolt, nut and washer ============================================== 1456 | elif self.d2.currentText() == "Bolt, nut and washer" and slot == False: 1457 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt nut and washer') 1458 | Gui.activeView().setActiveObject('pdbody', body) 1459 | 1460 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1461 | body.addObject(cylinder1) 1462 | cylinder1.Radius = washerR 1463 | cylinder1.Height = headH + washerH 1464 | cylinder1.Label = "Head" 1465 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1466 | cylinder1.MapReversed = False 1467 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1468 | cylinder1.MapMode = 'FlatFace' 1469 | 1470 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1471 | body.addObject(cylinder2) 1472 | cylinder2.Radius = bodyR 1473 | cylinder2.Height = bodyH + headH + washerH 1474 | cylinder2.Label = "Body" 1475 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1476 | cylinder2.MapReversed = False 1477 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1478 | cylinder2.MapMode = 'FlatFace' 1479 | 1480 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1481 | body.addObject(prism) 1482 | prism.Polygon = 6 1483 | prism.Circumradius = headR 1484 | prism.Height = nutH 1485 | prism.Label = "Nut" 1486 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1487 | prism.MapReversed = False 1488 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1489 | prism.MapMode = 'FlatFace' 1490 | 1491 | body.Placement.Base = App.Vector(originX, originY, originZ) 1492 | body.Placement.Rotation = rot.Q 1493 | 1494 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1495 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1496 | 1497 | Gui.activeDocument().activeObject().Visibility = False 1498 | Gui.activeDocument().activeObject().Visibility = True 1499 | Gui.activeView().setActiveObject('pdbody', None) 1500 | App.ActiveDocument.getObject(groupName).addObject(body) 1501 | App.ActiveDocument.recompute() 1502 | 1503 | print ("\n" + self.d1.currentText() + " Bolt, nut and washer created") 1504 | 1505 | # ===== Bolt, nut and washer (slot) ============================================== 1506 | if self.d2.currentText() == "Bolt, nut and washer" and slot == True: 1507 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt nut and washer with slot') 1508 | Gui.activeView().setActiveObject('pdbody', body) 1509 | App.ActiveDocument.recompute() 1510 | 1511 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1512 | body.addObject(cylinder1) 1513 | cylinder1.Radius = washerR 1514 | cylinder1.Height = headH + washerH 1515 | cylinder1.Label = "Head-left" 1516 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1517 | cylinder1.MapReversed = True 1518 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1519 | cylinder1.MapMode = 'FlatFace' 1520 | 1521 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1522 | body.addObject(cube1) 1523 | cube1.Length = slotWidth 1524 | cube1.Width = washerR*2 1525 | cube1.Height = headH + washerH 1526 | cube1.Label = "Head-center" 1527 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -washerR, -headH -washerH), App.Rotation(0.0, 0.0, 0.0)) 1528 | cube1.MapReversed = False 1529 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 1530 | cube1.MapMode = 'FlatFace' 1531 | 1532 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1533 | body.addObject(cylinder2) 1534 | cylinder2.Radius = washerR 1535 | cylinder2.Height = headH + washerH 1536 | cylinder2.Label = "Head-right" 1537 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1538 | cylinder2.MapReversed = True 1539 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1540 | cylinder2.MapMode = 'FlatFace' 1541 | 1542 | cylinder3 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1543 | body.addObject(cylinder3) 1544 | cylinder3.Radius = bodyR 1545 | cylinder3.Height = bodyH + headH + washerH 1546 | cylinder3.Label = "Body-left" 1547 | cylinder3.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1548 | cylinder3.MapReversed = True 1549 | cylinder3.Support = [(App.activeDocument().XY_Plane,'')] 1550 | cylinder3.MapMode = 'FlatFace' 1551 | 1552 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1553 | body.addObject(cube2) 1554 | cube2.Length = slotWidth 1555 | cube2.Width = bodyR*2 1556 | cube2.Height = bodyH + headH + washerH 1557 | cube2.Label = "Body-center" 1558 | cube2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -bodyH - headH - washerH), App.Rotation(0.0, 0.0, 0.0)) 1559 | cube2.MapReversed = False 1560 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 1561 | cube2.MapMode = 'FlatFace' 1562 | 1563 | cylinder4 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1564 | body.addObject(cylinder4) 1565 | cylinder4.Radius = bodyR 1566 | cylinder4.Height = bodyH + headH + washerH 1567 | cylinder4.Label = "Body-right" 1568 | cylinder4.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1569 | cylinder4.MapReversed = True 1570 | cylinder4.Support = [(App.activeDocument().XY_Plane,'')] 1571 | cylinder4.MapMode = 'FlatFace' 1572 | 1573 | prism1 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1574 | body.addObject(prism1) 1575 | prism1.Polygon = 6 1576 | prism1.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1577 | prism1.Height = nutH 1578 | prism1.Label = "Nut-left" 1579 | prism1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1580 | prism1.MapReversed = False 1581 | prism1.Support = [(App.activeDocument().XY_Plane,'')] 1582 | prism1.MapMode = 'FlatFace' 1583 | 1584 | cube3 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1585 | body.addObject(cube3) 1586 | cube3.Length = slotWidth 1587 | cube3.Width = nutWidth 1588 | cube3.Height = nutH 1589 | cube3.Label = "Nut-center" 1590 | cube3.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -nutWidth/2, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1591 | cube3.MapReversed = False 1592 | cube3.Support = [(App.activeDocument().XY_Plane,'')] 1593 | cube3.MapMode = 'FlatFace' 1594 | 1595 | prism2 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1596 | body.addObject(prism2) 1597 | prism2.Polygon = 6 1598 | prism2.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1599 | prism2.Height = nutH 1600 | prism2.Label = "Nut-right" 1601 | prism2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1602 | prism2.MapReversed = False 1603 | prism2.Support = [(App.activeDocument().XY_Plane,'')] 1604 | prism2.MapMode = 'FlatFace' 1605 | 1606 | body.Placement.Base = App.Vector(originX, originY, originZ) 1607 | body.Placement.Rotation = rot.Q 1608 | 1609 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1610 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1611 | 1612 | Gui.activeDocument().activeObject().Visibility = False 1613 | Gui.activeDocument().activeObject().Visibility = True 1614 | Gui.activeView().setActiveObject('pdbody', None) 1615 | App.ActiveDocument.getObject(groupName).addObject(body) 1616 | App.ActiveDocument.recompute() 1617 | 1618 | #print ("\n" + self.d1.currentText() + " Bolt, nut and washer with slot created") 1619 | 1620 | # ===== Bolt, nut and large washer ============================================== 1621 | elif self.d2.currentText() == "Bolt, nut and large washer": 1622 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt nut and large washer') 1623 | Gui.activeView().setActiveObject('pdbody', body) 1624 | 1625 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1626 | body.addObject(cylinder1) 1627 | cylinder1.Radius = washerLargeR 1628 | cylinder1.Height = headH + washerLargeH 1629 | cylinder1.Label = "Head" 1630 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1631 | cylinder1.MapReversed = False 1632 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1633 | cylinder1.MapMode = 'FlatFace' 1634 | 1635 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1636 | body.addObject(cylinder2) 1637 | cylinder2.Radius = bodyR 1638 | cylinder2.Height = bodyH + headH + washerLargeH 1639 | cylinder2.Label = "Body" 1640 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1641 | cylinder2.MapReversed = False 1642 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1643 | cylinder2.MapMode = 'FlatFace' 1644 | 1645 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1646 | body.addObject(prism) 1647 | prism.Polygon = 6 1648 | prism.Circumradius = headR 1649 | prism.Height = nutH 1650 | prism.Label = "Nut" 1651 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1652 | prism.MapReversed = False 1653 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1654 | prism.MapMode = 'FlatFace' 1655 | 1656 | body.Placement.Base = App.Vector(originX, originY, originZ) 1657 | body.Placement.Rotation = rot.Q 1658 | 1659 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1660 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1661 | 1662 | Gui.activeDocument().activeObject().Visibility = False 1663 | Gui.activeDocument().activeObject().Visibility = True 1664 | Gui.activeView().setActiveObject('pdbody', None) 1665 | App.ActiveDocument.getObject(groupName).addObject(body) 1666 | App.ActiveDocument.recompute() 1667 | 1668 | print ("\n" + self.d1.currentText() + " Bolt, nut and large washer created") 1669 | 1670 | # ===== Bolt, nut and large washer (slot) ============================================== 1671 | if self.d2.currentText() == "Bolt, nut and large washer" and slot == True: 1672 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt nut and large washer with slot') 1673 | Gui.activeView().setActiveObject('pdbody', body) 1674 | App.ActiveDocument.recompute() 1675 | 1676 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1677 | body.addObject(cylinder1) 1678 | cylinder1.Radius = washerLargeR 1679 | cylinder1.Height = headH + washerLargeH 1680 | cylinder1.Label = "Head-left" 1681 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1682 | cylinder1.MapReversed = True 1683 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1684 | cylinder1.MapMode = 'FlatFace' 1685 | 1686 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1687 | body.addObject(cube1) 1688 | cube1.Length = slotWidth 1689 | cube1.Width = washerLargeR*2 1690 | cube1.Height = headH + washerLargeH 1691 | cube1.Label = "Head-center" 1692 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -washerLargeR, -headH -washerLargeH), App.Rotation(0.0, 0.0, 0.0)) 1693 | cube1.MapReversed = False 1694 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 1695 | cube1.MapMode = 'FlatFace' 1696 | 1697 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1698 | body.addObject(cylinder2) 1699 | cylinder2.Radius = washerLargeR 1700 | cylinder2.Height = headH + washerLargeH 1701 | cylinder2.Label = "Head-right" 1702 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1703 | cylinder2.MapReversed = True 1704 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1705 | cylinder2.MapMode = 'FlatFace' 1706 | 1707 | cylinder3 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1708 | body.addObject(cylinder3) 1709 | cylinder3.Radius = bodyR 1710 | cylinder3.Height = bodyH + headH + washerLargeH 1711 | cylinder3.Label = "Body-left" 1712 | cylinder3.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1713 | cylinder3.MapReversed = True 1714 | cylinder3.Support = [(App.activeDocument().XY_Plane,'')] 1715 | cylinder3.MapMode = 'FlatFace' 1716 | 1717 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1718 | body.addObject(cube2) 1719 | cube2.Length = slotWidth 1720 | cube2.Width = bodyR*2 1721 | cube2.Height = bodyH + headH + washerLargeH 1722 | cube2.Label = "Body-center" 1723 | cube2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -bodyR, -bodyH - headH - washerLargeH), App.Rotation(0.0, 0.0, 0.0)) 1724 | cube2.MapReversed = False 1725 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 1726 | cube2.MapMode = 'FlatFace' 1727 | 1728 | cylinder4 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1729 | body.addObject(cylinder4) 1730 | cylinder4.Radius = bodyR 1731 | cylinder4.Height = bodyH + headH + washerLargeH 1732 | cylinder4.Label = "Body-right" 1733 | cylinder4.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 1734 | cylinder4.MapReversed = True 1735 | cylinder4.Support = [(App.activeDocument().XY_Plane,'')] 1736 | cylinder4.MapMode = 'FlatFace' 1737 | 1738 | prism1 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1739 | body.addObject(prism1) 1740 | prism1.Polygon = 6 1741 | prism1.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1742 | prism1.Height = nutH 1743 | prism1.Label = "Nut-left" 1744 | prism1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1745 | prism1.MapReversed = False 1746 | prism1.Support = [(App.activeDocument().XY_Plane,'')] 1747 | prism1.MapMode = 'FlatFace' 1748 | 1749 | cube3 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1750 | body.addObject(cube3) 1751 | cube3.Length = slotWidth 1752 | cube3.Width = nutWidth 1753 | cube3.Height = nutH 1754 | cube3.Label = "Nut-center" 1755 | cube3.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -nutWidth/2, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1756 | cube3.MapReversed = False 1757 | cube3.Support = [(App.activeDocument().XY_Plane,'')] 1758 | cube3.MapMode = 'FlatFace' 1759 | 1760 | prism2 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1761 | body.addObject(prism2) 1762 | prism2.Polygon = 6 1763 | prism2.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1764 | prism2.Height = nutH 1765 | prism2.Label = "Nut-right" 1766 | prism2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1767 | prism2.MapReversed = False 1768 | prism2.Support = [(App.activeDocument().XY_Plane,'')] 1769 | prism2.MapMode = 'FlatFace' 1770 | 1771 | body.Placement.Base = App.Vector(originX, originY, originZ) 1772 | body.Placement.Rotation = rot.Q 1773 | 1774 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1775 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1776 | 1777 | Gui.activeDocument().activeObject().Visibility = False 1778 | Gui.activeDocument().activeObject().Visibility = True 1779 | Gui.activeView().setActiveObject('pdbody', None) 1780 | App.ActiveDocument.getObject(groupName).addObject(body) 1781 | App.ActiveDocument.recompute() 1782 | 1783 | #print ("\n" + self.d1.currentText() + " Bolt, nut and large washer with slot created") 1784 | 1785 | # ===== Bolt, grooved nut and washer ============================================== 1786 | elif self.d2.currentText() == "Bolt, grooved nut and washer": 1787 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt grooved nut and washer') 1788 | Gui.activeView().setActiveObject('pdbody', body) 1789 | 1790 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1791 | body.addObject(cylinder1) 1792 | cylinder1.Radius = washerR 1793 | cylinder1.Height = headH + washerH 1794 | cylinder1.Label = "Head" 1795 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1796 | cylinder1.MapReversed = False 1797 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1798 | cylinder1.MapMode = 'FlatFace' 1799 | 1800 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1801 | body.addObject(cylinder2) 1802 | cylinder2.Radius = bodyR 1803 | cylinder2.Height = bodyH + headH + washerH 1804 | cylinder2.Label = "Body" 1805 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1806 | cylinder2.MapReversed = False 1807 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1808 | cylinder2.MapMode = 'FlatFace' 1809 | 1810 | cube = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1811 | body.addObject(cube) 1812 | cube.Length = grooveLength 1813 | cube.Width = nutWidth 1814 | cube.Height = nutH 1815 | cube.Label = "Groove" 1816 | cube.AttachmentOffset = App.Placement(App.Vector(0.0, -cube.Width/2,-nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1817 | cube.MapReversed = False 1818 | cube.Support = [(App.activeDocument().XY_Plane,'')] 1819 | cube.MapMode = 'FlatFace' 1820 | 1821 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1822 | body.addObject(prism) 1823 | prism.Polygon = 6 1824 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1825 | prism.Height = nutH 1826 | prism.Label = "Nut" 1827 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1828 | prism.MapReversed = False 1829 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1830 | prism.MapMode = 'FlatFace' 1831 | 1832 | body.Placement.Base = App.Vector(originX, originY, originZ) 1833 | body.Placement.Rotation = rot.Q 1834 | 1835 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1836 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1837 | 1838 | Gui.activeDocument().activeObject().Visibility = False 1839 | Gui.activeDocument().activeObject().Visibility = True 1840 | Gui.activeView().setActiveObject('pdbody', None) 1841 | App.ActiveDocument.getObject(groupName).addObject(body) 1842 | App.ActiveDocument.recompute() 1843 | 1844 | print ("\n" + self.d1.currentText() + " Bolt, grooved nut and washer created") 1845 | 1846 | # ===== Bolt, grooved nut and large washer ============================================== 1847 | elif self.d2.currentText() == "Bolt, grooved nut and large washer": 1848 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Bolt grooved nut and large washer') 1849 | Gui.activeView().setActiveObject('pdbody', body) 1850 | 1851 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 1852 | body.addObject(cylinder1) 1853 | cylinder1.Radius = washerLargeR 1854 | cylinder1.Height = headH + washerLargeH 1855 | cylinder1.Label = "Head" 1856 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1857 | cylinder1.MapReversed = False 1858 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 1859 | cylinder1.MapMode = 'FlatFace' 1860 | 1861 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder2") 1862 | body.addObject(cylinder2) 1863 | cylinder2.Radius = bodyR 1864 | cylinder2.Height = bodyH + headH + washerLargeH 1865 | cylinder2.Label = "Body" 1866 | cylinder2.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1867 | cylinder2.MapReversed = False 1868 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 1869 | cylinder2.MapMode = 'FlatFace' 1870 | 1871 | cube = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1872 | body.addObject(cube) 1873 | cube.Length = grooveLength 1874 | cube.Width = nutWidth 1875 | cube.Height = nutH 1876 | cube.Label = "Groove" 1877 | cube.AttachmentOffset = App.Placement(App.Vector(0.0, -cube.Width/2,-nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1878 | cube.MapReversed = False 1879 | cube.Support = [(App.activeDocument().XY_Plane,'')] 1880 | cube.MapMode = 'FlatFace' 1881 | 1882 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1883 | body.addObject(prism) 1884 | prism.Polygon = 6 1885 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1886 | prism.Height = nutH 1887 | prism.Label = "Nut" 1888 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -nutDisplacement), App.Rotation(0.0, 0.0, 0.0)) 1889 | prism.MapReversed = False 1890 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1891 | prism.MapMode = 'FlatFace' 1892 | 1893 | body.Placement.Base = App.Vector(originX, originY, originZ) 1894 | body.Placement.Rotation = rot.Q 1895 | 1896 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1897 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1898 | 1899 | Gui.activeDocument().activeObject().Visibility = False 1900 | Gui.activeDocument().activeObject().Visibility = True 1901 | Gui.activeView().setActiveObject('pdbody', None) 1902 | App.ActiveDocument.getObject(groupName).addObject(body) 1903 | App.ActiveDocument.recompute() 1904 | 1905 | print ("\n" + self.d1.currentText() + " Bolt, grooved nut and washer created") 1906 | 1907 | # ===== Nut ============================================== 1908 | elif self.d2.currentText() == "Nut" and slot == False: 1909 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Nut') 1910 | Gui.activeView().setActiveObject('pdbody', body) 1911 | 1912 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1913 | body.addObject(prism) 1914 | prism.Polygon = 6 1915 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1916 | prism.Height = nutH 1917 | prism.Label = "Nut" 1918 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1919 | prism.MapReversed = False 1920 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1921 | prism.MapMode = 'FlatFace' 1922 | 1923 | body.Placement.Base = App.Vector(originX, originY, originZ) 1924 | body.Placement.Rotation = rot.Q 1925 | 1926 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1927 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1928 | Gui.activeView().setActiveObject('pdbody', None) 1929 | App.ActiveDocument.getObject(groupName).addObject(body) 1930 | App.ActiveDocument.recompute() 1931 | 1932 | print ("\n" + self.d1.currentText() + " Nut created") 1933 | 1934 | # ===== Nut (slot) ============================================== 1935 | elif self.d2.currentText() == "Nut" and slot == True: 1936 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Nut with slot') 1937 | Gui.activeView().setActiveObject('pdbody', body) 1938 | 1939 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 1940 | body.addObject(prism) 1941 | prism.Polygon = 6 1942 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1943 | prism.Height = nutH 1944 | prism.Label = "Nut with slot" 1945 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1946 | prism.MapReversed = False 1947 | prism.Support = [(App.activeDocument().XY_Plane,'')] 1948 | prism.MapMode = 'FlatFace' 1949 | 1950 | 1951 | 1952 | prism1 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1953 | body.addObject(prism1) 1954 | prism1.Polygon = 6 1955 | prism1.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1956 | prism1.Height = nutH 1957 | prism1.Label = "Nut-left" 1958 | prism1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1959 | prism1.MapReversed = False 1960 | prism1.Support = [(App.activeDocument().XY_Plane,'')] 1961 | prism1.MapMode = 'FlatFace' 1962 | 1963 | cube = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 1964 | body.addObject(cube) 1965 | cube.Length = slotWidth 1966 | cube.Width = nutWidth 1967 | cube.Height = nutH 1968 | cube.Label = "Nut-center" 1969 | cube.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -nutWidth/2, -nutH), App.Rotation(0.0, 0.0, 0.0)) 1970 | cube.MapReversed = False 1971 | cube.Support = [(App.activeDocument().XY_Plane,'')] 1972 | cube.MapMode = 'FlatFace' 1973 | 1974 | prism2 = App.ActiveDocument.addObject('PartDesign::AdditivePrism','Prism') 1975 | body.addObject(prism2) 1976 | prism2.Polygon = 6 1977 | prism2.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 1978 | prism2.Height = nutH 1979 | prism2.Label = "Nut-right" 1980 | prism2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 1981 | prism2.MapReversed = False 1982 | prism2.Support = [(App.activeDocument().XY_Plane,'')] 1983 | prism2.MapMode = 'FlatFace' 1984 | 1985 | body.Placement.Base = App.Vector(originX, originY, originZ) 1986 | body.Placement.Rotation = rot.Q 1987 | 1988 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 1989 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 1990 | Gui.activeView().setActiveObject('pdbody', None) 1991 | App.ActiveDocument.getObject(groupName).addObject(body) 1992 | App.ActiveDocument.recompute() 1993 | 1994 | print ("\n" + self.d1.currentText() + " Nut with slot created") 1995 | 1996 | # ===== Grooved nut ============================================== 1997 | elif self.d2.currentText() == "Grooved nut": 1998 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Grooved nut') 1999 | Gui.activeView().setActiveObject('pdbody', body) 2000 | 2001 | cube = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 2002 | body.addObject(cube) 2003 | cube.Length = grooveLength 2004 | cube.Width = nutWidth 2005 | cube.Height = nutH 2006 | cube.Label = "Groove" 2007 | cube.AttachmentOffset = App.Placement(App.Vector(0.0, -cube.Width/2, -nutH), App.Rotation(0.0, 0.0, 0.0)) 2008 | cube.MapReversed = False 2009 | cube.Support = [(App.activeDocument().XY_Plane,'')] 2010 | cube.MapMode = 'FlatFace' 2011 | 2012 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 2013 | body.addObject(prism) 2014 | prism.Polygon = 6 2015 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 2016 | prism.Height = nutH 2017 | prism.Label = "Nut" 2018 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 2019 | prism.MapReversed = False 2020 | prism.Support = [(App.activeDocument().XY_Plane,'')] 2021 | prism.MapMode = 'FlatFace' 2022 | 2023 | body.Placement.Base = App.Vector(originX, originY, originZ) 2024 | body.Placement.Rotation = rot.Q 2025 | 2026 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2027 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2028 | 2029 | Gui.activeDocument().activeObject().Visibility = False 2030 | Gui.activeDocument().activeObject().Visibility = True 2031 | Gui.activeView().setActiveObject('pdbody', None) 2032 | App.ActiveDocument.getObject(groupName).addObject(body) 2033 | App.ActiveDocument.recompute() 2034 | 2035 | print ("\n" + self.d1.currentText() + " Grooved nut created") 2036 | 2037 | # ===== Nut and washer ============================================== 2038 | elif self.d2.currentText() == "Nut and washer" and slot == False: 2039 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Nut and washer') 2040 | Gui.activeView().setActiveObject('pdbody', body) 2041 | 2042 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2043 | body.addObject(cylinder1) 2044 | cylinder1.Radius = washerR 2045 | cylinder1.Height = nutH + washerH 2046 | cylinder1.Label = "Head" 2047 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 2048 | cylinder1.MapReversed = False 2049 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 2050 | cylinder1.MapMode = 'FlatFace' 2051 | 2052 | body.Placement.Base = App.Vector(originX, originY, originZ) 2053 | body.Placement.Rotation = rot.Q 2054 | 2055 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2056 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2057 | Gui.activeView().setActiveObject('pdbody', None) 2058 | App.ActiveDocument.getObject(groupName).addObject(body) 2059 | App.ActiveDocument.recompute() 2060 | 2061 | print ("\n" + self.d1.currentText() + " Nut and washer created") 2062 | 2063 | # ===== Nut and washer (slot) ============================================== 2064 | elif self.d2.currentText() == "Nut and washer" and slot == True: 2065 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Nut and washer with slot') 2066 | Gui.activeView().setActiveObject('pdbody', body) 2067 | 2068 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2069 | body.addObject(cylinder1) 2070 | cylinder1.Radius = washerR 2071 | cylinder1.Height = nutH + washerH 2072 | cylinder1.Label = "Head-left" 2073 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 2074 | cylinder1.MapReversed = True 2075 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 2076 | cylinder1.MapMode = 'FlatFace' 2077 | 2078 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 2079 | body.addObject(cube1) 2080 | cube1.Length = slotWidth 2081 | cube1.Width = washerR*2 2082 | cube1.Height = nutH + washerH 2083 | cube1.Label = "Head-center" 2084 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -washerR, -nutH - washerH), App.Rotation(0.0, 0.0, 0.0)) 2085 | cube1.MapReversed = False 2086 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 2087 | cube1.MapMode = 'FlatFace' 2088 | 2089 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2090 | body.addObject(cylinder2) 2091 | cylinder2.Radius = washerR 2092 | cylinder2.Height = nutH + washerH 2093 | cylinder2.Label = "Head-right" 2094 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 2095 | cylinder2.MapReversed = True 2096 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 2097 | cylinder2.MapMode = 'FlatFace' 2098 | 2099 | body.Placement.Base = App.Vector(originX, originY, originZ) 2100 | body.Placement.Rotation = rot.Q 2101 | 2102 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2103 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2104 | Gui.activeView().setActiveObject('pdbody', None) 2105 | App.ActiveDocument.getObject(groupName).addObject(body) 2106 | App.ActiveDocument.recompute() 2107 | 2108 | print ("\n" + self.d1.currentText() + " Nut and washer with slot created") 2109 | 2110 | # ===== Nut and large washer ============================================== 2111 | elif self.d2.currentText() == "Nut and large washer" and slot == False: 2112 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Nut and large washer') 2113 | Gui.activeView().setActiveObject('pdbody', body) 2114 | 2115 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2116 | body.addObject(cylinder1) 2117 | cylinder1.Radius = washerLargeR 2118 | cylinder1.Height = nutH + washerLargeH 2119 | cylinder1.Label = "Head" 2120 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 2121 | cylinder1.MapReversed = False 2122 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 2123 | cylinder1.MapMode = 'FlatFace' 2124 | 2125 | body.Placement.Base = App.Vector(originX, originY, originZ) 2126 | body.Placement.Rotation = rot.Q 2127 | 2128 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2129 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2130 | Gui.activeView().setActiveObject('pdbody', None) 2131 | App.ActiveDocument.getObject(groupName).addObject(body) 2132 | App.ActiveDocument.recompute() 2133 | 2134 | print ("\n" + self.d1.currentText() + " Nut and large washer created") 2135 | 2136 | # ===== Nut and large washer (slot) ============================================== 2137 | elif self.d2.currentText() == "Nut and large washer" and slot == True: 2138 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Nut and large washer with slot') 2139 | Gui.activeView().setActiveObject('pdbody', body) 2140 | 2141 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2142 | body.addObject(cylinder1) 2143 | cylinder1.Radius = washerLargeR 2144 | cylinder1.Height = nutH + washerLargeH 2145 | cylinder1.Label = "Head-left" 2146 | cylinder1.AttachmentOffset = App.Placement(App.Vector(slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 2147 | cylinder1.MapReversed = True 2148 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 2149 | cylinder1.MapMode = 'FlatFace' 2150 | 2151 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube") 2152 | body.addObject(cube1) 2153 | cube1.Length = slotWidth 2154 | cube1.Width = washerLargeR*2 2155 | cube1.Height = nutH + washerLargeH 2156 | cube1.Label = "Head-center" 2157 | cube1.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, -washerLargeR, -nutH - washerLargeH), App.Rotation(0.0, 0.0, 0.0)) 2158 | cube1.MapReversed = False 2159 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 2160 | cube1.MapMode = 'FlatFace' 2161 | 2162 | cylinder2 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2163 | body.addObject(cylinder2) 2164 | cylinder2.Radius = washerLargeR 2165 | cylinder2.Height = nutH + washerLargeH 2166 | cylinder2.Label = "Head-right" 2167 | cylinder2.AttachmentOffset = App.Placement(App.Vector(-slotWidth/2, 0.0, 0.0), App.Rotation(0.0, 0.0, 0.0)) 2168 | cylinder2.MapReversed = True 2169 | cylinder2.Support = [(App.activeDocument().XY_Plane,'')] 2170 | cylinder2.MapMode = 'FlatFace' 2171 | 2172 | body.Placement.Base = App.Vector(originX, originY, originZ) 2173 | body.Placement.Rotation = rot.Q 2174 | 2175 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2176 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2177 | Gui.activeView().setActiveObject('pdbody', None) 2178 | App.ActiveDocument.getObject(groupName).addObject(body) 2179 | App.ActiveDocument.recompute() 2180 | 2181 | print ("\n" + self.d1.currentText() + " Nut and large washer with slot created") 2182 | 2183 | # ===== Grooved nut and washer ============================================== 2184 | elif self.d2.currentText() == "Grooved nut and washer": 2185 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Grooved nut and large washer') 2186 | Gui.activeView().setActiveObject('pdbody', body) 2187 | 2188 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2189 | body.addObject(cylinder1) 2190 | cylinder1.Radius = washerR 2191 | cylinder1.Height = washerH 2192 | cylinder1.Label = "Washer" 2193 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 2194 | cylinder1.MapReversed = False 2195 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 2196 | cylinder1.MapMode = 'FlatFace' 2197 | 2198 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube1") 2199 | body.addObject(cube1) 2200 | cube1.Length = grooveLength 2201 | cube1.Width = washerR * 2 2202 | cube1.Height = washerH 2203 | cube1.Label = "Washer groove" 2204 | cube1.AttachmentOffset = App.Placement(App.Vector(0.0, -cube1.Width/2, -washerH), App.Rotation(0.0, 0.0, 0.0)) 2205 | cube1.MapReversed = False 2206 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 2207 | cube1.MapMode = 'FlatFace' 2208 | 2209 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube2") 2210 | body.addObject(cube2) 2211 | cube2.Length = grooveLength 2212 | cube2.Width = nutWidth 2213 | cube2.Height = nutH 2214 | cube2.Label = "Nut groove" 2215 | cube2.AttachmentOffset = App.Placement(App.Vector(0.0, -cube2.Width/2, -washerH-nutH), App.Rotation(0.0, 0.0, 0.0)) 2216 | cube2.MapReversed = False 2217 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 2218 | cube2.MapMode = 'FlatFace' 2219 | 2220 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 2221 | body.addObject(prism) 2222 | prism.Polygon = 6 2223 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 2224 | prism.Height = nutH 2225 | prism.Label = "Nut" 2226 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -washerH), App.Rotation(0.0, 0.0, 180.0)) 2227 | prism.MapReversed = False 2228 | prism.Support = [(App.activeDocument().XY_Plane,'')] 2229 | prism.MapMode = 'FlatFace' 2230 | 2231 | body.Placement.Base = App.Vector(originX, originY, originZ) 2232 | body.Placement.Rotation = rot.Q 2233 | 2234 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2235 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2236 | 2237 | Gui.activeDocument().activeObject().Visibility = False 2238 | Gui.activeDocument().activeObject().Visibility = True 2239 | Gui.activeView().setActiveObject('pdbody', None) 2240 | App.ActiveDocument.getObject(groupName).addObject(body) 2241 | App.ActiveDocument.recompute() 2242 | 2243 | print ("\n" + self.d1.currentText() + " Grooved nut and washer created") 2244 | 2245 | # ===== Grooved nut and large washer ============================================== 2246 | elif self.d2.currentText() == "Grooved nut and large washer": 2247 | body = App.ActiveDocument.addObject("PartDesign::Body",self.d1.currentText() + ' Grooved nut and large large washer') 2248 | Gui.activeView().setActiveObject('pdbody', body) 2249 | 2250 | cylinder1 = App.ActiveDocument.addObject("PartDesign::AdditiveCylinder","Cylinder1") 2251 | body.addObject(cylinder1) 2252 | cylinder1.Radius = washerLargeR 2253 | cylinder1.Height = washerLargeH 2254 | cylinder1.Label = "Washer" 2255 | cylinder1.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, 0.0), App.Rotation(0.0, 0.0, 180.0)) 2256 | cylinder1.MapReversed = False 2257 | cylinder1.Support = [(App.activeDocument().XY_Plane,'')] 2258 | cylinder1.MapMode = 'FlatFace' 2259 | 2260 | cube1 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube1") 2261 | body.addObject(cube1) 2262 | cube1.Length = grooveLength 2263 | cube1.Width = washerLargeR * 2 2264 | cube1.Height = washerLargeH 2265 | cube1.Label = "Washer groove" 2266 | cube1.AttachmentOffset = App.Placement(App.Vector(0.0, -cube1.Width/2, -washerLargeH), App.Rotation(0.0, 0.0, 0.0)) 2267 | cube1.MapReversed = False 2268 | cube1.Support = [(App.activeDocument().XY_Plane,'')] 2269 | cube1.MapMode = 'FlatFace' 2270 | 2271 | cube2 = App.ActiveDocument.addObject("PartDesign::AdditiveBox","Cube2") 2272 | body.addObject(cube2) 2273 | cube2.Length = grooveLength 2274 | cube2.Width = nutWidth 2275 | cube2.Height = nutH 2276 | cube2.Label = "Nut groove" 2277 | cube2.AttachmentOffset = App.Placement(App.Vector(0.0, -cube2.Width/2, -washerLargeH-nutH), App.Rotation(0.0, 0.0, 0.0)) 2278 | cube2.MapReversed = False 2279 | cube2.Support = [(App.activeDocument().XY_Plane,'')] 2280 | cube2.MapMode = 'FlatFace' 2281 | 2282 | prism = App.ActiveDocument.addObject("PartDesign::AdditivePrism","Prism") 2283 | body.addObject(prism) 2284 | prism.Polygon = 6 2285 | prism.Circumradius = nutWidth / 2 / cos(math.radians(180/float(6))) 2286 | prism.Height = nutH 2287 | prism.Label = "Nut" 2288 | prism.AttachmentOffset = App.Placement(App.Vector(0.0, 0.0, -washerLargeH), App.Rotation(0.0, 0.0, 180.0)) 2289 | prism.MapReversed = False 2290 | prism.Support = [(App.activeDocument().XY_Plane,'')] 2291 | prism.MapMode = 'FlatFace' 2292 | 2293 | body.Placement.Base = App.Vector(originX, originY, originZ) 2294 | body.Placement.Rotation = rot.Q 2295 | 2296 | Gui.activeDocument().activeObject().ShapeColor = bodyColor 2297 | Gui.activeDocument().activeObject().Transparency = bodyTransparency 2298 | 2299 | Gui.activeDocument().activeObject().Visibility = False 2300 | Gui.activeDocument().activeObject().Visibility = True 2301 | Gui.activeView().setActiveObject('pdbody', None) 2302 | App.ActiveDocument.getObject(groupName).addObject(body) 2303 | App.ActiveDocument.recompute() 2304 | 2305 | print ("\n" + self.d1.currentText() + " Grooved nut and large washer created") 2306 | 2307 | # ===== If errors ============================================== 2308 | else: 2309 | FreeCAD.Console.PrintError("\nError or 'TODO'") 2310 | 2311 | App.ActiveDocument.recompute() 2312 | # Gui.SendMsgToActiveView("ViewFit") 2313 | print ("\n********* END *********") 2314 | 2315 | ############################################################################################################### 2316 | 2317 | 2318 | def Alg_singleInstance(): 2319 | app = QtGui.QApplication 2320 | 2321 | for i in app.topLevelWidgets(): 2322 | if i.objectName() == "fastenerHoles": 2323 | i.deleteLater() 2324 | else: 2325 | pass 2326 | t=FreeCADGui.getMainWindow() 2327 | dw=t.findChildren(QtGui.QDockWidget) 2328 | #print str(dw) 2329 | for i in dw: 2330 | #say str(i.objectName()) 2331 | if str(i.objectName()) == "fastenerHoles": 2332 | i.deleteLater() 2333 | else: 2334 | pass 2335 | ## 2336 | 2337 | def Alg_checkInstance(): 2338 | app = QtGui.QApplication 2339 | 2340 | foundAlg=False 2341 | for i in app.topLevelWidgets(): 2342 | if i.objectName() == "fastenerHoles": 2343 | foundAlg=True 2344 | else: 2345 | pass 2346 | t=FreeCADGui.getMainWindow() 2347 | dw=t.findChildren(QtGui.QDockWidget) 2348 | #print str(dw) 2349 | for i in dw: 2350 | #say str(i.objectName()) 2351 | if str(i.objectName()) == "fastenerHoles": 2352 | foundAlg=True 2353 | else: 2354 | pass 2355 | return foundAlg 2356 | ## 2357 | 2358 | ############################################################## 2359 | 2360 | doc=FreeCAD.ActiveDocument 2361 | 2362 | Alg_singleInstance() 2363 | 2364 | ALGDockWidget = QtGui.QDockWidget() # create a new dockwidget 2365 | ALGDockWidget.ui = Ui_DockWidget() # load the Ui script 2366 | ALGDockWidget.ui.setupUi(ALGDockWidget) # setup the Ui 2367 | #ui = Ui_AlignDockWidget() 2368 | #ui.setupUi(AlignDockWidget) 2369 | #AlignDockWidget.show() 2370 | 2371 | ALGDockWidget.setObjectName("fastenerHoles") 2372 | 2373 | ALGDockWidget.setFloating(True) #undock 2374 | ALGDockWidget.resize(sizeX,sizeY) 2375 | ALGDockWidget.activateWindow() 2376 | ALGDockWidget.raise_() 2377 | 2378 | #ALGDockWidget.show() 2379 | 2380 | ALGDockWidget.setFeatures( QtGui.QDockWidget.DockWidgetMovable | QtGui.QDockWidget.DockWidgetFloatable|QtGui.QDockWidget.DockWidgetClosable ) 2381 | # 2382 | # if ALGDockWidget.style().metaObject().className()== "QStyleSheetStyle": 2383 | # ALGDockWidget.setStyleSheet('QPushButton {border-radius: 0px; padding: 1px 2px;}') 2384 | 2385 | ALGmw = FreeCADGui.getMainWindow() # PySide # the active qt window = the freecad window since we are inside it 2386 | ALGmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,ALGDockWidget) 2387 | #ALGDockWidget.show() 2388 | Alg_undock() 2389 | 2390 | ### ------------------------------------------------------------------------------------ ### 2391 | --------------------------------------------------------------------------------