资料

官网:https://www.freecad.org/

Github 仓库:https://github.com/FreeCAD/FreeCAD

中文文档:https://wiki.freecad.org/Online_Help_Toc/zh-cn

FreeCAD 社区: https://forum.freecad.org/index.php?style=5

Command Reference: https://wiki.freecad.org/Category:Command_Reference/zh-cn

FreeCAD|API 及其用法https://mp.weixin.qq.com/s/6yTHeZdN3dIZEHwHGpu8xg

鼠标键盘操作

缩放:滚轮,向下是缩小

移动:Ctrl+右键

旋转:Shift+右键

GUI 操作

中文界面

Edit—Preferences—General—Language—简体中文

建立几何-Part

  1. 工作台切换到 Part
  2. 零件—创建图元—可以创建:平面,立方体,圆柱体,圆锥体,球体,椭圆体,圆环体,棱柱,楔形,螺旋体,螺旋,圆,椭圆,点,线,正多边形
  3. 零件—拉伸

建立草图-Sketcher

  1. 工作台切换到 Sketcher
  2. Sketcher—创建草图
  3. 建立各种线,修剪
  4. 建立约束。共点,点在线上,水平,垂直,平行,设置线的水平长度等
  5. 退出草图工作台,可以再切换到 Part 工作台进行拉伸

Python 操作 FreeCAD

文档:https://wiki.freecad.org/Manual:A_gentle_introduction

打开 Python 面板:View—Panels—Python console

这样,我们在 FreeCAD 中的每一步操作都会有相应的 Python 代码在控制台输出。

官方文档创建 box

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 创建一个新的空文档
doc = FreeCAD.newDocument()

# 输入doc可在控制台的提示中看到其属性与方法
# 通常以大写字母开头的名称是属性,以小写字母开头的名称是函数
doc

# 将新对象添加到我们的文档中
box = doc.addObject("Part::Box","myBox")

# 使用 Python 时,文档不会自动重新计算。我们必须在需要时手动执行此操作来刷新界面
# doc.recompute() 执行完毕后就可以看到FreeCAD创建了一个立方体
doc.recompute()

# 获取所有的对象类型的列表
doc.supportedTypes()

# 探索一下盒子属性
box.Height
# >> 10.0 mm

# 改变盒子的尺寸
box.Length=20
box.Width = 5
box.Height = 5

# 查看框的线条颜色
box.ViewObject.LineColor

# 创建矢量-矢量加减
myvec = FreeCAD.Vector(2,0,0)
othervec = FreeCAD.Vector(0,3,0)
sumvec = myvec.add(othervec)
# >> Vector (2.0, 3.0, 0.0)

# FreeCAD每个对象都有一个 Placement 属性,它包含对象的位置(Base)和方向(Rotation)
box.Placement
# >> Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]
box.Placement.Base
# >> Vector (0.0, 0.0, 0.0)

# 将box从点box.Placement.Base移动到点sumvec
box.Placement.Base = sumvec

官方文档创建点-线-面-体

https://wiki.freecad.org/Manual:Creating_and_manipulating_geometry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import FreeCAD
import Part


# 点
V1 = FreeCAD.Vector(0,10,0)
V2 = FreeCAD.Vector(30,10,0)
V3 = FreeCAD.Vector(30,-10,0)
V4 = FreeCAD.Vector(0,-10,0)

# 线
L1 = Part.LineSegment(V1,V2)
L2 = Part.LineSegment(V4,V3)
VC1 = FreeCAD.Vector(-10,0,0)
C1 = Part.Arc(V1,VC1,V4)
VC2 = FreeCAD.Vector(40,0,0)
C2 = Part.Arc(V2,VC2,V3)

# 边界
E1 = Part.Edge(L1)
E2 = Part.Edge(L2)
E3 = Part.Edge(C1)
E4 = Part.Edge(C2)

# 添加几何到文档,几何名称会自动生成;也可以不添加,等形成了几何体,再添加体
# Part.show(E1)
# Part.show(E2)
# Part.show(E3)
# Part.show(E4)

