CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
2.93k stars 276 forks source link

How to sweep multisection along 3D..? #507

Open rasunag27 opened 3 years ago

rasunag27 commented 3 years ago

Dear all,

I would like to sweep from one diameter to another in a 3D space using points and spline. I tried using "Sweep_with_multisection" example. But, this uses offset in a single coordinate which is not useful for my case.

Below, I have mentioned the code in which the base I need diameter of 4mm and top I need diameter of 2 mm.

`import cadquery as cq from cadquery import exporters show = show_object

circle = cq.Workplane("XY").circle(0.072)

show(circle)

dia = 2 x = 50 y = 0 z = -5

pts = [(x, y, z), (x, (y+2), z), ((x-2), (y+14), z)] path= cq.Workplane("XY").moveTo(x, 0).spline(pts) sweep = cq.Workplane("XZ").moveTo(x, z).circle(dia).sweep(path)`

From the above code, I get the entire tube as diameter 2. Below is the manipulated code for sweep.

sweep = cq.Workplane("XZ").moveTo(x, z).circle(4).workplane(offset = (x-2, y+14, z)).circle(dia).sweep(path, multisection=True).

How to modify this sweep code so as to obtain base dia as 4mm and top dia as 2mm.

Below is the reference image.

Sweep_link

Any leads will be appreciated.

Regards, Sunag R A.

jmwright commented 3 years ago

There may be a cleaner way to do it, but have you looked at using loft? https://cadquery.readthedocs.io/en/latest/examples.html?highlight=loft#making-lofts

With lofts I expect you'd need to break the sweep up into sections. I'm not sure if that's useful either for your case.

adam-urbanczyk commented 3 years ago

You might want to try this:

dia = 2
x = 50
y = 0
z = -5

pts = [(x, y, z), (x, (y+2), z), ((x-2), (y+14), z)]
path= cq.Workplane("XY").moveTo(x, 0).spline(pts)

sweep = (cq.Workplane("XY")
    .pushPoints([path.val().locationAt(0)]).circle(2)
    .pushPoints([path.val().locationAt(1)]).circle(4)
    .consolidateWires()
    .sweep(path,multisection=True)
    )

image

rasunag27 commented 3 years ago

Dear adam,

Thank you for the reply.

I tried this and I am facing an attribute error stating 'Edge' object has no attribute named 'locationAt'.

What needs to be imported so as to remove the error.??

Thanks and Regards,

Sunag R A.

marcus7070 commented 3 years ago

locationAt is a very recent addition to CadQuery. If you are working from the stable version, you will have to switch to the master version as described in the README.md.

rasunag27 commented 3 years ago

Dear @marcus7070 ,

Thank you very much for the reply. I have installed the Cadquery using master only, Here is the same installation code line I have used as said in README.md .

conda install -c conda-forge -c cadquery cadquery=master

Or maybe do I need to reinstall again?

Regards,

Sunag R A.

adam-urbanczyk commented 3 years ago

Try reinstalling:

conda clean --all --force-pkgs-dirs
conda install --force-reinstall -c conda-forge -c cadquery cadquery=master

This sadly so complicated due to this conda issue: https://github.com/conda/conda/issues/7741

rasunag27 commented 3 years ago

@adam-urbanczyk I tried re-installing cadquery. But I am not able to get the attribute locationAt.

Are there any other alternative ways to obtain?

Regards, Sunag R A.

adam-urbanczyk commented 3 years ago

Could you paste the output of the above commands?

As a last resort you can try:

pip install git+https://github.com/CadQuery/cadquery.git
rasunag27 commented 3 years ago

Dear @adam-urbanczyk ,

After lot of uninstall, reinstall and creating new env for conda, the current version is working with above example.

Thank you for the support.

Regards, Sunag R A.