用于参数化 CAD 的 Python 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14519057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python module for parametric CAD
提问by Mermoz
I am looking for a CAD module for python. This is what i've found, correct me if I'm wrong:
我正在寻找一个用于 python 的 CAD 模块。这是我发现的,如果我错了,请纠正我:
- PythonCAD:
- file types: DWG,DXF,SVG
- oriented: click in a window
- last maintained: 2012-06-15
- documented: poor and dirty
- PythonOCC:
- file types: STEP, IGES, STL (import/export)
- oriented: scripts
- last maintained: 2013-01-12
- documented: good and clear
- Installation is such a pain
- Free-CAD (python wrapping)
- file types: ?
- oriented: click in a window and python scripting importable from python
- last maintained: jan 2013
- documented: very well
- 蟒蛇CAD:
- 文件类型:DWG、DXF、SVG
- 定向:在窗口中单击
- 最后维护:2012-06-15
- 记录:贫穷和肮脏
- PythonOCC:
- 文件类型:STEP、IGES、STL(导入/导出)
- 面向:脚本
- 最后维护:2013-01-12
- 记录:良好且清晰
- 安装好痛苦
- 免费 CAD(python 包装)
- 文件类型: ?
- 面向:单击窗口和可从 python 导入的 python 脚本
- 最后维护:2013 年 1 月
- 记录:非常好
Well, it seems the python bindings for FreeCad is the best but are there other things out there?
好吧,似乎 FreeCad 的 python 绑定是最好的,但还有其他东西吗?
采纳答案by Mermoz
I found that Freecad is the best solution. The python bindings lets you design parts in a comprehensive way.
我发现 Freecad 是最好的解决方案。python 绑定使您可以以全面的方式设计部件。
myShape = Part.makeBox(2,2,2)
myShape.translate(Base.Vector(2,0,0))
From simple geometries you can use boolean operations:
从简单的几何图形中,您可以使用布尔运算:
cylinder1 = Part.makeCylinder(3,10,Base.Vector(0,0,0),Base.Vector(1,0,0))
cylinder2 = Part.makeCylinder(3,10,Base.Vector(5,0,-5),Base.Vector(0,0,1))
common = cylinder1.common(cylinder2)
The only downpoint is the installation with mac os, I could not compile it on snow leaopard (because too much dependencies on unsustained libraries).
唯一的缺点是使用 mac os 安装,我无法在雪豹上编译它(因为对非持续库的依赖太多)。
But pythonocc has the same problem and what i don't like is the minimal documentation and the synthax which is too much opencascade like and not to much pythonistic.
但是 pythonocc 有同样的问题,我不喜欢的是最少的文档和 synthax,它太像 opencascade 而不是太多的 pythonistic。
回答by Ecir Hana
PythonOCC is probably the most feature complete. Here are some more:
PythonOCC 可能是功能最完整的。这里还有一些:
CADDD- uses PythonOCC, has GUI in Qt.
CADDD- 使用 PythonOCC,在 Qt 中有 GUI。
NURBS- Python module for working with NURBS.
NURBS- 用于处理 NURBS 的 Python 模块。
lolcad- looks very good but it was not updated for quite some time.
lolcad- 看起来很不错,但很长一段时间没有更新。
And of cource, you can try to use Blender, which has build-in Python interpreter and there are plugins for architecture and precision modeling (like this)
当然,您可以尝试使用 Blender,它具有内置的 Python 解释器,并且有用于架构和精确建模的插件(像这样)
回答by Volodimir Kopey
回答by steller
have a view at Salome. The code looks like this:
在莎乐美看风景。代码如下所示:
import sys
import salome
salome.salome_init()
theStudy = salome.myStudy
import salome_notebook
notebook = salome_notebook.NoteBook(theStudy)
sys.path.insert( 0, r'/tmp')
###
### GEOM component
###
import GEOM
from salome.geom import geomBuilder
import math
import SALOMEDS
geompy = geomBuilder.New(theStudy)
O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
Vertex_1 = geompy.MakeVertex(0, 0, 0)
Vertex_2 = geompy.MakeVertex(0, 2, 0)
Vertex_3 = geompy.MakeVertex(2, 2, 0)
Line_1 = geompy.MakeLineTwoPnt(Vertex_2, Vertex_3)
Line_1_vertex_2 = geompy.GetSubShape(Line_1, [2])
Line_1_vertex_3 = geompy.GetSubShape(Line_1, [3])
Curve_1 = geompy.MakeInterpol([Line_1_vertex_2, Line_1_vertex_3, Vertex_1], True, False)
geompy.addToStudy( O, 'O' )
geompy.addToStudy( OX, 'OX' )
geompy.addToStudy( OY, 'OY' )
geompy.addToStudy( OZ, 'OZ' )
geompy.addToStudy( Vertex_1, 'Vertex_1' )
geompy.addToStudy( Vertex_2, 'Vertex_2' )
geompy.addToStudy( Vertex_3, 'Vertex_3' )
geompy.addToStudy( Line_1, 'Line_1' )
geompy.addToStudyInFather( Line_1, Line_1_vertex_2, 'Line_1:vertex_2' )
geompy.addToStudyInFather( Line_1, Line_1_vertex_3, 'Line_1:vertex_3' )
geompy.addToStudy( Curve_1, 'Curve_1' )
回答by hum3
CADqueryis a plug currently for FreeCad that I have used and worked better than scripting OpenScad in Python. The developers are currently moving from FreeCad to Python OCC for Version 2 but I am currently plugging away with V1.
CADquery是目前用于 FreeCad 的插件,我使用过它并且比在 Python 中编写 OpenScad 脚本效果更好。开发人员目前正在从 FreeCad 迁移到版本 2 的 Python OCC,但我目前正在使用 V1。
CQParts is a really important part of what makes cadquery useful. It is an analogue of procedure so you design one wheel etc.
CQParts 是使 cadquery 有用的一个非常重要的部分。它是程序的类比,因此您可以设计一个轮子等。

