创建与导入
所有 Model 构造方法都返回由当前 Session 持有的新 Shape。输入是普通 Python 数值和序列;除 Sketch API 明确使用二维值外,坐标均为三维。
基本体
| 方法 | 参数 | 结果与约束 |
|---|---|---|
box(width, depth, height) | 正长度 | 从模型原点开始,沿正轴延伸的 Solid |
cylinder(radius, height) | 正半径与正高度 | 沿正 Z 轴的 Solid |
sphere(radius) | 正半径 | 以模型原点为中心的封闭 Solid |
cone(radius1, radius2, height) | 非负半径、正高度 | 沿正 Z 的圆锥或圆台;两个半径不能定义退化实体 |
with cad.Model() as model:
plate = model.box(80.0, 50.0, 4.0)
boss = model.cylinder(8.0, 12.0)
body = model.union(plate, model.translate(boss, 40.0, 25.0, 4.0))
Polyline 与轮廓
polyline(points, closed=False) 按顺序用直线连接点。开放 Wire 至少需要两个不同点;创建 Face 时需要不自交的封闭 Wire。
circle_profile(radius, center=(0, 0, 0), normal=(0, 0, 1)) 返回圆形 Wire,法向不能为零。arc(start, middle, end) 通过三个不共线点构造圆弧。
interpolate(points, periodic=False, tolerance=1e-6) 拟合经过有序点的曲线;periodic=True 请求周期闭合曲线。helix(pitch, height, radius, center, direction) 沿给定方向创建螺旋线。
精确 B-spline
curve = model.bspline(
control_points=((0, 0, 0), (15, 5, 0), (30, 0, 0)),
degree=2,
knots=(0.0, 1.0),
multiplicities=(3, 3),
weights=None,
periodic=False,
)
控制点数量、Degree、Knot、Multiplicity 与可选 Weight 必须组成有效 B-spline 定义。只需要插值而不需要精确 Knot 控制时使用 interpolate。
Face 与曲面
| 方法 | 输入 | 输出 |
|---|---|---|
face(wire) | 封闭平面 Wire | 平面 Face |
bezier_surface(points, weights=None) | 矩形控制网格 | Bezier 曲面 |
fit_surface(points, tolerance=1e-3, degree_min=3, degree_max=8) | 矩形采样网格 | 拟合 B-spline 曲面 |
ruled_surface(edge_a, edge_b) | 两条兼容 Edge | Edge 间直纹 Face |
filling_surface(edges, tolerance=1e-6) | 有序边界 Edge | 填充 Face |
gordon_surface(profiles, guides, tolerance=1e-6) | 相交的 Profile/Guide 网络 | 网络曲面 |
曲面控制网格和采样网格必须为矩形且数值有限。网络曲面要求两组曲线彼此兼容;断开或数值条件较差的边界可能被原生构造拒绝。
导入
| 方法 | 格式 | 说明 |
|---|---|---|
import_step(path) | STEP | 精确交换几何;装配内容归并为 Shape 结果 |
import_brep(path) | OpenCascade BREP | 原生拓扑与几何 |
import_stl(path) | STL | 三角网格输入,不代表恢复出精确曲面 |
导入方法读取磁盘;文件缺失、不可读、格式错误或不受支持时会抛出 I/O 或原生异常。下游使用前应查询 kind、bbox、topology 并调用 validate()。