Sweep command

91 views
Skip to first unread message

Adhip

unread,
Mar 4, 2024, 2:35:56 AMMar 4
to CadQuery
Hey everyone

I have been struggling with sweep command. I am attaching below what I want to happen using cadquery functions.

(All images are made in Creo and not using Cadquery)

Step 1: Creating the main body

box.png

This was quite easily done.

Step 2: Creating the profile 

profile.png

You can see in image above, the blue line is the profile. I have the equations and generation of points to create this curve.

Step 3: Using sweep to cut in main body

swept cut.png

This is where I struggle because I'm not getting what I want. I posted previously also.
If anyone can tell me method step by step? I have the equations and everything to create my curve, I just want to get this kind of cut in main body using sweep. It will help me alot if someone can tell.

Thanks in advance

Dov Grobgeld

unread,
Mar 4, 2024, 2:46:34 AMMar 4
to Adhip, CadQuery
Hi Adhip,

There is an additional step that you are not stating explicitly. Namely that of giving thickness to your profile. This is equivalent to setting the penwidth before stroking in postscript/SVG, and is known as an offset curve. Open Cascade has support for this in the function:


But I don't know if it is wrapped in cadquery. You can however always go back and forth between native Open Cascade and CadQuery through the OCP binding.

So you want to do the following:

1. Turn your parametric curve into an outline by creating an offset (or two for symmetry)
2. Cut a hole

I hope this helps.


--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/0ceab048-705b-473d-80cf-db05df3eae75n%40googlegroups.com.

Adam Urbanczyk

unread,
Mar 4, 2024, 2:59:29 AMMar 4
to CadQuery
Thanks for posting, but the OP asked specifically about sweeping, you are pointing him to an OCCT API that is not particularly relevant and this is not an OCCT group. FYI CQ does expose 2D offset functionality: https://cadquery.readthedocs.io/en/latest/classreference.html#cadquery.Workplane.offset2D or https://cadquery.readthedocs.io/en/latest/classreference.html#cadquery.Sketch.offset

@OP do you have an MRE, what did you try in CQ?

In general what you describe should be possible with the following cq.Workplane methods: box, parametricCurve, sweep, cut. Note that you need to crate the x-section that you want to sweep somehow and it will need to be in the correct orientation

Adhip

unread,
Mar 4, 2024, 5:23:24 AMMar 4
to CadQuery
Hey Adam

Sorry I'm still learning coding so I can be a little slow. Is this what you wanted?

import cadquery as cq
import numpy as np

#Inputs required for the generation of plate
m              = 1
R              = Hole_rad

c=16 #number of points required for involutes
for i in range(m): #Left side
    angle = 0
    x1y1points=[]
    for j in range(c):
        x1 = R * (np.cos(angle))
        y1 = R * (np.sin(angle))
        angle += 1 * (np.pi/180)
        x1y1points.append([x1,y1])
    c-= int((360/channel))#points reduction
    plate = cq.Workplane().polyline(x1y1points)

inv_track = cq.Workplane().rect(1.56,1.2).sweep(plate)
body=cq.Workplane().rect(20,18,centered=True).extrude(2)
final=body.cut(inv_track)

display(plate)
display(inv_track)
display(body)
display(final)

It's a simple curve acting as a profile and I want cut a rectangular profile in the main body. Have a look.
Thanks in advance!

Dov Grobgeld

unread,
Mar 4, 2024, 3:36:42 PMMar 4
to Adhip, CadQuery

Hi Adhip,

Sorry. Your example has several problems:

  • The variables R and channel have not been defined
  • You override your variable plate in your range(m) loop.

Make sure that your example runs as is, e.g. in cq-editor.


Adhip

unread,
Mar 5, 2024, 1:44:33 AMMar 5
to CadQuery
import cadquery as cq
import numpy as np
from cadquery import exporters


#Inputs required for the generation of plate
m              = 1
R              = 28

c=16
for i in range(m): 

    angle = 0
    x1y1points=[]
    for j in range(c):
        x1 = R * (np.cos(angle))
        y1 = R * (np.sin(angle))
        angle += 1 * (np.pi/180)
        x1y1points.append([x1,y1])
    plate = cq.Workplane().polyline(x1y1points)

inv_track = cq.Workplane().rect(1.56,1.2).sweep(plate)
body=cq.Workplane().rect(20,18,centered=True).extrude(2)
final=body.cut(inv_track)

display(plate)
display(inv_track)
display(body)
display(final)


The reason why I have my plate variable in for loop because in my original code, im creating the same curve at different locations. For the purpose of MRE, I'm giving only one iteration. 
Also, I use Jupyter Lab, not CQ editor, and this code runs on that.
Thanks in advance

Adam Urbanczyk

unread,
Mar 5, 2024, 2:58:33 AMMar 5
to CadQuery
I don't know what is the intent of your code, but take a look here. Pay attention to the orientation and position of the inv_track workplane. The rest is just an example.

import cadquery as cq
from math import cos, sin, pi

path = (
    cq.Workplane()
    .parametricCurve(
        lambda t: (cos(t)**(2/4), sin(t)**(2/4)),
        start=0,
        stop=pi/2
     )
)

inv_track = (
    cq.Workplane("XZ", origin=path.val().startPoint())
    .rect(0.5,2)
    .sweep(path)
)

final=(
    cq.Workplane()
    .rect(4,5)
    .extrude(1, both=True)
    .cut(inv_track)
)

show_object(final)

Adhip

unread,
Mar 5, 2024, 4:49:05 AMMar 5
to CadQuery
Hello Adam

This example really helped me and I got what I wanted. One small issue, for my code, "inv_track" is generating as surface and not solid. Any specific command to convert it to solid?

THANKS A LOT!!

Adhip

unread,
Mar 8, 2024, 5:04:06 AMMar 8
to CadQuery
Hello Adam

I got my code working and I appreciate all the help from you guys. 
However, I had one question on Sweep command. While creating the swept solid from the profile, we mention orientation using "XY", "XZ" or "YZ". Is there a way to give plane which will be normal to my profile? The reason is because if I give "XZ", for example, and I have multiple curves, some curves will not have "XZ" as normal plane and it will lead to generation of weird looking solids. 
I'm not sure if this feature is available in CadQuery, if it is please let me know? 

Adam Urbanczyk

unread,
Mar 10, 2024, 5:12:26 AMMar 10
to CadQuery
You can construct any workplane using

cq.Workplane(cq.Plane(...))

You can get the start point, tangent using

cq.Edge.startPoint()
cq.Edge.tangentAt(0)

Adhip

unread,
Mar 11, 2024, 2:55:12 AMMar 11
to CadQuery
Thank you so much Adam!
I totally forgot about cq.Plane. My code works perfectly! Thanks a lot everyone!

Reply all
Reply to author
Forward
0 new messages