Hello,
Firstly I would like to say how great cadquery is! The API is very good and compared with FreeCAD scripting it a lot neater. The documentation is also very good so I would like to use cadquery in my next project. However, I am having trouble revolving a face that is made from splines.
I am working with a shape that is defined in a cylindrical co-ordinate system. This shape that is defined as series of constant radius ((x**2+y**2)**0.5) profiles . To create this shape I would usually create a Face from a loft of these profiles. This shape will be non-planar and cannot be defined from primitives or analytically. Then I would revolve this face about an axis to create a solid. However, I am having trouble doing this in cadquery. I am pretty sure this is a sane thing to do in CAD as I have done it before in FreeCAD. Most of the examples for sweeping and revolving are based on primitives so I get a bit lost trying to apply them to my case.
One problem I saw with my 'real' geometry was that the revolved shape was hollow, i.e. the faces did not enclose. So I decided to make a simple geometry to share here that demonstrated this problem. But, when I tried with a simplified geometry I got a different error! So let us start with the simplified geometry.
The problem that I am seeing is that when I try and create a Solid it contains a Compound object rather than a Face. This causes problems as the Solid class method revolve requires a face not a compound.
I have defined a wire named 'sweep' as I thought I might be able sweep about this line, but ideally I don't want to do that as it is arc so want to revolve to save making this sweep line.
I am running version '2.4.0.dev0'.
See my code below .
import numpy as np
import cadquery as cq
#this is a simple example, but basically it is a shape defined by multiple constant radius ((x**2+y**2)**0.5) profiles
#it is non-planar
mid_points =[ [(1,1,0),(1,1,1),(1.2,0.7483,2) ], [(2,2,0),(2,2,1),(2.2,1.7776,2) ]]
N_sections = 2
sweep_angle = np.pi/4
edges = []
for i in range(N_sections):
pts = [tuple(pt) for pt in mid_points[i]]
edges.append(cq.Edge.makeSpline([cq.Vector(p) for p in pts]))
if i==0:
rad = np.sqrt(pts[0][0]**2 + pts[0][1]**2)
t_start = np.arctan(pts[0][1]/pts[0][0])
t_end = t_start - sweep_angle
for_sweep =[]
for_sweep.append(cq.Vector(pts[0]))
for_sweep.append(cq.Vector((rad*np.cos(t_start -0.5*sweep_angle),rad*np.sin(t_start - 0.5*sweep_angle),pts[0][2])))
for_sweep.append(cq.Vector((rad*np.cos(t_end),rad*np.sin(t_end),pts[0][2])))
my_solid = cq.Solid.makeLoft(
[cq.Wire.assembleEdges([edge]) for edge in edges]
)
print(my_solid.faces())
sweep = cq.Wire.assembleEdges([cq.Edge.makeSpline(for_sweep)])
show_object(my_solid,name='my_solid')
show_object(sweep,'sweep_line')
As you can see the my_solid object is of type cadquery.occ_impl.shapes.Compound.
I would really appreciate any help on how to achieve this!
Thanks in advance,
John