Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save medicationforall/9a7f141fb42bd8ebf9182155bc3b23aa to your computer and use it in GitHub Desktop.
Save medicationforall/9a7f141fb42bd8ebf9182155bc3b23aa to your computer and use it in GitHub Desktop.

CadQuery Python Packaging - Making your own library

Probably an advanced topic

Goal of the video

Show you how to make your own python package that can be called in your CadQuery scripts.

Pre-requisites

Resources


Example Plugin

Installation

pip install git+https://github.com/JustinSDK/cqMore

Usage

from cqmore import Workplane

result = (Workplane()
            .rect(10, 10)
            .makePolygon(((-2, -2), (2, -2), (2, 2), (-2, 2)))
            .extrude(1)
         )
show_object(part)

Example library

Installation

pip install git+https://github.com/medicationforall/cadqueryhelper

Usage

from cadqueryhelper import shape

part = shape.arrow(length=10, inner_length=5, width=5, width_outset=2, height=3)
show_object(part)

Tutorial Steps

Make a project

  • Create a directory cqlib
    • Create a src directory
      • Create project directory cqlib
        • Create cylinder.py with the following contents:
          import cadquery as cq
          
          def cylinder(radius = 2.5, height = 5 ):
            work = cq.Workplane().cylinder(height, radius)
            return work
        • Make __init__.py with the following:
          from .cylinder import cylinder
    • create pyproject.toml with the following contents:
      [build-system]
      requires = ["setuptools>=61.0"]
      build-backend = "setuptools.build_meta"
      
      [project]
      name = "cqlib"
      version = "0.0.1"
      authors = [
        { name="James Adams", email="inklink28@gmail.com" },
      ]
      description = "Demo CadQuery library"
      readme = "README.md"
      license = { file="LICENSE" }
      requires-python = ">=3.8"
      classifiers = [
          "Programming Language :: Python :: 3",
          "License :: OSI Approved :: Apache Software License",
          "Operating System :: OS Independent",
      ]
      dependencies = [
      "cadquery==2.2.0b0",
      'cqmore @ git+https://github.com/JustinSDK/cqMore'
      ]
      
      [project.urls]
      "Homepage" = "https://github.com/medicationforall/cqlib"
      "Bug Tracker" = "https://github.com/medicationforall/cqlib/issues"    
  • Create README.MD file
  • create LICENSE file
  • Initialize the repo
    git init
  • Stage changes
    git add .
  • Commit changes
    git commit -m "initial commit"
  • Install the package locally
      pip install ./
    
  • Run your package in CQ-Editor
    from cqlib import cylinder
    
    result = cylinder()
    show_object(cylinder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment