FreeCAD是一個基于OpenCASCADE的開源CAD/CAE工具。OpenCASCADE是一套開源的CAD/CAM/CAE幾何模型核心,來自法國Matra Datavision公司,是著名的CAD軟件EUCLID的開發平臺。FreeCAD可運行于Windows以及Linux系統環境下,是一種通用的3D CAD建模工具,其發展是完全開源的(遵循GPL的LGPL許可證)。
FreeCAD的直接應用目標是機械工程和產品設計,但其用途十分廣泛,也適用于建筑或其他工程專業,工程制圖等領域。FreeCAD具有類似CATIA,SolidWorks或Solid Edge的工具,因此也將提供CAX(CAD,CAM,CAE),PLM等功能。這是一個基于參數化建模功能與模塊化的軟件架構,使得它易于無需修改核心系統即可提供額外的功能。
在FreeCAD中使用Python腳本編寫可以極大地擴展其功能,并允許用戶自動化設計流程、創建自定義工具和宏,以及進行高級的參數化設計。以下是一些FreeCAD中Python腳本編寫的示例:
導入STEP
import Part
s = Part.Shape()
s.read(u"d:/Documents/drill.step")
Part.show(s)
?
創建平面
plan1=Part.makePlane(2,2,App.Vector(-1,-1,0.8),App.Vector(0,0,1))
Part.show(plan1)
布爾相交
k=s.common(plan1)
Part.show(k1)
瓶子建模
import FreeCAD as App
import Part, math
?
def makeBottleTut(myWidth = 50.0, myHeight = 70.0, myThickness = 30.0):
aPnt1=App.Vector(-myWidth / 2., 0, 0)
aPnt2=App.Vector(-myWidth / 2., -myThickness / 4., 0)
aPnt3=App.Vector(0, -myThickness / 2., 0)
aPnt4=App.Vector(myWidth / 2., -myThickness / 4., 0)
aPnt5=App.Vector(myWidth / 2., 0, 0)
?
aArcOfCircle = Part.Arc(aPnt2, aPnt3, aPnt4)
aSegment1=Part.LineSegment(aPnt1, aPnt2)
aSegment2=Part.LineSegment(aPnt4, aPnt5)
?
aEdge1=aSegment1.toShape()
aEdge2=aArcOfCircle.toShape()
aEdge3=aSegment2.toShape()
aWire=Part.Wire([aEdge1, aEdge2, aEdge3])
?
aTrsf=App.Matrix()
aTrsf.rotateZ(math.pi) # rotate around the z-axis
?
aMirroredWire=aWire.copy()
aMirroredWire.transformShape(aTrsf)
myWireProfile=Part.Wire([aWire, aMirroredWire])
?
myFaceProfile=Part.Face(myWireProfile)
aPrismVec=App.Vector(0, 0, myHeight)
myBody=myFaceProfile.extrude(aPrismVec)
?
myBody=myBody.makeFillet(myThickness / 12.0, myBody.Edges)
?
neckLocation=App.Vector(0, 0, myHeight)
neckNormal=App.Vector(0, 0, 1)
?
myNeckRadius = myThickness / 4.
myNeckHeight = myHeight / 10.
myNeck = Part.makeCylinder(myNeckRadius, myNeckHeight, neckLocation, neckNormal)
myBody = myBody.fuse(myNeck)
?
return myBody
?
el = makeBottleTut()
Part.show(el)
?