# 曲线
W = Part.Wire([E1,E4,E2,E3])
# 面
F = Part.Face(W)
# 体-拉伸
P1 = F.extrude(FreeCAD.Vector(0,0,10))
print(P.ShapeType)

# 添加几何体到文档
obj = FreeCAD.ActiveDocument.addObject("Part::Feature","Solid_1")
obj.Shape = P1
FreeCAD.ActiveDocument.recompute()

其他常用操作

创建几何

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
创建向量
V1 = App.Vector(0, 5, 0)

创建直线
L1 = Part.LineSegment(V1, V2)

创建圆线
c = Part.makeCircle(5)

创建圆弧线
c = Part.Arc(V1, VC1, V4)

创建多边形
V1 = App.Vector(0, 2, 0)
V2 = App.Vector(0, 0, 0)
V3 = App.Vector(2, 0, 0)
wire = Part.makePolygon([V1, V2, V3,V1])


创建边界
edge1 = Part.makeLine((0, 0, 0), (2, 0, 0))
edge2 = Part.makeLine((2, 0, 0), (2, 2, 0))
wire = Part.Wire([edge1, edge2])

创建面
face = Part.Face(wire1)

创建平面
plane = Part.makePlane(3, 3, App.Vector(4, 0, 0), App.Vector(0, 1, 0))

创建椭圆
Part.Ellipse(Center, MajorRadius, MinorRadius)

创建环面
tor=Part.makeTorus(20, 10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 360, 180)

创建长方体
box = Part.makeBox(10, 10, 10)

创建球体
sphere1 = Part.makeSphere(5)
sphere2 = Part.makeSphere(5, App.Vector(0, 0, 0), App.Vector(0, 0, 1), -90, 90, 180)

创建圆柱
cylinder1 = Part.makeCylinder(4, 10)
cylinder2 = Part.makeCylinder(4, 10, App.Vector(20, 0, 0), App.Vector(0, 0, 1), 180)

创建圆锥
cone1 = Part.makeCone(5, 0, 20)
cone2 = Part.makeCone(5, 0, 20, App.Vector(20, 0, 0), App.Vector(0, 0, 1), 180)

布尔操作

合并 fuse,减 cut,相交 common

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import FreeCAD as App
import Part


# 布尔减
cylinder = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
# Part.show(cylinder)

sphere = Part.makeSphere(5, App.Vector(5, 0, 0))
# Part.show(sphere)

diff = cylinder.cut(sphere)
Part.show(diff)

# Part.show(diff.Solids[0])

平移

1
2
3
4
5
6
7
8
9
10
11
12
import FreeCAD as App

myShape = Part.makeBox(2, 2, 2)
Part.show(myShape)
myShape.Placement
# >> Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]

myShape.translate(App.Vector(10, 0, 0))
Part.show(myShape)
myShape.Placement
# >> Placement [Pos=(10,0,0), Yaw-Pitch-Roll=(0,0,0)]

旋转

1
2
3
4
5
6
7
8
9
10
11
12
13
import FreeCAD as App

myShape = Part.makeBox(2, 2, 2)
Part.show(myShape)
myShape.Placement
# >> Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]

# 绕直线(0,0,0)-(0,0,1)旋转180°
myShape.rotate(App.Vector(0, 0, 0),App.Vector(0, 0, 1), 180)
Part.show(myShape)
myShape.Placement
# >> Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(180,0,0)]

矩阵变换与缩放

1
2
3
4
5
6
7
8
9
10
# 矩阵变换
myMat = App.Matrix()
myMat.move(App.Vector(2, 0, 0))
myMat.rotateZ(math.pi/2)
myShape.transformShape(myMat)

# 缩放
myMat = App.Matrix()
myMat.scale(2, 1, 1)
myShape=myShape.transformGeometry(myMat)

导入 stp 文件

1
2
3
4
import Part
shape = Part.Shape()
shape.read("your_file_path")
shape

界面制作

https://www.yuque.com/xdd1997/ek3kug/xk5xu4?singleDoc# 《FreeCAD 笔记》