### Install Miniforge on Linux/MacOS Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs Miniforge to a local directory and activates it. This method avoids polluting the local Python installation. ```bash # Install to ~/miniforge curl -L -o miniforge.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" bash miniforge.sh -b -p $HOME/miniforge # Activate source $HOME/miniforge/bin/activate ``` -------------------------------- ### Install CadQuery for Development Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs CadQuery with all necessary development dependencies. This setup is for users who plan to contribute to CadQuery's development or need a full local development environment. ```bash pip install cadquery[dev] ``` -------------------------------- ### Download and Run CQ-editor Installer (Linux/MacOS) Source: https://cadquery.readthedocs.io/en/latest/installation.html Use curl to download the CQ-editor installer script and then execute it to begin the installation process on Linux or MacOS. ```bash curl -LO https://github.com/CadQuery/CQ-editor/releases/download/nightly/CQ-editor-master-Linux-x86_64.sh sh CQ-editor-master-Linux-x86_64.sh ``` -------------------------------- ### Install Extra Packages with Mamba (Windows) Source: https://cadquery.readthedocs.io/en/latest/installation.html Activate the CQ-editor environment and then use mamba to install additional packages on Windows. ```batch C:\Users\\cq-editor\Scripts\activate mamba install ``` -------------------------------- ### Install Miniforge on Windows CMD Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs Miniforge non-interactively to the user's profile directory and activates the environment via a batch script. ```batch :: Install to %USERPROFILE%\Miniforge curl -L -o miniforge.exe https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe start "" /wait miniforge.exe /InstallationType=JustMe /RegisterPython=0 /NoRegistry=1 /NoScripts=1 /S /D=%USERPROFILE%\Miniforge :: Activate cmd /K ""%USERPROFILE%/Miniforge/Scripts/activate.bat" "%USERPROFILE%/Miniforge"" ``` -------------------------------- ### Install Extra Packages with Mamba (Linux/MacOS) Source: https://cadquery.readthedocs.io/en/latest/installation.html Activate the CQ-editor environment and then use mamba to install additional packages on Linux or MacOS. ```bash source $HOME/cq-editor/bin/activate mamba install ``` -------------------------------- ### Install CQ-editor with Pip Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs necessary Python packages including PyQt5, spyder, pyqtgraph, and logbook, followed by the CQ-editor from its GitHub repository. ```bash pip install PyQt5 spyder pyqtgraph logbook pip install git+https://github.com/CadQuery/CQ-editor.git ``` -------------------------------- ### Test CadQuery Installation Source: https://cadquery.readthedocs.io/en/latest/installation.html Opens a Python interpreter, imports the cadquery library, creates a simple box shape, and converts it to SVG format to verify the installation. ```python $ python >>> import cadquery >>> cadquery.Workplane('XY').box(1,2,3).toSvg() ``` -------------------------------- ### Install Miniforge on Windows PowerShell Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs Miniforge non-interactively to the user's profile directory and activates the environment using PowerShell scripts. ```powershell # Install to $env:USERPROFILE\Miniforge curl.exe -L -o miniforge.exe https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe Start-Process -Wait -FilePath miniforge.exe -ArgumentList @("/InstallationType=JustMe", "/RegisterPython=0", "/NoRegistry=1", "/NoScripts=1", "/S", "/D=$env:USERPROFILE\Miniforge") # Activate . $env:USERPROFILE\Miniforge\shell\condabin\conda-hook.ps1 conda activate ``` -------------------------------- ### Install CadQuery Core Package Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs the main CadQuery package using pip. This is the standard installation for using CadQuery in your projects. ```bash pip install cadquery ``` -------------------------------- ### Install JupyterLab with Pip Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs JupyterLab using pip into the current Python virtual environment. ```bash pip install jupyterlab ``` -------------------------------- ### Create Cubes Plugin Example Source: https://cadquery.readthedocs.io/en/latest/extending.html An example of a CadQuery plugin that creates cubes at each stack point. It demonstrates the use of inner functions and the `eachpoint` utility method for local coordinate transformations. ```python import cadquery as cq from cadquery.func import box def makeCubes(self, length): # self refers to the Workplane object # inner method that creates a cube def _singleCube(loc): # loc is a location in local coordinates # since we're using eachpoint with useLocalCoordinates=True return box(length, length, length).locate(loc) # use CQ utility method to iterate over the stack, call our # method, and convert to/from local coordinates. return self.eachpoint(_singleCube, True) # link the plugin into CadQuery cq.Workplane.makeCubes = makeCubes # use the plugin result = ( cq.Workplane("XY") .box(6.0, 8.0, 0.5) .faces(">Z") .rect(4.0, 4.0, forConstruction=True) .vertices() .makeCubes(1.0) .combine() ) ``` -------------------------------- ### Install CadQuery from GitHub Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs the latest development version of CadQuery directly from its GitHub repository. Use this if you need the newest features or want to test recent changes, but be aware of potential breaking changes. ```bash pip install git+https://github.com/CadQuery/cadquery.git ``` -------------------------------- ### Launch CQ-editor (Linux/MacOS) Source: https://cadquery.readthedocs.io/en/latest/installation.html Execute the run.sh script from the CQ-editor installation directory to launch the application on Linux or MacOS. ```bash $HOME/cq-editor/run.sh ``` -------------------------------- ### Importing BRepPrimAPI_MakeBox from OCCT Source: https://cadquery.readthedocs.io/en/latest/primer.html Provides a concrete example of importing the BRepPrimAPI_MakeBox class from the OCCT API. ```python from OCP.BRepPrimAPI import BRepPrimAPI_MakeBox ``` -------------------------------- ### Install CadQuery with IPython/Jupyter Dependencies Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs CadQuery along with extra dependencies required for using it with IPython/Jupyter environments. This is useful for interactive development and visualization. ```bash pip install cadquery[ipython] ``` -------------------------------- ### Launch CQ-editor (Windows) Source: https://cadquery.readthedocs.io/en/latest/installation.html Execute the run.bat script from the CQ-editor installation directory to launch the application on Windows. ```batch C:\Users\\cq-editor\run.bat ``` -------------------------------- ### CadQuery Fig VtkRemoteView and GitTree Setup Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/fig.html Configuration of the VtkRemoteView for 3D rendering and GitTree for managing scene actors. ```python self.view = vtk_widgets.VtkRemoteView( win, interactive_ratio=1, interactive_quality=100 ) with layout.drawer: self.tree = trame.GitTree( sources=("actors", []), visibility_change=(self.onVisibility, "[$event]"), actives_change=(self.onSelection, "[$event]"), ) ``` -------------------------------- ### Create an Empty Assembly Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Instantiate an empty Assembly object. This is useful as a starting point before adding any components. ```python assy = Assembly(None) ``` -------------------------------- ### Get Start Vertex of an Edge Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves the Vertex object representing the start of an edge. Note that for closed curves like circles, the start and end vertices may be the same. ```python edge.startVertex() ``` -------------------------------- ### Get Start Point of an Edge Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Returns the starting point of an edge as a Vector. This method is useful for determining the beginning of a curve segment. ```python edge.startPoint() ``` -------------------------------- ### Assembly Protocol Initialization Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/assembly.html Shows how to initialize an object conforming to the AssemblyProtocol, specifying the underlying object, location, name, color, and material. ```python assembly_obj = AssemblyProtocol(obj=my_shape, loc=Location((1, 2, 3)), name="part1", color=Color("blue"), material=Material("steel")) ``` -------------------------------- ### Get End Vertex of an Edge Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves the Vertex object representing the end of an edge. Similar to startVertex, for closed curves, this may be the same as the start vertex. ```python edge.endVertex() ``` -------------------------------- ### Get Parametric Bounds of a Curve Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Calculates and returns the parametric start and end values for a curve. This is essential for operations that rely on the curve's parameterization. ```python edge.bounds() ``` -------------------------------- ### Adding Objects with Initial Locations Source: https://cadquery.readthedocs.io/en/latest/assy.html Demonstrates adding objects to an assembly with specified locations, names, and colors. Use this when precise initial placement is known. ```python import cadquery as cq cone = cq.Solid.makeCone(1, 0, 2) assy = cq.Assembly() assy.add( cone, loc=cq.Location((0, 0, 0), (1, 0, 0), 180), name="cone0", color=cq.Color("green"), ) assy.add(cone, name="cone1", color=cq.Color("blue")) show_object(assy) ``` -------------------------------- ### Initialize an Empty Sketch Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/sketch.html Constructs an empty sketch object. This is the starting point for building 2D geometry. ```python sketch = Sketch() ``` -------------------------------- ### Upgrade Pip Source: https://cadquery.readthedocs.io/en/latest/installation.html Ensures you have the latest version of pip, which is recommended for installing CadQuery. Run this command before installing CadQuery itself. ```bash python3 -m pip install --upgrade pip ``` -------------------------------- ### Initialize Material with Defaults Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/assembly.html Creates a new Material object with default properties. You can optionally provide a name and other material characteristics like density and description. ```python from cadquery.occ_impl.assembly import Material # Create a default material material1 = Material() # Create a material with a specific name material2 = Material(name="Steel") # Create a material with name and density material3 = Material(name="Aluminum", density=2.7, densityUnit="g/cm^3") ``` -------------------------------- ### Get Geometry Type Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Gets the underlying geometry type of the shape. The return value is a string that can be used for type filtering. ```python tr: Any = geom_LUT[shapetype(self.wrapped)] if isinstance(tr, str): rv = tr elif tr is BRepAdaptor_Curve: rv = geom_LUT_EDGE[tr(tcast(TopoDS_Edge, self.wrapped)).GetType()] else: rv = geom_LUT_FACE[tr(self.wrapped).GetType()] return tcast(Geoms, rv) ``` -------------------------------- ### Install JupyterLab with Conda Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs JupyterLab into the current conda environment. This is a prerequisite for using CadQuery models within Jupyter notebooks. ```bash mamba install jupyterlab ``` -------------------------------- ### Start JupyterLab Source: https://cadquery.readthedocs.io/en/latest/installation.html Launches the JupyterLab application, which will open in your web browser, allowing you to create notebooks for interactive CadQuery model development. ```bash jupyter lab ``` -------------------------------- ### Initialize DXF Document Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/exporters/dxf.html Initializes a DXF document with specified version, setup options, units, metadata, and approximation settings for shape conversion. ```python dxf = DxfDocument(dxfversion="AC1027", setup=False, doc_units=units.MM, metadata=None, approx=None, tolerance=1e-3) ``` -------------------------------- ### makeLoft Source: https://cadquery.readthedocs.io/en/latest/classreference.html Creates a loft solid from a list of wires. ```APIDOC ## classmethod makeLoft ### Description Creates a loft solid from a list of wires. The wires are converted into faces. ### Method classmethod ### Signature makeLoft(_listOfWire : list[Wire], _ruled : bool = False) ### Parameters #### Path Parameters - **listOfWire** (list[Wire]) - A list of wires to create the loft from. - **ruled** (bool) - Optional. If True, creates a ruled loft. Defaults to False. ### Return type Solid ``` -------------------------------- ### Building a Sample Part with CadQuery Source: https://cadquery.readthedocs.io/en/latest/workplane.html Constructs a sample CadQuery part using a fluent API, including operations like box, tag, wires, toPending, translate, loft, faces, workplane, circle, and extrude. This example is used to demonstrate introspection. ```python part = ( cq.Workplane() .box(1, 1, 1) .tag("base") .wires(">Z") .toPending() .translate((0.1, 0.1, 1.0)) .toPending() .loft() .faces(">>X", tag="base") .workplane(centerOption="CenterOfMass") .circle(0.2) .extrude(1) ) ``` -------------------------------- ### Vector Initialization Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/geom.html Demonstrates various ways to initialize a 3D vector using different input types such as floats, tuples, or existing Vector objects. ```python from cadquery.occ_impl.geom import Vector # Initialize with three floats v1 = Vector(1.0, 2.0, 3.0) # Initialize with two floats (z defaults to 0) v2 = Vector(4.0, 5.0) # Initialize from another Vector object v3 = Vector(v1) # Initialize from a tuple v4 = Vector((6.0, 7.0, 8.0)) # Initialize from an empty tuple (results in zero vector) v5 = Vector(()) # Initialize with a zero vector v6 = Vector() # Initialize from an OCC gp_Vec from OCP.gp import gp_Vec gp_v = gp_Vec(9.0, 10.0, 11.0) v7 = Vector(gp_v) # Initialize from an OCC gp_Pnt from OCP.gp import gp_Pnt gp_p = gp_Pnt(12.0, 13.0, 14.0) v8 = Vector(gp_p) # Initialize from an OCC gp_Dir from OCP.gp import gp_Dir gp_d = gp_Dir(15.0, 16.0, 17.0) v9 = Vector(gp_d) # Initialize from an OCC gp_XYZ from OCP.gp import gp_XYZ gp_xyz = gp_XYZ(18.0, 19.0, 20.0) v10 = Vector(gp_xyz) print(v1.toTuple()) print(v2.toTuple()) print(v3.toTuple()) print(v4.toTuple()) print(v5.toTuple()) print(v6.toTuple()) print(v7.toTuple()) print(v8.toTuple()) print(v9.toTuple()) print(v10.toTuple()) ``` -------------------------------- ### Install CQ-editor with Conda Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs CQ-editor and CadQuery into a new conda environment named 'cqdev'. This command uses mamba for faster package resolution. ```bash conda create -n cqdev conda activate cqdev mamba install -c cadquery cq-editor=master ``` -------------------------------- ### Load Assembly from File Source: https://cadquery.readthedocs.io/en/latest/classreference.html Loads an assembly from STEP, XBF, or XML files. Only STEP files support unit conversion during loading. ```python assembly = cadquery.Assembly.load("my_assembly.step") assembly = cadquery.Assembly.load("my_assembly.xbf", importType='XBF') assembly = cadquery.Assembly.load("my_assembly.step", unit='CM') ``` -------------------------------- ### Install Latest Development Version of CadQuery Source: https://cadquery.readthedocs.io/en/latest/installation.html Creates a conda environment named 'cqdev' and installs the latest development version of CadQuery from the 'cadquery' channel. ```bash conda create -n cqdev conda activate cqdev mamba install -c cadquery cadquery=master ``` -------------------------------- ### Close Wire Operation Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/cq.html Attempts to close a wire by adding a line segment if the start and end points are not coincident. Resets the starting point after closing. ```python endPoint = self._findFromPoint(True) if self.ctx.firstPoint is None: raise ValueError("No start point specified - cannot close") else: startPoint = self.ctx.firstPoint # Check if there is a distance between startPoint and endPoint # that is larger than what is considered a numerical error. # If so; add a line segment between endPoint and startPoint if endPoint.sub(startPoint).Length > 1e-6: self.polyline([endPoint, startPoint]) # Need to reset the first point after closing a wire self.ctx.firstPoint = None return self.wire() ``` -------------------------------- ### Vector Initialization Examples Source: https://cadquery.readthedocs.io/en/latest/classreference.html Illustrates various ways to initialize a CadQuery Vector object, including with no arguments, existing vectors, tuples, and individual float values. ```python cq.Vector() ``` ```python cq.Vector(cq.Vector()) ``` ```python cq.Vector((1.0, 2.0, 3.0)) ``` ```python cq.Vector((1.0, 2.0)) ``` ```python cq.Vector(1.0, 2.0, 3.0) ``` ```python cq.Vector(1.0, 2.0) ``` -------------------------------- ### Install Specific CadQuery Version via Conda Source: https://cadquery.readthedocs.io/en/latest/installation.html Creates a conda environment named 'cq231' and installs a specific version (2.3.1) of CadQuery using mamba. ```bash conda create -n cq231 conda activate cq231 mamba install cadquery=2.3.1 ``` -------------------------------- ### Finding Start Point for Operations (CadQuery) Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/cq.html Determines the starting point for an operation, using the end of the previous edge or a vector on the stack. Supports local or global coordinates. ```python def _findFromPoint(self, useLocalCoords: bool = False) -> Vector: """ Finds the start point for an operation when an existing point is implied. Examples include 2d operations such as lineTo, which allows specifying the end point, and implicitly use the end of the previous line as the starting point :return: a Vector representing the point to use, or none if such a point is not available. :param useLocalCoords: selects whether the point is returned in local coordinates or global coordinates. The algorithm is this: * If an Edge is on the stack, its end point is used.yp * if a vector is on the stack, it is used WARNING: only the last object on the stack is used. """ obj = self.objects[-1] if self.objects else self.plane.origin if isinstance(obj, Edge): p = obj.endPoint() elif isinstance(obj, Vector): p = obj elif isinstance(obj, Vertex): p = obj.Center() else: raise ValueError(f"Cannot convert object type {type(obj)} to vector.") if useLocalCoords: return self.plane.toLocalCoords(p) else: return p ``` -------------------------------- ### ellipseArc Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/cq.html Draws an elliptical arc. The arc can be defined by its x and y radii, start and end angles, rotation, and sense. It can either start at the current point or have the current point as its center. ```APIDOC ## ellipseArc ### Description Draws an elliptical arc with specified x and y radii. The arc is defined by start and end angles, rotation, and sense (clockwise or counter-clockwise). The arc can be positioned relative to the current point, either as the start point or the center. ### Method ``` def ellipseArc( self: T, x_radius: float, y_radius: float, angle1: float = 360, angle2: float = 360, rotation_angle: float = 0.0, sense: Literal[-1, 1] = 1, startAtCurrent: bool = True, makeWire: bool = False, ) -> T ``` ### Parameters * **x_radius** (float) - Required - The x-radius of the ellipse (along the x-axis of the plane the ellipse should lie in). * **y_radius** (float) - Required - The y-radius of the ellipse (along the y-axis of the plane the ellipse should lie in). * **angle1** (float) - Optional - The start angle of the arc. Defaults to 360. * **angle2** (float) - Optional - The end angle of the arc. If `angle2 == angle1`, a closed ellipse is returned. Defaults to 360. * **rotation_angle** (float) - Optional - The angle to rotate the created ellipse/arc. Defaults to 0.0. * **sense** (Literal[-1, 1]) - Optional - The direction of the arc: clockwise (-1) or counter-clockwise (1). Defaults to 1. * **startAtCurrent** (bool) - Optional - If True, the start point of the arc is moved to the current point. If False, the current point is the center of the arc. Defaults to True. * **makeWire** (bool) - Optional - Whether to convert the resulting arc edge to a wire. Defaults to False. ### Returns * T - A Workplane object with the current point unchanged. ``` -------------------------------- ### Step-by-Step Box Creation and Hole Cutting in CadQuery Source: https://cadquery.readthedocs.io/en/latest/primer.html This example shows the same operation as the chained version but broken down into individual steps. This style can be easier to debug and visualize in tools like CQ-Editor. ```python part = Workplane("XY") part = part.box(1, 2, 3) part = part.faces(">Z") part = part.vertices() part = part.circle(0.5) part = part.cutThruAll() ``` -------------------------------- ### Move and Place Objects Source: https://cadquery.readthedocs.io/en/latest/free-func.html Demonstrates using `moved()` and `move()` to position and replicate objects. Use `moved()` for multiple locations and `move()` for single transformations. ```python from cadquery.func import * locs = [(0,-1,0), (0,1,0)] s = sphere(1).moved(locs) c = cylinder(1,2).move(rx=15).moved(*locs) result = compound(s, c.moved(2)) ``` -------------------------------- ### Complex Selector Grammar Example Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/selectors.html This example demonstrates the structure of a complex selector string that can be parsed by CadQuery's grammar. It shows combinations of direction, type, operators, and indices. ```python direction("only_dir") | (type_op("type_op") + cqtype("cq_type")) | (direction_op("dir_op") + direction("dir") + Optional(index)) | (center_nth_op("center_nth_op") + direction("dir") + Optional(index)) | (other_op("other_op") + direction("dir")) | named_view("named_view") ``` -------------------------------- ### Install Specific CadQuery and OCP Versions Source: https://cadquery.readthedocs.io/en/latest/installation.html Installs a specific version of CadQuery (2.2.0) and a compatible version of OCP (7.7.0.*) using mamba. This is useful for ensuring compatibility with older releases. ```bash mamba install cadquery=2.2.0 ocp=7.7.0.* ``` -------------------------------- ### Querying Assembly Objects Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/assembly.html Demonstrates how to query objects within an assembly using a specific query string format. This is useful for selecting parts of an assembly based on name, tags, and kinds. ```python obj_name @ faces @ >Z obj_name?tag1@faces@>Z obj_name ? tag obj_name ``` -------------------------------- ### Color Class Initialization Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/assembly.html Demonstrates various ways to initialize a Color object, including from a name, RGB(A) values, or with default settings. Handles sRGB/linear RGB conversion. ```python c = Color("green") c = Color(1.0, 0.5, 0.0) c = Color(r=1.0, g=0.5, b=0.0, a=0.5) c = Color(1.0, 0.5, 0.0, 0.5) c = Color(1.0, 0.5, 0.0, 0.5, False) c = Color() ``` -------------------------------- ### Initialize Color by Name Source: https://cadquery.readthedocs.io/en/latest/classreference.html Creates a Color object using a predefined color name. ```python color = Color("Red") ``` -------------------------------- ### size Source: https://cadquery.readthedocs.io/en/latest/classreference.html Get the simple size of the shape. ```APIDOC ## size ### Description Simple size implementation. ### Return Type int ``` -------------------------------- ### size Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Get the size of the current selection. ```APIDOC ## size ### Description Simple size implementation. ### Method Not applicable (method call on an object) ### Return type int ``` -------------------------------- ### Solid.makeBox Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Creates a box primitive. ```APIDOC ## Solid.makeBox ### Description Make a box located in pnt with the dimensions (length,width,height). ### Method Signature makeBox(length: float, width: float, height: float, pnt: VectorLike = Vector(0, 0, 0), dir: VectorLike = Vector(0, 0, 1)) -> Solid ### Parameters - **length** (float): The length of the box. - **width** (float): The width of the box. - **height** (float): The height of the box. - **pnt** (VectorLike): The origin point of the box. Defaults to Vector(0, 0, 0). - **dir** (VectorLike): The direction of the box's height. Defaults to Vector(0, 0, 1). ### Returns - Solid: The created box solid. ``` -------------------------------- ### startVertex Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Retrieves the starting vertex of a 1D curve. ```APIDOC ## startVertex ### Returns a vertex representing the start point of this edge ### Parameters **self** (_Mixin1DProtocol_) ### Return type _Vertex_ Note, circles may have the start and end vertex the same ``` -------------------------------- ### Location Constructors Source: https://cadquery.readthedocs.io/en/latest/classreference.html Demonstrates various ways to initialize a Location object, including translation, rotation, and wrapping existing OCCT objects. ```python Location(_t : Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]_, _angles : Tuple[int | float, int | float, int | float]_) -> None Location(_x : int | float = 0_, _y : int | float = 0_, _z : int | float = 0_, _rx : int | float = 0_, _ry : int | float = 0_, _rz : int | float = 0_) -> None Location(_t : Plane_) -> None Location(_T : TopLoc_Location_) -> None Location(_t : Plane_, _v : Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]_) -> None Location(_T : gp_Trsf_) -> None ``` -------------------------------- ### geomType Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Gets the underlying geometry type of the shape. ```APIDOC ## geomType ### Description Gets the underlying geometry type of the shape. The return values are used for type filtering. ### Method [Method not explicitly defined, likely a Python method call] ### Endpoint [Not applicable, this is an SDK method] ### Parameters None ### Response #### Success Response (200) - **return value** (Geoms) - A string representing the geometry type (e.g., 'Vertex', 'LINE', 'PLANE', 'Solid'). ### Response Example [Not applicable, this is an SDK method] ### Geometry Types - **Vertex**: 'Vertex' - **Edge**: 'LINE', 'CIRCLE', 'ELLIPSE', 'HYPERBOLA', 'PARABOLA', 'BEZIER', 'BSPLINE', 'OFFSET', 'OTHER' - **Face**: 'PLANE', 'CYLINDER', 'CONE', 'SPHERE', 'TORUS', 'BEZIER', 'BSPLINE', 'REVOLUTION', 'EXTRUSION', 'OFFSET', 'OTHER' - **Solid**: 'Solid' - **Shell**: 'Shell' - **Compound**: 'Compound' - **Wire**: 'Wire' ``` -------------------------------- ### CadQuery Fig Server Initialization and Threading Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/fig.html Initializes the Trame server, sets up an event loop in a separate thread, and starts the server. ```python server.state.flush() self.loop = new_event_loop() def _run_loop(): set_event_loop(self.loop) self.loop.run_forever() self.thread = Thread(target=_run_loop, daemon=True) self.thread.start() coro = server.start( thread=True, exec_mode="coroutine", port=port, open_browser=False, show_connection_info=False, ) if coro: self._run(coro) # prevent reinitialization self._initialized = True # view is initialized as empty self.empty = True self.last = None # open webbrowser open_new_tab(f"http://localhost:{port}") ``` -------------------------------- ### startPoint Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Retrieves the starting point of a 1D curve as a Vector. ```APIDOC ## startPoint ### Returns a vector representing the start point of this edge ### Parameters **self** (_Mixin1DProtocol_) ### Return type _Vector_ Note, circles may have the start and end points the same ``` -------------------------------- ### Get Shape Location Source: https://cadquery.readthedocs.io/en/latest/classreference.html Retrieves the current location of the shape in space. ```python loc = shape.location() ``` -------------------------------- ### Sketch Initialization Source: https://cadquery.readthedocs.io/en/latest/apireference.html Methods for creating and initializing new Sketch objects, including importing DXF files and finalizing sketch construction. ```APIDOC ## Sketch Initialization ### `Sketch(parent, locs, obj)` **Description**: Creates a 2D sketch. ### `Sketch.importDXF(filename[, tol, exclude, ...])` **Description**: Imports a DXF file and constructs face(s). ### `Workplane.sketch()` **Description**: Initializes and returns a sketch. ### `Sketch.finalize()` **Description**: Finishes sketch construction and returns the parent object. ### `Sketch.copy()` **Description**: Creates a partial copy of the sketch. ### `Sketch.located(loc)` **Description**: Creates a partial copy of the sketch with a new location. ### `Sketch.moved(...)` **Description**: Creates a partial copy of the sketch with moved faces. ``` -------------------------------- ### Get Shape Location Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves the current absolute location of the shape. ```python return Location(self.wrapped.Location()) ``` -------------------------------- ### Get Inverse Location Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/geom.html Returns the inverse of the current Location object. ```python return Location(self.wrapped.Inverted()) ``` -------------------------------- ### Create a Simple Rectangular Plate Source: https://cadquery.readthedocs.io/en/latest/examples.html This snippet demonstrates the creation of a basic rectangular box using the `box` method on a `Workplane`. It's a fundamental example for beginners. ```python result = cadquery.Workplane("front").box(2.0, 2.0, 0.5) ``` -------------------------------- ### Get Plane Location Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/geom.html Returns the Location object associated with the plane. ```python return Location(self) ``` -------------------------------- ### CQGI Script Example: Cube with Circle Source: https://cadquery.readthedocs.io/en/latest/cqgi.html This script generates a cube with a circle on top. It uses `debug()` to show intermediate objects like a workplane and a circle, and `show_object()` to export the final extruded circle. ```python base_cube = cq.Workplane("XY").rect(1.0, 1.0).extrude(1.0) top_of_cube_plane = base_cube.faces(">Z").workplane() debug( top_of_cube_plane, { "color": "yellow", }, ) debug(top_of_cube_plane.center, {"color": "blue"}) circle = top_of_cube_plane.circle(0.5) debug(circle, {"color": "red"}) show_object(circle.extrude(1.0)) ``` -------------------------------- ### Edge.makeBezier Example Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Creates a cubic Bézier curve from a list of points. ```python Edge.makeBezier(points) ``` -------------------------------- ### Edge.makeEllipse Example Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Creates an ellipse with specified radii, center, direction, and angles. ```python Edge.makeEllipse(x_radius, y_radius, pnt, dir, xdir, angle1, angle2, sense) ``` -------------------------------- ### Load Assembly from File Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/assembly.html Loads an assembly from a STEP, XBF, or XML file. Only STEP files support unit conversion during loading. The import type can be inferred from the file extension or specified explicitly. ```python @classmethod def load( cls, path: str, importType: Optional[ImportLiterals] = None, unit: UnitLiterals = "MM", ) -> Self: """ Load step, xbf or xml. Only STEP supports unit conversion on loading. """ if importType is None: t = path.split(".")[-1].upper() if t in ("STEP", "XML", "XBF"): importType = cast(ImportLiterals, t) else: raise ValueError("Unknown extension, specify import type explicitly") assy = cls() if importType == "STEP": _importStep(assy, path, unit) elif importType == "XML": importXml(assy, path) elif importType == "XBF": importXbf(assy, path) return assy ``` -------------------------------- ### Solid.makeSolid Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Creates a solid from a single shell. ```APIDOC ## Solid.makeSolid ### Description Makes a solid from a single shell. ### Method Signature makeSolid(shell: Shell) -> Solid ### Parameters - **shell** (Shell): The shell to convert into a solid. ### Returns - Solid: The created solid. ``` -------------------------------- ### makeTangentArc Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Creates a tangent arc starting from v1, in the direction of v2, and ending at v3. ```APIDOC ## makeTangentArc ### Description Makes a tangent arc from point v1, in the direction of v2 and ends at v3. ### Method classmethod ### Parameters * **v1** (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) * **v2** (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) * **v3** (Vector | Tuple[int | float, int | float] | Tuple[int | float, int | float, int | float]) ``` -------------------------------- ### makeTangentArc Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Creates a tangent arc starting from a point, in a direction, and ending at another point. ```APIDOC ## makeTangentArc ### Description Makes a tangent arc from a starting point, in the direction of a tangent vector, and ending at a specified end point. ### Method `classmethod makeTangentArc(v1: VectorLike, v2: VectorLike, v3: VectorLike) -> Edge` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Example usage not provided in source ``` ### Response #### Success Response (200) - **Edge**: An Edge object representing the tangent arc. #### Response Example ```json { "example": "Edge object" } ``` ``` -------------------------------- ### Create an Assembly with a Root Object Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Construct an Assembly with a specified root object, location, and name. This sets up the initial structure of the assembly. ```python b = Workplane().box(1, 1, 1) assy = Assembly(b, Location(Vector(0, 0, 1)), name="root") ``` -------------------------------- ### Import DXF File Source: https://cadquery.readthedocs.io/en/latest/importexport.html Imports a DXF file and prepares its wires for subsequent operations. Use this to bring 2D profiles into CadQuery for 3D modeling. ```python import cadquery as cq result = ( cq.importers.importDXF("/path/to/dxf/circle.dxf").wires().toPending().extrude(10) ) ``` -------------------------------- ### Get Solids of a Shape Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves a list of all solid entities within a CadQuery shape. ```python from cadquery import Shape # Assuming 'my_shape' is a CadQuery Shape object # solids = my_shape.Solids() ``` -------------------------------- ### Offsetting Wires in 2D Source: https://cadquery.readthedocs.io/en/latest/examples.html Illustrates offsetting 2D wires using different techniques like 'arc' and 'intersection'. ```python original = cq.Workplane().polygon(5, 10).extrude(0.1).translate((0, 0, 2)) arc = cq.Workplane().polygon(5, 10).offset2D(1, "arc").extrude(0.1).translate((0, 0, 1)) intersection = cq.Workplane().polygon(5, 10).offset2D(1, "intersection").extrude(0.1) result = original.add(arc).add(intersection) ``` -------------------------------- ### Get Shells of a Shape Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves a list of all shell entities within a CadQuery shape. ```python from cadquery import Shape # Assuming 'my_shape' is a CadQuery Shape object # shells = my_shape.Shells() ``` -------------------------------- ### Plane Initialization Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/geom.html Demonstrates various ways to initialize a Plane object, including using predefined named planes and specifying origin and direction vectors. ```APIDOC ## Plane Initialization Methods ### Description Provides methods to create Plane objects using named presets or by specifying origin and direction vectors. ### Methods #### `Plane.named(stdName, origin)` Creates a plane using a predefined name (e.g., "XY", "front"). - **stdName** (string) - The name of the predefined plane. - **origin** (tuple or Vector) - The origin point of the plane. #### `Plane.XY(origin, xDir)` Creates a Plane oriented along the XY axes. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(1, 0, 0). #### `Plane.YZ(origin, xDir)` Creates a Plane oriented along the YZ axes. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(0, 1, 0). #### `Plane.ZX(origin, xDir)` Creates a Plane oriented along the ZX axes. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(0, 0, 1). #### `Plane.XZ(origin, xDir)` Creates a Plane oriented along the XZ axes. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(1, 0, 0). #### `Plane.YX(origin, xDir)` Creates a Plane oriented along the YX axes. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(0, 1, 0). #### `Plane.ZY(origin, xDir)` Creates a Plane oriented along the ZY axes. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(0, 0, 1). #### `Plane.front(origin, xDir)` Creates a Plane oriented towards the front. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(1, 0, 0). #### `Plane.back(origin, xDir)` Creates a Plane oriented towards the back. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(-1, 0, 0). #### `Plane.left(origin, xDir)` Creates a Plane oriented towards the left. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(0, 0, 1). #### `Plane.right(origin, xDir)` Creates a Plane oriented towards the right. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(0, 0, -1). #### `Plane.top(origin, xDir)` Creates a Plane oriented towards the top. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(1, 0, 0). #### `Plane.bottom(origin, xDir)` Creates a Plane oriented towards the bottom. - **origin** (tuple or Vector) - Defaults to (0, 0, 0). - **xDir** (Vector) - Defaults to Vector(1, 0, 0). ### `__init__(origin, xDir, normal)` Creates a Plane from origin in global coordinates, vector xDir, and normal direction for the plane. - **origin** (Union[Tuple[Real, Real, Real], Vector]) - The origin point of the plane. - **xDir** (Optional[Union[Tuple[Real, Real, Real], Vector]]) - The x-direction vector of the plane. If None, it's derived from the normal. - **normal** (Union[Tuple[Real, Real, Real], Vector]) - The normal vector of the plane. Defaults to (0, 0, 1). ### `__init__(loc)` Creates a Plane from a Location object. - **loc** (Location) - The Location object defining the plane's position and orientation. ``` -------------------------------- ### Get Faces of a Shape Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves a list of all face entities within a CadQuery shape. ```python from cadquery import Shape # Assuming 'my_shape' is a CadQuery Shape object # faces = my_shape.Faces() ``` -------------------------------- ### Get Wires of a Shape Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves a list of all wire entities within a CadQuery shape. ```python from cadquery import Shape # Assuming 'my_shape' is a CadQuery Shape object # wires = my_shape.Wires() ``` -------------------------------- ### makeSolid Source: https://cadquery.readthedocs.io/en/latest/classreference.html?highlight=workplane Creates a solid from a single shell. ```APIDOC ## makeSolid ### Description Creates a solid from a single shell. ### Method classmethod ### Parameters * **shell** (_Shell_) - Description ### Return type _Solid_ ``` -------------------------------- ### Get Compounds of a Shape Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves a list of all compound entities within a CadQuery shape. ```python from cadquery import Shape # Assuming 'my_shape' is a CadQuery Shape object # compounds = my_shape.Compounds() ``` -------------------------------- ### Import STEP File (Default Units) Source: https://cadquery.readthedocs.io/en/latest/importexport.html Imports a STEP file with default unit conversion to millimeters. Use this for importing 3D models. ```python import cadquery as cq result = cq.importers.importStep("/path/to/step/block.stp") ``` -------------------------------- ### Create a Box and Cut a Hole with CadQuery Fluent API Source: https://cadquery.readthedocs.io/en/latest/primer.html This example demonstrates creating a box, selecting its top vertices, and cutting a hole through it using the CadQuery Fluent API. It showcases a chained method call style. ```python part = Workplane("XY").box(1, 2, 3).faces(">Z").vertices().circle(0.5).cutThruAll() ``` -------------------------------- ### Get Vertices of a Shape Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Retrieves a list of all vertex entities within a CadQuery shape. ```python from cadquery import Shape # Assuming 'my_shape' is a CadQuery Shape object # vertices = my_shape.Vertices() ``` -------------------------------- ### Get Hash Code Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Returns a hashed value for the shape, computed from its TShape and Location. ```python return hash(self.wrapped) ``` -------------------------------- ### Solid.makeCone Source: https://cadquery.readthedocs.io/en/latest/_modules/cadquery/occ_impl/shapes.html Creates a cone primitive. ```APIDOC ## Solid.makeCone ### Description Make a cone with given radii and height. ### Method Signature makeCone(radius1: float, radius2: float, height: float, pnt: VectorLike = Vector(0, 0, 0), dir: VectorLike = Vector(0, 0, 1), angleDegrees: float = 360) -> Solid ### Parameters - **radius1** (float): The radius of the first base. - **radius2** (float): The radius of the second base. - **height** (float): The height of the cone. - **pnt** (VectorLike): The origin point of the cone. Defaults to Vector(0, 0, 0). - **dir** (VectorLike): The direction of the cone's height. Defaults to Vector(0, 0, 1). - **angleDegrees** (float): The angle of the cone sector in degrees. Defaults to 360. ### Returns - Solid: The created cone solid. ```