CadQuery / cadquery

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

Planar surface #1590

Open OmarZaki96 opened 4 months ago

OmarZaki96 commented 4 months ago

I have a simple code that generate a box

rectangular_prism = cq.Workplane("XY").box(1, 1, 1)

I want to add a rectangular planar selectable surface at the top face, with dimensions 0.5x0.5.

How can I create planar surfaces (or zero thickness surface) in CadQuery?

adam-urbanczyk commented 4 months ago

I'll plug the free function API here (you'll have to be on master):

from cadquery.occ_impl.shapes import *

# start with a box
b = box(1,1,1)

# split int top face and others
f_top = b.faces('>Z')
f_rest = b.faces('not >Z')

# create the new top face
f_new = f_top + plane(0.5,0.5).moved(f_top.Center())

# assemble into a solid
res = solid(f_rest,f_new)

show_object(res)

afbeelding