2022/12/21 23:55

## 1、基于面的 API

import cadquery as cq

result = (
cq.Sketch()
.trapezoid(4,3,90)
.vertices()
.circle(.5, mode='s')
.reset()
.vertices()
.fillet(.25)
.reset()
.rarray(.6,1,5,1).slot(1.5,0.4, mode='s', angle=90)
)


## 2、模式

result = (
cq.Sketch()
.rect(1, 2, mode='c', tag='base')
.vertices(tag='base')
.circle(.7)
.reset()
.edges('|Y', tag='base')
.ellipse(1.2, 1, mode='i')
.reset()
.rect(2, 2, mode='i')
.clean()
)


## 3、基于边的 API

import cadquery as cq

result = (
cq.Sketch()
.segment((0.,0),(0.,2.))
.segment((2.,0))
.close()
.arc((.6,.6),0.4,0.,360.)
.assemble(tag='face')
.edges('%LINE',tag='face')
.vertices()
.chamfer(0.2)
)


## 4、凸包

result = (
cq.Sketch()
.arc((0,0),1.,0.,360.)
.arc((1,1.5),0.5,0.,360.)
.segment((0.,2),(-1,3.))
.hull()
)


## 5、基于约束的草图

import cadquery as cq

result = (
cq.Sketch()
.segment((0,0), (0,3.),"s1")
.arc((0.,3.), (1.5,1.5), (0.,0.),"a1")
.constrain("s1","Fixed",None)
.constrain("s1", "a1","Coincident",None)
.constrain("a1", "s1","Coincident",None)
.constrain("s1",'a1', "Angle", 45)
.solve()
.assemble()
)


• 固定点约束：指定的点被固定
• 重合约束：指定的两个点重合
• 夹角约束：两个实体的夹角固定
• 长度约束：指定的实体具有固定的长度
• 距离约束：两点之间的距离固定
• 半径约束：指定的实体具有固定的半径
• 方向约束：指定的实体平行于 (x,y)
• 弧角度：指定的实体具有固定的圆周角度

## 6、工作平面集成

import cadquery as cq

result = (
cq.Workplane()
.box(5,5,1)
.faces('>Z')
.sketch()
.regularPolygon(2,3,tag='outer')
.regularPolygon(1.5,3,mode='s')
.vertices(tag='outer')
.fillet(.2)
.finalize()
.extrude(.5)
)


Sketch API 在 sketch() 调用和原始工作平面之后可用。

import cadquery as cq

result = (
cq.Workplane()
.box(5,5,1)
.faces('>Z')
.workplane()
.rarray(2,2,2,2)
.rect(1.5,1.5)
.extrude(.5)
.faces('>Z')
.sketch()
.circle(0.4)
.wires()
.distribute(6)
.circle(0.1,mode='a')
.clean()
.finalize()
.cutBlind(-0.5,taper=10)
)


import cadquery as cq

s = (
cq.Sketch()
.trapezoid(3,1,110)
.vertices()
.fillet(0.2)
)

result = (
cq.Workplane()
.box(5,5,5)
.faces('>X')
.workplane()
.transformed((0,0,-90))
.placeSketch(s)
.cutThruAll()
)


from cadquery import Workplane, Sketch, Vector, Location

s1 = (
Sketch()
.trapezoid(3,1,110)
.vertices()
.fillet(0.2)
)

s2 = (
Sketch()
.rect(2,1)
.vertices()
.fillet(0.2)
)

result = (
Workplane()
.placeSketch(s1, s2.moved(Location(Vector(0, 0, 3))))
.loft()
)


0 评论
0 收藏
0