PartCAD Documentation

repository·devel·Indexed 19 days ago

https://github.com/partcad/partcad

PartCAD is a next-generation computer-aided design (CAD) system for managing the lifecycle of manufacturable physical products. It functions as a hardware package manager that integrates requirements, detailed designs, and implementation artifacts into deterministic specifications. The system includes a CLI (pc), support for various representations (build123d, cadquery, openscad, sdf), and vendor-neutral AI agent skills for automating part, assembly, and sketch generation.

Tokens
62.1K
Snippets
237
Records
320
Agent score
66%

What's inside PartCAD

  1. What is PartCAD?

    devel
    PartCAD is a package manager for CAD models and a framework for managing assemblies. It is designed to complement Git, providing the capabilities necessary to substitute commercial Product Lifecycle Management (PLM) tools. It manages information regarding mechanical parts and their relationships within larger assemblies, allowing for part reuse across multiple assemblies and projects while leveraging Git for versioning and collaboration.
  2. What is PartCAD?

    devel
    PartCAD is a standard for documenting manufacturable physical products. Unlike traditional CAD tools used for drawing, PartCAD focuses on creating a clear and deterministic specification of a product. It acts as a package manager for hardware, allowing users to maintain product information, requirements, and implementation details (mechanical, PCB, and software) in a modular and reusable way. This enables building upon not just previous CAD files, but also previous manufacturing processes.
  3. Identify the correct PartCAD package for your needs

    devel

    PartCAD is distributed across several packages depending on your use case:

    • partcad: The core Python module for programmatic instantiation of parts, assemblies, and scenes.
    • partcad-cli: The package containing PartCAD command-line tools.
    • partcad-dev: Standalone PartCAD bundles.
  4. Understand package identity and location

    devel

    In PartCAD, a package is addressed by its location (the path at which it is loaded, derived from its parent). For example, a package in the gobilda subfolder of //vendor is addressed as //vendor/gobilda.

    • name field: This declares the package's identity (the path it expects to be seen at). This only takes effect when the package is loaded as the root.
    • Vendoring: When you copy (vendor) a package into your own tree, it is loaded at its new location, not its declared name. PartCAD automatically redirects any internal references the package makes to its own name to its new location, ensuring the vendored copy uses itself rather than pulling in the original upstream version.
  5. Use Interfaces to connect parts and assemblies

    devel

    Interfaces define how parts and assemblies connect.

    • Implementation: A part can implement one or more interfaces (and multiple instances of each).
    • Inheritance: Interfaces can hierarchically inherit ports and properties.
    • Mating: Compatibility information (mating) can be maintained within interfaces.
    • Automatic Placement: If interfaces and mating are defined, PartCAD can often place parts and assemblies without user-provided coordinates.
  6. Use the partcad Python module for CAD automation

    devel

    The partcad Python module serves as the core engine for programmatic CAD management. You can use it in Python scripts to:

    • Instantiate parts, assemblies, and scenes implemented as PartCAD packages.
    • Integrate with [CadQuery] and [build123d] scripts.
    • Power custom web, mobile, or desktop applications that render CAD models.
    • Generate Bills of Materials (BoMs) and assembly instructions.

    Note: If you need command-line tools, use the partcad-cli package instead of this module.

  7. Configure port matching and orientation

    devel

    Ports are matched based on their logical center coordinates and their direction (orientation).

    Matching Rules:

    • For direct connections (e.g., male/female connectors) without offsets, coordinates should match and directions should be opposite (rotated 180 degrees around [1, 1, 0]).
    • Convention: Use the Z-axis (blue) as the main direction.
      • Male ports: Z-axis points outwards.
      • Female ports: Z-axis points inwards.

    Interchangeable Ports: To allow multiple ports to connect to any other (like NEMA-17 mounting holes), orient the ports in a circular direction. For example, set the X-axis (red) to point to the next port clockwise using the right-hand rule.

  8. Define 3D parts by sweeping 2D sketches

    devel

    The sweep operation in PartCAD allows you to create complex 3D geometries by taking a 2D sketch (such as a circle, a DXF file, or a custom clock sketch) and sweeping it along a path to produce a 3D part.

    Common use cases demonstrated in this example include:

    • clock: Sweeping a clock sketch to create a 3D clock.
    • dxf: Sweeping a DXF sketch to create a 3D part.
    • pipe: Sweeping a circle sketch to create a pipe.
  9. Access configuration parameters in providers using get_from_config()

    devel

    To avoid hardcoding sensitive or reusable values (like API keys or URLs) multiple times, you can reference parameters dynamically within the providers section of your configuration. Use the get_from_config() function within a parameter definition to pull values from the parameters section of ~/.partcad/config.yaml.

    # ~/.partcad/config.yaml
    parameters:
      my_api_url: "https://api.example.com"
    
    providers:
      my_provider:
        type: store
        parameters:
          url:
            type: string
            default: {{ get_from_config() }}
  10. Implement supply chain operations using providers

    devel

    PartCAD uses providers to implement supply chain operations. Common provider types include:

    • store: Used to buy off-the-shelf parts by SKU.
    • manufacturer: Used to manufacture parts following specific instructions.

    To list existing providers in the PartCAD public repository, use the pc list providers command with the -r flag pointing to the commerce service.

    pc init
    pc list providers -r //pub/svc/commerce
  11. Scripting conventions for Python-based CAD

    devel

    When authoring scripts for build123d, cadquery, or sdf, follow these conventions:

    • Imports: Import everything you use, including math and the specific CAD library.
    • Exposing the part: Call show_object(<result>) to make the part visible in the renderer.
    • Exports: Do not use export statements.
    • CadQuery specific: Avoid using tetrahedron or hexahedron primitives.

    OpenSCAD Convention:

    • Provide a complete script defining all functions and constants.
    • Do not use external modules.
    • Do not use export statements.
  12. Author a PartCAD ASSY file

    devel

    An .assy file is a YAML tree of nodes under a links: key. You must choose exactly one placement method for each part node: location, connectPorts, or connect.

    Container Node

    Used for the top level or grouping nodes.

    name: <optional>
    description: <the description>
    location: <optional [[x,y,z], [ax,ay,az], angle_deg]>
    links:
      - <node>

    Part Node Placement Methods

    1. Explicit Placement (Translation + Rotation): Use this when parts do not have defined ports or interfaces.

    - part: <part-path>
      name: <instance-name>
      location: [[x, y, z], [ax, ay, az], angle_deg]

    2. Connect by Ports (No interface mating): Use this to connect specific ports between instances.

    - part: <part-path>
      connectPorts:
        with: <this part's port>
        name: <target instance name>
        to: <target port>

    3. Connect by Interfaces (Universal mating): Use this for parts that define compatible interfaces.

    - part: <part-path>
      connect:
        with: <this part's interface>
        name: <target instance name>
        to: <target interface>

    Note: with names the interface/port on the part being added; to names it on the part already in the assembly. Use millimeters and degrees.

    Sub-assembly Node

    Identical to a part node, but uses the assembly: key instead of part: and can contain its own nested links:.

    # Example Part Node with explicit placement
    - part: //package:part_name
      name: my_instance
      location: [[10, 0, 0], [0, 0, 1], 90]
    
    # Example Part Node with port connection
    - part: //package:part_name
      connectPorts:
        with: port_a
        name: existing_part_instance
        to: port_b