├── .gitignore ├── .gitmodules ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CQGui ├── Command.py ├── HelpDialog.py ├── Shared.py ├── __init__.py ├── display.py └── icons │ └── CQ_Logo.svg ├── Init.py ├── InitGui.py ├── LICENSE ├── README.md ├── __init__.py ├── changes.md ├── docs ├── _config.yml ├── cqfm_user_interface.png ├── developers.md ├── images │ ├── addon_manager_menu_item.png │ ├── cadquery_dependencies_error_dialog.png │ ├── cadquery_menu_item.png │ ├── cadquery_module_addon_manager_item.png │ ├── cadquery_workbench_addon_manager_item.png │ ├── cadquery_workbench_item.png │ ├── execute_macro_button.png │ ├── execute_macros_dialog.png │ └── install_cadquery_stable_submenu_item.png ├── index.md ├── installation.md └── usage.md └── package.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .idea/ 3 | .DS_Store 4 | temp/ 5 | .vscode/ 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadQuery/cadquery-freecad-workbench/b3d31945ab08ffc9202b78b6a988fecd71d90d2e/.gitmodules -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | It is asked that all contributions to this project be made in a respectful and considerate way. This project has adopted the [Python Community Code of Conduct's](https://www.python.org/psf/codeofconduct/) guidelines. 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Thank you for your interest in contributing to the CadQuery Module for FreeCAD. Contributions by the community are welcome and appreciated. 4 | 5 | This guide was created to help get contributors up and running as quickly as possible. Following these guidelines will help ensure that issues get resolved more quickly and efficiently. 6 | 7 | You do not need to be a software developer to have a big impact on this project. Contributions can take many forms including, but not limited to, the following: 8 | 9 | * Writing and improving documentation 10 | * Triaging bugs 11 | * Submitting bugs and feature requests 12 | * Creating tutorial videos and blog posts 13 | * Helping other users get started and solve problems 14 | * Telling others about this project 15 | * Helping with translations and internationalization 16 | * Helping with accessibility 17 | * Contributing bug fixes and new features 18 | 19 | # Code of Conduct 20 | It is asked that all contributions to this project be made in a respectful and considerate way. This project has adopted the [Python Community Code of Conduct's](https://www.python.org/psf/codeofconduct/) guidelines. 21 | 22 | # Technical Guidelines 23 | Beyond being good to one another, there are technical guidelines for contributing to this project as well. 24 | 25 | * Create issues and pull requests for any major changes and enhancements that you wish to contribute back to the project. Discuss things transparently and get community feedback. 26 | * Be welcoming and encouraging to new contributors. Again, see the [Python Community Code of Conduct](https://www.python.org/psf/codeofconduct/). 27 | 28 | # First Time Contributors 29 | There is no need to be nervous about making your first contribution. Everybody is a beginner at some point, and there is no better way to learn than just jumping in. If you are not sure what to do, open an [issue](https://github.com/CadQuery/cadquery-freecad-workbench/issues) so that a community member can help you through it. 30 | 31 | # How to Report a Bug 32 | When filing an bug report [issue](https://github.com/CadQuery/cadquery-freecad-workbench/issues), make sure to answer these questions: 33 | 34 | 1. What version of the software are you running? 35 | 2. What operating system are you running the software on? 36 | 3. What are the steps to reproduce the bug? 37 | 38 | # How to Suggest a Feature or Enhancement 39 | 40 | If you find yourself wishing for a feature that does not exist in this module, you are probably not alone. There are bound to be others out there with similar needs. Open a [issue](https://github.com/CadQuery/cadquery-freecad-workbench/issues) which describes the feature you would like to see, why you need it, and how it should work. 41 | -------------------------------------------------------------------------------- /CQGui/Command.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # (c) 2014-2025 CadQuery Developers 3 | 4 | """Adds all of the commands that are used for the menus of the CadQuery module""" 5 | 6 | import FreeCADGui 7 | from PySide import QtGui 8 | from CQGui.HelpDialog import HelpDialog 9 | 10 | class CadQueryStableInstall: 11 | """ 12 | Allows the user to easily attempt a manual install of the stable version of CadQuery 13 | """ 14 | 15 | def GetResources(self): 16 | return {"MenuText": "Install CadQuery Stable", 17 | "Accel": "", 18 | "ToolTip": "Installs the stable version of CadQuery", 19 | "Pixmap": ":/icons/preferences-system.svg"} 20 | 21 | def IsActive(self): 22 | return True 23 | 24 | def Activated(self): 25 | import subprocess 26 | print("Starting to install CadQuery stable...") 27 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "cadquery==2.5.2"], capture_output=False) 28 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "cadquery-ocp==7.7.2"], capture_output=False) 29 | print("CadQuery stable has been installed! Please restart FreeCAD.") 30 | 31 | 32 | class CadQueryUnstableInstall: 33 | """ 34 | Allows the user to easily attempt a manual install of the unstable version of CadQuery 35 | """ 36 | 37 | def GetResources(self): 38 | return {"MenuText": "Install CadQuery Unstable", 39 | "Accel": "", 40 | "ToolTip": "Installs the unstable version of CadQuery", 41 | "Pixmap": ":/icons/preferences-system.svg"} 42 | 43 | def IsActive(self): 44 | return True 45 | 46 | def Activated(self): 47 | print("Starting to install CadQuery unstable...") 48 | import subprocess 49 | subprocess.run(["python", "-m", "pip", "uninstall", "-y", "vtk"], capture_output=False) 50 | subprocess.run(["python", "-m", "pip", "uninstall", "-y", "cadquery-vtk"], capture_output=False) 51 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "vtk==9.3.1"], capture_output=False) 52 | subprocess.run(["python", "-m", "pip", "uninstall", "-y", "cadquery-ocp"], capture_output=False) 53 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "cadquery-ocp==7.8.1.0"], capture_output=False) 54 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "https://github.com/CadQuery/cadquery.git"], capture_output=False) 55 | print("CadQuery unstable has been installed! Please restart FreeCAD.") 56 | 57 | 58 | class Build123DInstall: 59 | """ 60 | Allows the user to easily attempt a manual install of Build123D 61 | """ 62 | 63 | def GetResources(self): 64 | return {"MenuText": "Install Build123d", 65 | "Accel": "", 66 | "ToolTip": "Installs Build123d", 67 | "Pixmap": ":/icons/preferences-system.svg"} 68 | 69 | def IsActive(self): 70 | return True 71 | 72 | def Activated(self): 73 | import subprocess 74 | print("Starting to install Build123d...") 75 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "build123d"], capture_output=False) 76 | subprocess.run(["python", "-m", "pip", "install", "--upgrade", "cadquery-ocp==7.7.2"], capture_output=False) 77 | print("Build123d has been installed! Please restart FreeCAD.") 78 | 79 | 80 | class CadQueryClearOutput: 81 | """Allows the user to clear the reports view when it gets overwhelmed with output""" 82 | 83 | def GetResources(self): 84 | return {"MenuText": "Clear Output", 85 | "Accel": "Shift+Alt+C", 86 | "ToolTip": "Clears the script output from the Reports view", 87 | "Pixmap": ":/icons/button_invalid.svg"} 88 | 89 | def IsActive(self): 90 | return True 91 | 92 | def Activated(self): 93 | # Grab our main window so we can interact with it 94 | mw = FreeCADGui.getMainWindow() 95 | 96 | reportView = mw.findChild(QtGui.QDockWidget, "Report view") 97 | 98 | # Clear the view because it gets overwhelmed sometimes and won't scroll to the bottom 99 | reportView.widget().clear() 100 | 101 | 102 | class CadQueryHelp: 103 | """Opens a help dialog, allowing the user to access documentation and information about CadQuery""" 104 | 105 | def GetResources(self): 106 | return {"MenuText": "Help", 107 | "Accel": "", 108 | "ToolTip": "Opens the Help dialog", 109 | "Pixmap": ":/icons/help-browser.svg"} 110 | 111 | def IsActive(self): 112 | return True 113 | 114 | def Activated(self): 115 | win = HelpDialog() 116 | 117 | win.exec_() 118 | -------------------------------------------------------------------------------- /CQGui/HelpDialog.py: -------------------------------------------------------------------------------- 1 | from PySide import QtGui, QtCore 2 | 3 | class HelpDialog(QtGui.QDialog): 4 | def __init__(self, parent=None): 5 | super(HelpDialog, self).__init__(parent) 6 | self.resize(300, 200) 7 | self.setWindowTitle('Help') 8 | self.initUI() 9 | 10 | def initUI(self): 11 | import cadquery 12 | 13 | # Introduction to CadQuery line 14 | intro_label = QtGui.QLabel('CadQuery is a parametric scripting API for creating CAD models and assemblies.') 15 | intro_label.setWordWrap(True) 16 | 17 | # CadQuery version 18 | cadquery_ver = cadquery.__version__ 19 | version_label = QtGui.QLabel('CadQuery Version: ' + cadquery_ver) 20 | 21 | # CadQuery contributors 22 | cq_contribs = QtGui.QLabel('Authors: CadQuery Developers') 23 | 24 | # CadQuery documentation link 25 | cq_docs_link = QtGui.QLabel('- CadQuery Documentation') 26 | cq_docs_link.setOpenExternalLinks(True) 27 | 28 | # FreeCAD workbench documentation link 29 | wb_docs_link = QtGui.QLabel('- Workbench Documentation') 30 | wb_docs_link.setOpenExternalLinks(True) 31 | 32 | self.buttons = QtGui.QDialogButtonBox() 33 | self.buttons.setOrientation(QtCore.Qt.Horizontal) 34 | self.buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok) 35 | self.buttons.layout().setDirection(QtGui.QBoxLayout.LeftToRight) 36 | self.buttons.accepted.connect(self.closeHelp) 37 | 38 | grid = QtGui.QGridLayout() 39 | grid.setContentsMargins(10, 10, 10, 10) 40 | grid.addWidget(intro_label, 0, 0) 41 | grid.addWidget(version_label, 1, 0) 42 | grid.addWidget(cq_contribs, 2, 0) 43 | grid.addWidget(cq_docs_link, 3, 0) 44 | grid.addWidget(wb_docs_link, 4, 0) 45 | grid.addWidget(self.buttons, 5, 0) 46 | 47 | self.setLayout(grid) 48 | 49 | @QtCore.Slot(int) 50 | def closeHelp(self): 51 | self.accept() 52 | -------------------------------------------------------------------------------- /CQGui/Shared.py: -------------------------------------------------------------------------------- 1 | # (c) 2014-2025 CadQuery Developers 2 | import FreeCAD 3 | import FreeCADGui 4 | from PySide import QtGui 5 | 6 | 7 | def clearActiveDocument(): 8 | """Clears the currently active 3D view so that we can re-render""" 9 | 10 | # Grab our code editor so we can interact with it 11 | mw = FreeCADGui.getMainWindow() 12 | mdi = mw.findChild(QtGui.QMdiArea) 13 | currentWin = mdi.currentSubWindow() 14 | if currentWin == None: 15 | return 16 | winName = currentWin.windowTitle().split(" ")[0].split('.')[0] 17 | 18 | # Translate dashes so that they can be safetly used since theyare common 19 | if '-' in winName: 20 | winName= winName.replace('-', "__") 21 | 22 | try: 23 | doc = FreeCAD.getDocument(winName) 24 | 25 | # Make sure we have an active document to work with 26 | if doc is not None: 27 | for obj in doc.Objects: 28 | doc.removeObject(obj.Name) 29 | except: 30 | pass 31 | -------------------------------------------------------------------------------- /CQGui/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /CQGui/display.py: -------------------------------------------------------------------------------- 1 | # Define the show_object function which CadQuery execution environments need to provide 2 | def show_object(cq_object, options=None): 3 | import cadquery as cq 4 | import Part, FreeCAD, FreeCADGui 5 | from PySide import QtGui 6 | 7 | # Create the object that the BRep data will be read into 8 | from io import BytesIO 9 | brep_stream = BytesIO() 10 | 11 | # Keep track of the feature name 12 | feature_name = None 13 | # Check to see what type of object we are dealing with 14 | if isinstance(cq_object, cq.Workplane): 15 | # Handle the label if the user set it 16 | if cq_object.val().label: 17 | feature_name = cq_object.val().label 18 | 19 | # If we have a workplane, we need to convert it to a solid 20 | cq_object.val().exportBrep(brep_stream) 21 | elif isinstance(cq_object, cq.Shape): 22 | # If we have a solid, we can export it directly 23 | cq_object.exportBrep(brep_stream) 24 | elif hasattr(cq_object, "wrapped"): 25 | # Handle the label if the user has it set 26 | if hasattr(cq_object, "label"): 27 | feature_name = cq_object.label 28 | 29 | from build123d import export_brep 30 | export_brep(cq_object, brep_stream) 31 | elif hasattr(cq_object, "_obj"): 32 | # Handle the label if the user has it set 33 | if hasattr(cq_object, "label"): 34 | feature_name = cq_object.label 35 | 36 | from build123d import export_brep 37 | export_brep(cq_object._obj, brep_stream) 38 | else: 39 | print("Object type not suuport for display: ", type(cq_object).__name__) 40 | return 41 | 42 | # Get the title of the current document so that we can create/find the FreeCAD part window 43 | doc_name = "untitled" 44 | mw = FreeCADGui.getMainWindow() 45 | mdi_area = mw.findChild(QtGui.QMdiArea) 46 | active_subwindow = mdi_area.activeSubWindow() 47 | if active_subwindow: 48 | doc_name = active_subwindow.windowTitle().split(" :")[0] 49 | doc_name = doc_name.split(".py")[0] 50 | 51 | # Create or find the document that corresponds to this code pane 52 | # If the matching 3D view has been closed, we need to open a new one 53 | try: 54 | FreeCAD.getDocument(doc_name) 55 | except NameError: 56 | FreeCAD.newDocument(doc_name) 57 | ad = FreeCAD.activeDocument() 58 | 59 | # Convert the CadQuery object to a BRep string and then into a FreeCAD part shape 60 | brep_string = brep_stream.getvalue().decode('utf-8') 61 | part_shape = Part.Shape() 62 | part_shape.importBrepFromString(brep_string) 63 | 64 | # options={"alpha":0.5, "color": (64, 164, 223)} 65 | 66 | # If the user wanted to use a specific name in the tree, use it 67 | if not feature_name: 68 | feature_name = doc_name 69 | 70 | # Find the feature in the document, if it exists 71 | cur_feature = None 72 | for feat in ad.Objects: 73 | if feat.Name == feature_name or feat.Label == feature_name: 74 | cur_feature = feat 75 | break 76 | 77 | # Decide whether to create a new object or update an existing one 78 | if cur_feature: 79 | # Update the existing object 80 | cur_feature = ad.getObject(feature_name) 81 | cur_feature.Shape = part_shape 82 | else: 83 | cur_feature = ad.addObject("Part::Feature", feature_name) 84 | cur_feature.Label = feature_name 85 | cur_feature.Shape = part_shape 86 | 87 | # Apply any options to the imported shape 88 | if options: 89 | # Handle a transparency change, if requested 90 | if "alpha" in options: 91 | # Make sure that the alpha is scaled between 0 and 255 92 | alpha = int(options["alpha"] * 100) 93 | cur_feature.ViewObject.Transparency = alpha 94 | 95 | # Handle a color change, if requested 96 | if "color" in options: 97 | cur_feature.ViewObject.ShapeColor = options["color"] 98 | 99 | # Make sure the document updates 100 | ad.recompute() 101 | -------------------------------------------------------------------------------- /CQGui/icons/CQ_Logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 43 | 45 | 46 | 48 | image/svg+xml 49 | 51 | 52 | 53 | 54 | 55 | 60 | 65 | 68 | 72 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Init.py: -------------------------------------------------------------------------------- 1 | from CQGui.display import show_object 2 | 3 | # Register the show_object function as a global function 4 | globals()['show_object'] = show_object 5 | -------------------------------------------------------------------------------- /InitGui.py: -------------------------------------------------------------------------------- 1 | # (c) 2014-2025 CadQuery Developers 2 | 3 | """ 4 | CadQuery GUI init module for FreeCAD 5 | This adds a workbench with a scripting editor to FreeCAD's GUI. 6 | """ 7 | 8 | import Part, FreeCAD, FreeCADGui 9 | from CQGui.Command import (CadQueryHelp, 10 | CadQueryClearOutput, 11 | CadQueryStableInstall, 12 | CadQueryUnstableInstall, 13 | Build123DInstall) 14 | 15 | 16 | class CadQueryWorkbench (Workbench): 17 | """CadQuery workbench for FreeCAD""" 18 | 19 | MenuText = "CadQuery" 20 | ToolTip = "CadQuery workbench" 21 | 22 | 23 | def Initialize(self): 24 | self.appendMenu('CadQuery', ['CadQueryClearOutput']) 25 | self.appendMenu(['CadQuery', 'Install'], ["CadQueryStableInstall", 26 | "CadQueryUnstableInstall", 27 | "Build123DInstall"]) 28 | self.appendMenu('CadQuery', ['CadQueryHelp']) 29 | 30 | 31 | def Activated(self): 32 | pass 33 | 34 | 35 | def Deactivated(self): 36 | pass 37 | 38 | 39 | 40 | FreeCADGui.addCommand('CadQueryStableInstall', CadQueryStableInstall()) 41 | FreeCADGui.addCommand('CadQueryUnstableInstall', CadQueryUnstableInstall()) 42 | FreeCADGui.addCommand('Build123DInstall', Build123DInstall()) 43 | FreeCADGui.addCommand('CadQueryClearOutput', CadQueryClearOutput()) 44 | FreeCADGui.addCommand('CadQueryHelp', CadQueryHelp()) 45 | 46 | FreeCADGui.addWorkbench(CadQueryWorkbench()) 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The CadQuery Workbench for FreeCAD 2 | ======================= 3 | [![GitHub version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=gh&type=6&v=2.0.0&x2=0)](https://github.com/CadQuery/cadquery-freecad-workbench/releases/tag/v2.0.0) 4 | 5 | ## Introduction 6 | 7 | This is a FreeCAD workbench that allows the Macro Editor to execute and display CadQuery models. 8 | 9 | ![User Interface](docs/cqfm_user_interface.png) 10 | 11 | The documentation for this workbench can be found [here](docs/index.md). Below are the main entry points into the documentation. 12 | 13 | ### Documentation 14 | - [Introduction](docs/index.md#introduction) 15 | - [Installation](docs/installation.md) 16 | - [Usage](docs/usage.md) 17 | - [Developers](docs/developers.md) 18 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = "CadQuery Developers" 2 | __copyright__ = "Copyright 2014-2025" 3 | __license__ = "Apache 2.0" 4 | __version__ = "2.0.0" 5 | __maintainer__ = "CadQuery Developers" 6 | __status__ = "Production/Stable" 7 | -------------------------------------------------------------------------------- /changes.md: -------------------------------------------------------------------------------- 1 | Changes 2 | ======= 3 | 4 | v2.1.0 5 | ----- 6 | 7 | * Fixed bug where 3D model document tab could be duplicated in some cases (tahnks @benjinne) 8 | * Added a submenu to allow manual install of CadQuery and Build123d until #165 is fixed 9 | * Changed `show_object` to handle build123d objects natively (thanks @jdegenstein) 10 | 11 | v2.0.0 12 | ----- 13 | 14 | * Completely reworked the Workbench to that it would work with CadQuery 2.x 15 | * Functionality was changed to fit in with the FreeCAD workflow and toolset as much as possible 16 | * CadQuery is now available from the Macro Editor screen 17 | * Removed `libs` directory and code that messed with PYTHONPATH 18 | * Cleaned up repository to remove items that were only technical debt 19 | * Removed Settings dialog since those settings were mostly tied to the custom code editor 20 | * Added Help dialog to make it easier to find documentation 21 | * Updated documentation to reflect CadQuery 2.x and FreeCAD 1.0 changes 22 | 23 | v1.3.0 (unreleased) 24 | ----- 25 | * PyQode editor has been replaced by a custom editor due to compatibility problems with Qt5/PySide2 26 | * Settings have now been moved into FreeCAD user parameters 27 | * Settings dialog has been added under CadQuery->Settings 28 | * Execute-on-save setting is now on by default 29 | * Execute-script key has been changed to F9 to avoid conflicts with FreeCAD's F2, but key is still configurable 30 | * New code editor automatically reloads contents of script file if changed on disk, enabling use of external editor by default 31 | * Setting added to show/hide line numbers in code editor 32 | * Default font size for code editor changed to 12, but size is still configurable 33 | 34 | v1.2.0 35 | ----- 36 | * Made a copy of the PyQode editor which is abandoned, so that a custom version can be maintained here 37 | * Fixed Qt5 bugs, particularly ones that were effecting macOS 38 | * Added infrastructure to support third party add-on libraries 39 | * Integrated the cqparts library as an add-on in the ThirdParty directory - https://github.com/fragmuffin/cqparts 40 | * Created a script to update third-party libraries to aid in maintenance 41 | * An option was added to Settings.py which reports script execution time to the Report View 42 | * Created a Docs directory to lay the ground work for a documentation revamp. 43 | 44 | v1.1.0 45 | ----- 46 | * Updated to the v1.1.0 version of the CadQuery library 47 | 48 | v1.0.0.2 49 | ----- 50 | * Added support for the CadQuery Gateway Interface (CQGI), which is a way to make scripts portable 51 | 52 | v1.0.0.1 53 | ----- 54 | * Added example (Ex033) using logical operators in a string selector (thanks @adam-urbanczyk) 55 | * Fixed a bug in Helpers.show() that would clear the 3D view each time it was called 56 | * Fixed a bug that required there to be an open script window, disallowing the use of macros 57 | 58 | v1.0.0 59 | ----- 60 | * Embedded pyparsing package as a supporting library for new selector syntax 61 | * Added a check to remove any disallowed characters from the document name when executing a script 62 | * Added advanced example of 3D printer extruder support (thanks @adam-urbanczyk) 63 | * Made the switch to tabbed editing 64 | 65 | v0.5.1 66 | ----- 67 | * Version updates for CadQuery v0.4.0, v0.4.1, v0.5.0-stable and v0.5.1 68 | * Updated CadQuery license to Apache 2.0 69 | 70 | v0.3.0 71 | ----- 72 | * Converted thickness setting to thickness boolean in the Lego brick example (thanks @galou) #59 73 | * Improved parametric enclosure (Ex023) example (thanks @galou) #61 74 | * Added braille and NumPy examples (thanks @galou) #61 75 | * Embedded CadQuery library as a git subtree to lessen maintenance issues 76 | * Embedded Pint library for units handling 77 | * Fixed version number in InitGui.py 78 | * Added BoundingBox centerOption example (Ex030) (thanks @huskier) #66 79 | * Made change to leave the 3D render in place when switching to another workbench 80 | * Now use a user provided CadQuery shape label to label rendered FreeCAD objects 81 | 82 | v0.2.0 83 | ----- 84 | * Added a license badge to the readme 85 | * Updated the CadQuery library 86 | * Updated the PyQode libraries 87 | 88 | v0.1.8 89 | ----- 90 | * Initial commit 91 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /docs/cqfm_user_interface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CadQuery/cadquery-freecad-workbench/b3d31945ab08ffc9202b78b6a988fecd71d90d2e/docs/cqfm_user_interface.png -------------------------------------------------------------------------------- /docs/developers.md: -------------------------------------------------------------------------------- 1 | [](installation.md) 18 | -------------------------------------------------------------------------------- /docs/installation.md: -------------------------------------------------------------------------------- 1 | [](usage.md) 2 | ## Installation 3 | 4 | ### Table of Contents 5 | - [Automated (via the Addon manager)](installation.md#automated) 6 | - [Manual](installation.md#manual) 7 | 8 | ### Automated (via the Addon manager) 9 | 10 | This workbench can be install via FreeCAD's `Addon manager`. 11 | 1. Run the FreeCAD Addon Manager by clicking `Tools->Addon manager` 12 | 13 | ![Addon manager menu item](images/addon_manager_menu_item.png) 14 | 15 | 2. Scroll down and click on `CadQuery` 16 | 17 | ![cadquery_module addon item](images/cadquery_workbench_addon_manager_item.png) 18 | 19 | 3. Click the `Install / update` button 20 | 3. Restart FreeCAD 21 | 4. Confirm that CadQuery is in the drop down menu of available workbenches 22 | 23 | ![cadquery workbench item](images/cadquery_workbench_item.png) 24 | 25 | This process can be repeated to update the module every time changes are pushed to the master branch on GitHub. 26 | 27 | Due to the way FreeCAD's Python package whitelisting works, the dependencies of the workbench will probably not install automatically. You may be an error similar to the following. 28 | 29 | ![CadQuery Dependencies not Installed Error Dialog](images/cadquery_dependencies_error_dialog.png) 30 | 31 | If this happens, go ahead and click the `OK` button. Please check the list below to make sure that your system is supported by CadQuery's dependency chain by checking the following list. 32 | 33 | * Linux Intel/AMD 34 | * Windows Intel/AMD 35 | * MacOS Intel 36 | * MacOS ARM64 37 | 38 | Once you have checked that list, restart FreeCAD, and try the "Install CadQuery Stable" installation method shown below. 39 | 40 | ### Install CadQuery Stable 41 | 42 | Activate the `CadQuery` workbench from the dropdown. This should add a `CadQuery` item to FreeCAD's menu. Click on the menu item, and expand the `Install` submenu. There you will find a `Install CadQuery Stable` item. 43 | 44 | ![Install CadQuery Stable Menu](images/install_cadquery_stable_submenu_item.png) 45 | 46 | Click that and check the Report View to see when it is finished installing. It will take a few minutes. Once the installation is complete, restart FreeCAD. 47 | 48 | You can also re-run this menu item again to update the CadQuery dependencies after a workbench update. 49 | 50 | There are other installation options in this submenu, but they are made available for testing purposes. 51 | 52 | ### Manual 53 | Sometimes a different version or branch of the workbench may be needed, other than what is installed using the addon manager. The steps below outline the steps to manually install the workbench. 54 | 1. Download the [latest released version](https://github.com/CadQuery/cadquery-freecad-workbench/releases) 55 | 2. Extract the archive file 56 | 3. Copy the entire extracted directory to FreeCAD's `Mod` directory on your system. Typical `Mod` directory locations are listed below. 57 | 58 | **Linux Mod Locations** 59 | - /usr/lib/freecad/Mod 60 | - /usr/local/lib/freecad/Mod 61 | - ~/.FreeCAD/Mod 62 | - ~/.local/share/FreeCAD/Mod 63 | 64 | **Windows Mod Locations** 65 | - C:\Program Files\FreeCAD 0.14\Mod 66 | - C:\Program Files (x86)\FreeCAD 0.14\Mod 67 | - C:\Users\[your_user_name]\Application Data\FreeCAD\Mod 68 | 69 | **Mac Mod Locations** 70 | - /Applications/FreeCAD.app/Contents/Mod 71 | - /Applications/FreeCAD.app/Mod 72 | - /Users/[your_user_name]/Library/Preferences/FreeCAD/Mod 73 | - ~/Library/Preferences/FreeCAD/Mod 74 | 75 | [](usage.md) 76 | -------------------------------------------------------------------------------- /docs/usage.md: -------------------------------------------------------------------------------- 1 | [Macros...` in the menu bar. Doing so will oepn the `Execute macro` dialog box. You can then click the `Create` button and give your script a name. CadQuery files typically end in `.py`, so it is best to use that rather than the `.FCMacro` extension. 30 | 31 | ![Execute macro dialog](images/execute_macros_dialog.png) 32 | 33 | Clicking the `OK` button will create the macro/script and open it in a document tab. 34 | 35 | As a start, you can enter the following script in the macro document tab. 36 | 37 | ```python 38 | import cadquery as cq 39 | 40 | # Create the model that we want to display 41 | box = cq.Workplane().box(10, 10, 5) 42 | 43 | # You can output a message to FreeCAD's Report view 44 | print("I want to display something in the Report view") 45 | 46 | # You can set a custom name for for the part object in FreeCAD's model tree 47 | box.val().label = "My_Box" 48 | 49 | # Display the object in a new document tab 50 | show_object(box) 51 | ``` 52 | 53 | Save the macro (Ctrl+S) and then click the green `Execute macro` button (Ctrl+F6). 54 | 55 | ![Execute macro button](images/execute_macro_button.png) 56 | 57 | The model should be displayed in a new document tab, and any subsequent executions after change the script should cause the model to update, assuming that you do not change the label name. 58 | 59 | **NOTE:** The first model execution after opening FreeCAD will likely be a little slow because CadQuery and all of its dependencies have to be loaded. However, after the first execution, model updates should be displayed more quickly. 60 | 61 | ![CadQuery Workbench User Interface](cqfm_user_interface.png) 62 | 63 | 64 | An `options` parameter is used with the `show_object` method which allows the `color` and `alpha` (transparency) of the model to be changed. Below is a code example. 65 | 66 | ```python 67 | show_object(box, options={"color": (64, 164, 223), "alpha": 0.8}) 68 | ``` 69 | 70 | Notice that these options follow the pattern used in [CQ-editor](https://github.com/CadQuery/CQ-editor), which is done to ensure compatibility across CadQuery environments, but may not follow FreeCAD standards for color and transparency. 71 | 72 | ### Using an External Code Editor 73 | 74 | This feature is not currently implemented, but is planned for the future. 75 | 76 | ### Getting Help 77 | 78 | - Found a bug while using this workbench? You can open an issue [here](https://github.com/CadQuery/cadquery-freecad-workbench/issues) 79 | - Need help using this workbench? Join the [CadQuery Google Group](https://groups.google.com/forum/#!forum/cadquery) and ask your question there. Alternatively, you can join CadQuery's [Discord community](https://discord.com/invite/Bj9AQPsCfx) and ask your question in the `#other-guis` channel. 80 | 81 | [](developers.md) 82 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | CadQuery 3 | Workbench which makes CadQuery models executable within FreeCAD 4 | 2.1.0 5 | 2024-12-10 6 | Apache-2.0 7 | https://github.com/CadQuery/cadquery-freecad-workbench 8 | CQGui/icons/CQ_Logo.svg 9 | 10 | 11 | 12 | CadQuery 13 | Workbench which makes CadQuery models executable within FreeCAD 14 | CadQueryWorkbench 15 | ./ 16 | CQGui/icons/CQ_Logo.svg 17 | cadquery 18 | cadquery-ocp 19 | 20 | 21 | 22 | --------------------------------------------------------------------------------