From 915eb39051e07259f7dcf9824e7d32e8bed02d63 Mon Sep 17 00:00:00 2001 From: vectronic Date: Mon, 21 Feb 2022 11:00:14 +0000 Subject: [PATCH] feature: added macro to add technic pin to existing body --- README.md | 9 +++++++ legify-technic-pin.FCMacro | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 legify-technic-pin.FCMacro diff --git a/README.md b/README.md index d313d03..7bf0cf4 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ to create parametric models in FreeCAD is quite possibly insane! ## Usage +### Create a new brick model 1. Create a new document 1. Run the `legify-brick.FCMacro` 1. Modify parameters as desired in the popup dialog @@ -42,6 +43,14 @@ to create parametric models in FreeCAD is quite possibly insane! 1. Wait for a lot of sketches, constraints, pads, pockets and fillets to be rendered... 1. Admire the resulting beauty! +### Add a technic pin to the face of a body +1. Within the Part Design workbench, create a body. +2. Create a datum point on an existing face representing the centre point of the base of the pin. +3. Create a datum point extended 8mm from the normal to the face representing the centre point of the tip of the pin. +4. Create a datum line supported by the base datum point and the tip datum point in that order. +5. Select the body and select the datum line. +6. Run the `legify-technic-pin.FCMacro` + ## TODO - [ ] Wait for [Linear Pattern bug fix](https://tracker.freecad.org/view.php?id=4781) needed when rendering more than one technic pin diff --git a/legify-technic-pin.FCMacro b/legify-technic-pin.FCMacro new file mode 100644 index 0000000..2ddcfd3 --- /dev/null +++ b/legify-technic-pin.FCMacro @@ -0,0 +1,49 @@ +# coding: UTF-8 + +import sys +import os.path + +# get the path of the current python script +current_path = os.path.dirname(os.path.realpath(__file__)) + +# check if this path belongs to the PYTHONPATH variable and if not add it +if not sys.path.__contains__(str(current_path)): + sys.path.append(str(current_path)) + +from FreeCAD import Console, Gui, activeDocument +from PySide2.QtWidgets import QMessageBox +from PySide2.QtCore import Qt +from Legify.Common import * + +if not Gui.activeDocument(): + + Console.PrintMessage("No active document!\n") + dialog = QMessageBox(QMessageBox.Warning, 'No active document!', "There is no active document!") + dialog.setWindowModality(Qt.ApplicationModal) + dialog.exec_() + + exit(1) + +selection = Gui.Selection.getSelection() + +if not selection[0]: + + Console.PrintMessage("No selected body!\n") + dialog = QMessageBox(QMessageBox.Warning, 'No selected body!', "There is no selected body!") + dialog.setWindowModality(Qt.ApplicationModal) + dialog.exec_() + + exit(1) + +if not selection[1]: + Console.PrintMessage("No selected datum line!\n") + dialog = QMessageBox(QMessageBox.Warning, 'No selected datum line!', "There is no selected datum line!") + dialog.setWindowModality(Qt.ApplicationModal) + dialog.exec_() + + exit(1) + +render_pin('Pin', selection[1], selection[0], activeDocument()) + +Gui.activeDocument().activeView().viewAxonometric() +Gui.SendMsgToActiveView("ViewFit")