text: Topological data scripting Plane
  - 2.11 Creating an ellipse
  - 2.12 Creating a Torus
  - 2.13 Creating a box or cuboid
  - 2.14 Creating a Sphere
  - 2.15 Creating a Cylinder
  - 2.16 Creating a Cone
  - 3 Modifying shapes
  - 4 Exploring shapes
  - 5 Complete example: The OCC bottle
  - 6 Loading and Saving.
  Class Diagram
  This is a Unified Modeling Language (UML) overview of the most important classes of the Part module:
  Geometry
  The geometric.
  Quick example : Creating simple topology
  We will now create a topology by constructing it out of simpler geometry. As a case study we use a part as seen in the picture which consists of four vertexes, two circles and two lines.
  Creating Geometry
  First we have to create the distinct geometric parts of this wire. And we have to take care that the vertexes of the geometric parts are at the same position. Otherwise later on we might not be able to connect the geometric parts to a topology!
  So we create first the points:
  from FreeCAD import Base V1 = Base.Vector(0,10,0) V2 = Base.Vector(30,10,0) V3 = Base.Vector(30,-10,0) V4 = Base.Vector(0,-10,0)
  Arc
  To create an arc of circle we make a helper point and create the arc of circle through three points:
  VC1 = Base.Vector(-10,0,0) C1 = Part.Arc(V1,VC1,V4) # and the second one VC2 = Base.Vector(40,0,0) C2 = Part.Arc(V2,VC2,V3)
  Line
  The line contain a 3 numbers acually nothing else than.Line's time to display your creation on screen.
  Creating a Wire
  A wire is a multi-edge line and can be created from a list of edges or even a list of wires:
  edge1 = Part.makeLine((0,0,0), (10,0,0)) edge2 = Part.makeLine((10,0,0), (10,10,0)) wire1 = Part.Wire([edge1,edge2]) edge3 = Part.makeLine((10,10,0), (0,10,0)) edge4 = Part.makeLine((0,10,0), (0,0,0)) wire2 = Part.Wire([edge3,edge4]) wire3 = Part.Wire([wire1,wire2]) wire3.Edges > [<Edge object at 016695F8>, <Edge object at 0197AED8>, <Edge object at 01828B20>, <Edge object at 0190A788>] Part.show(wire3)
  Part.show(wire3) will display the 4 edges that compose our wire. Other useful information can be easily retrieved:
  wire3.Length > 40.0 wire3.CenterOfMass > Vector (5, 5, 0) wire3.isClosed() > True wire2.isClosed() > False
  Creating a Face
  Only faces created from closed wires will be valid. In this example, wire3 is a closed wire but wire2 is not a closed wire (see above)
  face = Part.Face(wire3) face.Area > 99.999999999999972 face.CenterOfMass > Vector (5, 5, 0) face.Length > 40.0 face.isValid() > True sface = Part.Face(wire2) face.isValid() > False
  Only faces will have an area, not wires nor edges.
  Creating a Circle:
  from math import pi arc1 = Part.makeCircle(10, Base.Vector(0,0,0), Base.Vector(0,0,1), 0, 180) arc2 = Part.makeCircle(10, Base.Vector(0,0,0), Base.Vector(0,0,1), 180, 360)
  Both arc1 and arc2 jointly will make a circle. Angles should be provided in degrees, if you have radians simply convert them using(c,0,pi)
  Arcs are valid edges, like lines. So they can be used in wires too.
  Creating a polygon
  A polygon is simply a wire with multiple straight edges. The makePolygon function takes a list of points and creates a wire along those points:
  lshape_wire = Part.makePolygon([Base.Vector(0,5,0),Base.Vector(0,0,0),Base.Vector(5,0,0)]):
  plane = Part.makePlane(2,2) plane ><Face object at 028AF990> plane = Part.makePlane(2,2, Base.Vector(3,0,0), Base.Vector(0,1,0)) plane.BoundBox > BoundBox (3, 0, 0, 5, 0, 2)
  BoundBox is a cuboid enclosing the plane with a diagonal starting at (3,0,0) and ending at (5,0,2). Here the BoundBox thickness a copy of the given ellipse
  Part.Ellipse(S1,S2,Center)
  Creates an ellipse centered on the point Center, where the plane of the ellipse is defined by Center, S1 and S2, its major axis is defined by Center and S1, its major radius is the distance between Center and S1, and its minor radius is the distance between S2 and the major axis.
  Part.Ellipse(Center,MajorRadius,MinorRadius)
  Creates an ellipse with major and minor radii MajorRadius and MinorRadius, and located in the plane defined by Center and the normal (0,0,1)
  eli = Part.Ellipse(Base.Vector(10,0,0),Base.Vector(0,5,0),Base.Vector(0,0,0)) Part.show(eli.toShape())
  In the above code we have passed S1, S2 and center. the method cirlce radius 2)
  tor=Part.makeTorus(10,5,Base.Vector(0,0,0),Base.Vector(0,0,1),0,180)
  The above code will create a slice of the torus
  tor=Part.makeTorus(10,5,Base.Vector(0,0,0),Base.Vector(0,0,1),0,360,180)
  The above code will create a semi torus, only the last parameter is changed i.e the angle and remaining angles are defaults. Giving the angle 180 will create the torus from 0 to 180,, other are more complex, such as unioning and subtracting one shape from another. Be aware that differenty. 2 with edges
  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)) section = cylinder1.section(cylinder2) section.Wires > [] section.Edges > [<Edge object at 0D87CFE8>, <Edge object at 019564F8>, <Edge object at 0D998458>, <Edge object at 0D86DE18>, <Edge object at 0D9B8E80>, <Edge object at 012A3640>, <Edge object at 0D8F4BB0>].makeFace(wire) cylinder = disc.extrude(Base.Vector(0,0,2))
  Exploring shapes
  You can easily explore the topological data structure:
  import Part b = Part.makeBox(100,100,100) b.Wires w = b.Wires[0] w w.Wires w.Vertexes Part.show(w) w.Edges e = w.Edges[0] e.Vertexes v = e.Vertexes[0] v.Point
  By typing the lines above in the python interpreter, you will gain a good understanding of the structure of Part objects. Here, our makeBox() command created a solid shape. This solid, like all Part solids, contains faces. Faces always contain wires, which are lists of edges that border the face. Each face has.Length
  Now you can access a lot of properties of the edge by using the length as a position. That means if the edge is 100mm long the start position is 0 and the end position 100.
  anEdge.tangentAt(0.0) # tangent direction at the beginning anEdge.valueAt(0.0) # Point at the beginning anEdge.valueAt(100.0) # Point at the end of the edge anEdge.derivative1At(50.0) # first derivative of the curve in the middle anEdge.derivative2At(50.0) # second derivative of the curve in the middle anEdge.derivative3At(50.0) # third derivative of the curve in the middle anEdge.centerOfCurvatureAt(50) # center of the curvature for that position anEdge.curvatureAt(50.0) # the curvature anEdge.normalAt(50) # normal vector at that position (if defined)
  Using the selection
  Here we see now how we can use the selection the user did in the viewer. First of all we create a box and shows it in the viewer
  import Part Part.show(Part.makeBox(100,100,100)) Gui.SendMsgToActiveView("ViewFit")
  Select now some faces or edges. With this script you can iterate all selected objects and their sub elements:
  for o in Gui.Selection.getSelectionEx(): print o.ObjectName for s in o.SubElementNames: print "name: ",s for s in o.SubObjects: print "object: ",s
  Select some edges and this script will calculate the length:
  length = 0.0 for o in Gui.Selection.getSelectionEx(): for s in o.SubObjects: length += s.Length print "Length of the selected edges:" ,length
  Complete example: in FreeCAD installation (inside the Mod/Part folder) and can be called from the python interpreter by typing:
  import Part import MakeBottle bottle = MakeBottle.makeBottle() Part.show(bottle)
  The complete script
  Here is the complete MakeBottle script:
  import Part, FreeCAD, math from FreeCAD import Base) aArcOfCircle = Part.Arc(aPnt2,aPnt3,aPnt4) aSegment1=Part.Line(aPnt1,aPnt2) aSegment2=Part.Line(aPnt4,aPnt5) aEdge1=aSegment1.toShape() aEdge2=aArcOfCircle.toShape() aEdge3=aSegment2.toShape() aWire=Part.Wire([aEdge1,aEdge2,aEdge3]) aTrsf=Base.Matrix() aTrsf.rotateZ(math.pi) # rotate around the z-axis aMirroredWire=aWire.transformGeometry(aTrsf) myWireProfile=Part.Wire([aWire,aMirroredWire]) myFaceProfile=Part.Face(myWireProfile) aPrismVec=Base.Vector(0,0,myHeight) myBody=myFaceProfile.extrude(aPrismVec) myBody=myBody.makeFillet(myThickness/12.0,myBody.Edges) neckLocation=Base.Vector(0,0,myHeight) neckNormal=Base.Vector(0,0,1) myNeckRadius = myThickness / 4. myNeckHeight = myHeight / 10 myNeck = Part.makeCylinder(myNeckRadius,myNeckHeight,neckLocation,neckNormal) myBody = myBody.fuse(myNeck) faceToRemove = 0 zMax = -1.0 for xp in myBody.Faces: try: surf = xp.Surface if type(surf) == Part.Plane: z = surf.Position.z if z > zMax: zMax = z faceToRemove = xp except: continue myBody = myBody.)
  Here we define our makeBottle function. This function can be called without arguments, like we did above, in which case default values for width, height, and thickness will be used. Then, we define a couple of points that will be used for building our base profile.
  aArcOfCircle = Part.Arc(aPnt2,aPnt3,aPnt4) aSegment1=Part.Line(aPnt1,aPnt2) aSegment2=Part.Line(aPnt4,aPnt5)
  Here we actually define the geometry: an arc, made of 3 points, and two line segments, made of 2 points.
  aEdge1=aSegment1.toShape() aEdge2=aArcOfCircle.toShape() aEdge3=aSegment2.toShape() aWire=Part.Wire([aEdge1,aEdge2,aEdge3])
  Remember the difference between geometry and shapes? Here we build shapes out of our construction geometry. 3 we create a copy of our wire with that transformation matrix applied to it. We now have two wires, and we can make a third wire out of them, since wires are actually lists of edges.
  myFaceProfile=Part.Face(myWireProfile) aPrismVec=Base.Vector(0,0,myHeight) myBody=myFaceProfile.extrude(aPrismVec) myBody=myBody.makeFillet(myThickness/12.0,myBody.Edges)
  Now that we have a closed wire, it can be turned into a face. Once we have a face, we can extrude)
  There are several ways to save your work in the Part module. You can of course save your FreeCAD document, but you can also save Part objects directly to common CAD formats, such as BREP, IGS, STEP and STL.
  Saving a shape to a file is easy. There are exportBrep(), exportIges(), exportStl() and exportStep() methods, while exporting is with File -> Export
  