Multi-section Sweep

397 views
Skip to first unread message

CONNOR MORENO

unread,
Jun 28, 2022, 3:07:59 PM6/28/22
to CadQuery
Hi all,

I'm having some difficulty understanding how to use the multi-section sweep (using the multisection flag on workplane.sweep). As an exercise, I'm trying to create a sweep whose cross-sectional shape alternates between circles and squares along a path of a half revolution of a circle. I thought perhaps the following script would work

import cadquery as cq
import numpy as np

n = 5
phi = np.linspace(0, np.pi, num = n)
rad = 5
pts = []
j = 0

for i in phi:
pt = (rad*np.cos(i), rad*np.sin(i))
pts += [pt]

rotation = (0.0, np.rad2deg(i), 0.0)

if i == phi[0]:
sweep = cq.Workplane("XZ").transformed(rotate = rotation, offset = pt)
else:
sweep = sweep.copyWorkplane(cq.Workplane("XZ")
).transformed(rotate = rotation, offset = pt)

if (j % 2) == 0:
sweep = sweep.circle(1)
else:
sweep = sweep.rect(1, 1)

j += 1

path = cq.Workplane("XY").spline(pts)
sweep = sweep.sweep(path, multisection = True)
cq.exporters.export(sweep, 'sweep.step')


but running gives the following error

Traceback (most recent call last):

File "/home/camoreno/Documents/ParametricStellarator/sweep_test.py", line 35, in <module>

sweep = sweep.sweep(path, multisection = True)

File "/home/camoreno/miniforge/lib/python3.9/site-packages/cadquery/cq.py", line 3161, in sweep

r = self._sweep(

File "/home/camoreno/miniforge/lib/python3.9/site-packages/cadquery/cq.py", line 3732, in _sweep

thisObj = Solid.sweep_multi(sections, p, makeSolid, isFrenet, mode)

File "/home/camoreno/miniforge/lib/python3.9/site-packages/cadquery/occ_impl/shapes.py", line 3234, in sweep_multi

builder.Build()

OCP.Standard.Standard_ConstructionError: BRepFill :: profiles are inconsistent


I'm having trouble finding documentation for the multi-section sweep and I'm certain I'm using it incorrectly. Any help would be greatly appreciated and please let me know if I can provide additional information/explanation.

Thanks!

Connor

CONNOR MORENO

unread,
Jun 29, 2022, 11:57:47 AM6/29/22
to CadQuery
Was able to get it to work with the following script. Turns out I was misplacing the cross-sectional profiles such that they didn't coincide with the defined path.

import cadquery as cq
import numpy as np

n = 5
phi = np.linspace(0, np.pi, num = n)
rad = 5
pts = []
j = 0

for i in phi:
pt = (rad*np.cos(i), rad*np.sin(i))
pts += [pt]
rotation = (0.0, np.rad2deg(i), 0.0)

if i == phi[0]:
sweep = cq.Workplane("XZ", origin = pt).transformed(rotate = rotation)
else:
sweep = sweep.copyWorkplane(cq.Workplane("XZ", origin = pt)
).transformed(rotate = rotation)


if (j % 2) == 0:
sweep = sweep.circle(1)
else:
sweep = sweep.rect(1, 1)

j += 1

path = cq.Workplane("XY").spline(pts)
sweep = sweep.sweep(path, multisection = True)
cq.exporters.export(sweep, 'sweep.step')


For anyone viewing this from the future who is also confused about how to use this feature, what you want to do is the following:
  • Define cross-sectional profiles of the shape you want to sweep. Put them all on the same stack in a manner similar to what's done in the script above.
  • Define the path you want to sweep along
  • Ensure the profiles coincide with the path, meaning the path passes inside of the profile
At least, that's my understanding of how it works. Hope this helps!

Connor

CONNOR MORENO

unread,
Jun 29, 2022, 12:01:43 PM6/29/22
to CadQuery
Here are some images of the shape created from the script above as a reference
Screen Shot 2022-06-29 at 8.59.08 AM.png
Screen Shot 2022-06-29 at 8.59.45 AM.png
Screen Shot 2022-06-29 at 9.00.35 AM.png
Reply all
Reply to author
Forward
0 new messages