00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import Part, math
00026 import FreeCAD, FreeCADGui
00027 App=FreeCAD
00028 Gui=FreeCADGui
00029 from FreeCAD import Base
00030
00031 def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0):
00032 aPnt1=Base.Vector(-myWidth/2.,0,0)
00033 aPnt2=Base.Vector(-myWidth/2.,-myThickness/4.,0)
00034 aPnt3=Base.Vector(0,-myThickness/2.,0)
00035 aPnt4=Base.Vector(myWidth/2.,-myThickness/4.,0)
00036 aPnt5=Base.Vector(myWidth/2.,0,0)
00037
00038 aArcOfCircle = Part.Arc(aPnt2,aPnt3,aPnt4)
00039 aSegment1=Part.Line(aPnt1,aPnt2)
00040 aSegment2=Part.Line(aPnt4,aPnt5)
00041
00042 aEdge1=aSegment1.toShape()
00043 aEdge2=aArcOfCircle.toShape()
00044 aEdge3=aSegment2.toShape()
00045 aWire=Part.Wire([aEdge1,aEdge2,aEdge3])
00046
00047 aTrsf=Base.Matrix()
00048 aTrsf.rotateZ(math.pi)
00049
00050 aMirroredWire=aWire.transformGeometry(aTrsf)
00051 myWireProfile=Part.Wire([aWire,aMirroredWire])
00052
00053 myFaceProfile=Part.Face(myWireProfile)
00054 aPrismVec=Base.Vector(0,0,myHeight)
00055 myBody=myFaceProfile.extrude(aPrismVec)
00056
00057 myBody=myBody.makeFillet(myThickness/12.0,myBody.Edges)
00058
00059 neckLocation=Base.Vector(0,0,myHeight)
00060 neckNormal=Base.Vector(0,0,1)
00061
00062 myNeckRadius = myThickness / 4.
00063 myNeckHeight = myHeight / 10
00064 myNeck = Part.makeCylinder(myNeckRadius,myNeckHeight,neckLocation,neckNormal)
00065 myBody = myBody.fuse(myNeck)
00066
00067 faceToRemove = 0
00068 zMax = -1.0
00069
00070 for xp in myBody.Faces:
00071 try:
00072 surf = xp.Surface
00073 if type(surf) == Part.Plane:
00074 z = surf.Position.z
00075 if z > zMax:
00076 zMax = z
00077 faceToRemove = xp
00078 except:
00079 continue
00080
00081
00082 myBody = myBody.makeThickness([faceToRemove],-myThickness/50 , 1.e-3)
00083
00084 return myBody
00085
00086 def makeBoreHole():
00087
00088 if App.ActiveDocument == None:
00089 App.newDocument("Solid")
00090
00091 Group = App.ActiveDocument.addObject("App::DocumentObjectGroup","Group")
00092 Group.Label="Bore hole"
00093
00094 V1 = Base.Vector(0,10,0)
00095 V2 = Base.Vector(30,10,0)
00096 V3 = Base.Vector(30,-10,0)
00097 V4 = Base.Vector(0,-10,0)
00098 VC1 = Base.Vector(-10,0,0)
00099 C1 = Part.Arc(V1,VC1,V4)
00100
00101 VC2 = Base.Vector(40,0,0)
00102 C2 = Part.Arc(V2,VC2,V3)
00103 L1 = Part.Line(V1,V2)
00104
00105 L2 = Part.Line(V4,V3)
00106 S1 = Part.Shape([C1,C2,L1,L2])
00107
00108 W=Part.Wire(S1.Edges)
00109 F=Part.Face(W)
00110 P=F.extrude(Base.Vector(0,0,5))
00111
00112
00113 Wire=Group.newObject("Part::Feature","Wire")
00114 Wire.Shape=W
00115 Face=Group.newObject("Part::Feature","Face")
00116 Face.Shape=F
00117 Prism=Group.newObject("Part::Feature","Extrude")
00118 Prism.Shape=P
00119
00120 c=Part.Circle(Base.Vector(0,0,-1),Base.Vector(0,0,1),2.0)
00121 w=Part.Wire(c.toShape())
00122 f=Part.Face(w)
00123 p=f.extrude(Base.Vector(0,0,7))
00124 P=P.cut(p)
00125
00126
00127 Bore1=Group.newObject("Part::Feature","Borer_1")
00128 Bore1.Shape=p
00129 Hole1=Group.newObject("Part::Feature","Borer_Hole1")
00130 Hole1.Shape=P
00131
00132 c=Part.Circle(Base.Vector(0,-11,2.5),Base.Vector(0,1,0),1.0)
00133 w=Part.Wire(c.toShape())
00134 f=Part.Face(w)
00135 p=f.extrude(Base.Vector(0,22,0))
00136 P=P.cut(p)
00137
00138
00139 Bore2=Group.newObject("Part::Feature","Borer_2")
00140 Bore2.Shape=p
00141 Hole2=Group.newObject("Part::Feature","Borer_Hole2")
00142 Hole2.Shape=P
00143
00144 App.ActiveDocument.recompute()
00145
00146
00147 Gui.ActiveDocument.getObject(Wire.Name).hide()
00148 Gui.ActiveDocument.getObject(Face.Name).hide()
00149 Gui.ActiveDocument.getObject(Prism.Name).hide()
00150 Gui.ActiveDocument.getObject(Bore1.Name).hide()
00151 Gui.ActiveDocument.getObject(Hole1.Name).hide()
00152 Gui.ActiveDocument.getObject(Bore2.Name).hide()
00153 Gui.ActiveDocument.ActiveView.fitAll()