CadQuery / CadQuery/cq-cli

[Help needed] errors exporting with cq-cli

Open
#42 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
30
Forks
10
PR merge metrics
No merged PRs in 30d

Description

Hello all,

I made some code for creating parts with cadquery and now i want to export with cq-cli to differents formats such as STEP or GLTF.

# CadQuery 2.x script: 320 mm vented rotor with 5 x M12 holes on 114.3 mm PCD

import os, math
import cadquery as cq
from cadquery import exporters

# --------------------
# Parameters (mm)
# --------------------
rotor_od = 320.0              # outer diameter
r_outer = rotor_od / 2.0

# Friction ring geometry
ring_inner_radius = 120.0     # inner radius of friction ring (adjust as needed)
plate_thickness = 5.0         # thickness of each friction plate
air_gap = 8.0                 # vent gap between plates
t_total = plate_thickness * 2 + air_gap

# Hub and mounting
pcd = 114.3                    # pitch circle diameter for bolt holes
bolt_count = 5
bolt_hole_d = 12.5             # M12 typical clearance hole (adjust to fit)
center_bore_d = 70.0           # assumed center bore; confirm with your hub
hub_radius = max(pcd / 2.0 + 8.0, center_bore_d / 2.0 + 8.0)  # leave margin around holes

# Vane and spoke layout (simplified straight vanes)
vane_count = 24
vane_width = 8.0               # tangential width of each vane
spoke_width = 8.0              # tangential width of spokes connecting hub-to-ring
# radial length of vanes across the vented ring
vane_radial_len = max(0.0, r_outer - ring_inner_radius)
# radial length of spokes between hub and ring inner radius
spoke_radial_len = max(0.0, ring_inner_radius - hub_radius)

# --------------------
# Helper functions
# --------------------
def polar_points(radius, count, start_deg=0.0):
    return [
        (radius * math.cos(math.radians(start_deg + i * 360.0 / count)),
         radius * math.sin(math.radians(start_deg + i * 360.0 / count)))
        for i in range(count)
    ]

# --------------------
# Build vented rotor
# --------------------
base = cq.Workplane("XY")

# Top and bottom friction plates (annular rings)
top_plate = (
    base.circle(r_outer)
        .circle(ring_inner_radius)
        .extrude(plate_thickness)
)
bottom_plate = (
    base.circle(r_outer)
        .circle(ring_inner_radius)
        .extrude(plate_thickness)
        .translate((0, 0, plate_thickness + air_gap))
)

rotor = top_plate.union(bottom_plate)

# Central hub (solid disc) to carry bore and bolt holes
hub = base.circle(hub_radius).extrude(t_total)
rotor = rotor.union(hub)

# Vanes: straight rectangular bridges across the air gap
# Constructed as boxes centered in Z across the air gap
if vane_radial_len > 0:
    for i in range(vane_count):
        angle = i * 360.0 / vane_count
        vane = (cq.Workplane("XY")
                .box(vane_radial_len, vane_width, air_gap)  # X=radial, Y=tangential, Z=gap
                .translate((ring_inner_radius + vane_radial_len / 2.0, 0, plate_thickness + air_gap / 2.0))
                .rotate((0, 0, 0), (0, 0, 1), angle))
        rotor = rotor.union(vane)

# Spokes: connect hub to ring inner radius through the air gap
if spoke_radial_len > 0:
    for i in range(vane_count):
        angle = i * 360.0 / vane_count
        spoke = (cq.Workplane("XY")
                 .box(spoke_radial_len, spoke_width, air_gap)
                 .translate((hub_radius + spoke_radial_len / 2.0, 0, plate_thickness + air_gap / 2.0))
                 .rotate((0, 0, 0), (0, 0, 1), angle))
        rotor = rotor.union(spoke)

# Center bore
rotor = rotor.cut(base.circle(center_bore_d / 2.0).extrude(t_total))

# Bolt holes on PCD (through all)
bolt_radius = pcd / 2.0
bolt_pts = polar_points(bolt_radius, bolt_count, start_deg=0.0)
bolt_cuts = cq.Workplane("XY").pushPoints(bolt_pts).circle(bolt_hole_d / 2.0).extrude(t_total)
rotor = rotor.cut(bolt_cuts)

# Combine into single solid for clean exports / measurements
rotor = rotor.combine()


# Final result for display/export tools
result = rotor

When i try to export to step with the simplest command : /cq-cli --codec step --infile "
eb98df729aff4c99812502be7a9f7fcb/generated_22fdb39fedc14ac6afffc2b3f48fe4d2.py"

i have this error :
Conversion codec error: Traceback (most recent call last):
File "/mnt/c/0-sources/Perso/DesignerAgent/venv_cq/lib/python3.12/site-packages/cq_cli/main.py", line 550, in main
converted = codec_module.convert(
^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/0-sources/Perso/DesignerAgent/venv_cq/lib/python3.12/site-packages/cq_cli/cqcodecs/cq_codec_step.py", line 15, in convert
shape = build_result.results[0].shape
~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

and to GLTF :
Conversion codec error: Traceback (most recent call last):
File "/mnt/c/0-sources/Perso/DesignerAgent/venv_cq/lib/python3.12/site-packages/cq_cli/main.py", line 550, in main
converted = codec_module.convert(
^^^^^^^^^^^^^^^^^^^^^
File "/mnt/c/0-sources/Perso/DesignerAgent/venv_cq/lib/python3.12/site-packages/cq_cli/cqcodecs/cq_codec_gltf.py", line 14, in convert
if type(build_result.first_result.shape).name == "Assembly":
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'shape'

I'm not sure my script is fully correct but it works in cq editor :

Image

Do you have any hints or tips or myabe know what can cause this please ?

Thanks in advance

Regards

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cq_cli/main.py and the conversion paths in cq_cli/cqcodecs/cq_codec_step.py and cq_codec_gltf.py. Run the supplied script through cq-cli and inspect how build_result and first_result are populated compared with cq-editor execution. Done means the reported script is handled consistently and STEP and GLTF conversion no longer fail with these empty-result errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.