Topological data scripting/de: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
 
(334 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
{{TutorialInfo/de

|Topic=Programming
{{Docnav/de
|Level=Intermediate
|[[FreeCAD_Scripting_Basics/de|FreeCAD Grundlagen Skripten]]
|Time=
|[[Mesh_Scripting|Netz Skripten]]
|Author=
|FCVersion=
|Files=
}}
}}


{{TOCright}}


<span id="Introduction"></span>
This page describes several methods for creating and modifying [[Part Module|Part shapes]] from python. Before reading this page, if you are new to python, it is a good idea to read about [[Introduction to Python|python scripting]] and [[FreeCAD Scripting Basics|how python scripting works in FreeCAD]].
==Einleitung==


Hier wird erklärt, wie sich der Arbeitsbereich [[Part_Workbench/de|Part]] direkt aus dem FreeCAD-Python-Interpreter oder aus einem externen Skript heraus steuern lässt. Unter [[Scripting/de|Skripten]] und [[FreeCAD_Scripting_Basics/de|FreeCAD Grundlagen Skripten]] finden sich weitere Informationen über die Funktionsweise von Python-Skripten in FreeCAD. Für Python-Anfänger ist es eine gute Idee, zuerst die [[Introduction_to_Python/de|Einführung in Python]] zu lesen.
== Introduction ==
We will here explain you how to control the [[Part Module]] directly from the FreeCAD python interpreter, or from any external script. The basics about Topological data scripting are described in [[Part_Module#Explaining_the_concepts|Part Module Explaining the concepts]]. Be sure to browse the [[Scripting]] section and the [[FreeCAD Scripting Basics]] pages if you need more information about how python scripting works in FreeCAD.


<span id="See_also"></span>
=== Class Diagram ===
===Siehe auch===
This is a [http://en.wikipedia.org/wiki/Unified_Modeling_Language Unified Modeling Language (UML)] overview of the most important classes of the Part module:
[[Image:Part_Classes.jpg|center|Python classes of the Part module]]


* [[Part_scripting/de|Part Skripten]]
=== Geometry ===
* [[OpenCASCADE/de|OpenCASCADE]]
The geometric objects are the building block of all topological objects:
* '''Geom''' Base class of the geometric objects
* '''Line''' A straight line in 3D, defined by starting point and end point
* '''Circle''' Circle or circle segment defined by a center point and start and end point
* '''......''' And soon some more


<span id="Class_diagram"></span>
=== Topology ===
==Klassendiagramm==
The following topological data types are available:
* '''Compound''' A group of any type of topological object.
* '''Compsolid''' A composite solid is a set of solids connected by their faces. It expands the notions of WIRE and SHELL to solids.
* '''Solid''' A part of space limited by shells. It is three dimensional.
* '''Shell''' A set of faces connected by their edges. A shell can be open or closed.
* '''Face''' In 2D it is part of a plane; in 3D it is part of a surface. Its geometry is constrained (trimmed) by contours. It is two dimensional.
* '''Wire''' A set of edges connected by their vertices. It can be an open or closed contour depending on whether the edges are linked or not.
* '''Edge''' A topological element corresponding to a restrained curve. An edge is generally limited by vertices. It has one dimension.
* '''Vertex''' A topological element corresponding to a point. It has zero dimension.
* '''Shape''' A generic term covering all of the above.


Dies ist ein Überblick über die wesentlichen Klassen des Arbeitsbereichs Part in Form eines UML-Diagramms. Siehe [http://de.wikipedia.org/wiki/Unified_Modeling_Language Unified Modeling Language] :
=== Quick example : Creating simple topology ===
[[Image:Part_Classes.jpg|center|Python-Klassen des Arbeitsbereichs Part]]
{{Top}}
<span id="Geometry"></span>
===Geometrie===


Geometrische Objekte sind die Bausteine aller topologischen Objekte:
[[Image:Wire.png|right|Wire]]
* '''Geom''' Basisklasse der geometrischen Objekte
* '''Line''' Eine gerade Linie im Raum, definiert durch den Start- und Endpunkt
* '''Circle''' Kreis oder Kreissegment, definiert durch einen Mittelpunkt sowie Start- und Endpunkt
* Usw.
{{Top}}
<span id="Topology"></span>
===Topologie===


Die folgenden topologischen Datentypen stehen zur Verfügung:
We will now create a topology by constructing it out of simpler geometry.
* '''Compound''' Eine Gruppe von beliebigen topologischen Objekten.
As a case study we use a part as seen in the picture which consists of
* '''Compsolid''' Ein zusammengesetzter Körper (composite solid) ist ein Satz (eine Menge) von Körpern, die über ihre Flächen verbunden sind. Dies erweitert das Konzept von WIRE and SHELL auf (Fest-)Körper (solids).
four vertexes, two circles and two lines.
* '''Solid''' Ein Teil des (Konstruktion-)Raumes, der durch eine geschlossene Hülle begrenzt ist. Ein Solid (Festkörper) ist dreidimensional.
* '''Shell''' Hülle = Ein Satz (eine Menge) von über ihre Kanten verbundenen Flächen. Eine Hülle kann offen oder geschlossen sein.
* '''Face''' In 2D ist es ein Teil einer Ebene; in 3D ist es ein Teil einer Oberfläche (Trägerfläche). Die Form wird durch Konturen begrenzt (getrimmt). Ein Face (eine Fläche) ist zweidimensional (hat keine Wandstärke).
* '''Wire''' Ein Satz von über ihre Endpunkten verknüpften Kanten. Ein "Wire" kann eine offene oder geschlossene Form haben, je nach dem ob Start- und Endpunkt verbunden sind oder nicht.
* '''Edge''' Ein topologisches Element (Kante) das einer begrenzten Kurve entspricht. Eine Kante ist generell durch Knoten(-punkte) (Vertizes) begrenzt. Eine Kante (Edge) ist eindimensional (hat keine radiale Ausdehnung).
* '''Vertex''' Ein topologisches Element das einem (Knoten-)Punkt entspricht. Es ist nulldimensional.
* '''Shape''' (Form) ist der Oberbegriff für all die zuvor aufgezählten Elemente.
{{Top}}
<span id="Example:_Create_simple_topology"></span>
==Beispiel: Einfache Topologie erstellen==


[[Image:Wire.png|Wire]]
==== 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!


Wir werden nun eine Topologie erstellen, indem wir sie mit einfacheren Geometrien konstruieren.
So we create first the points:
Als Beispiel verwenden wir ein Teil, wie im Bild zu sehen, das aus
<syntaxhighlight>
vier Knoten, zwei Kreisen und zwei Linien besteht.
from FreeCAD import Base
{{Top}}
V1 = Base.Vector(0,10,0)
<span id="Create_geometry"></span>
V2 = Base.Vector(30,10,0)
===Geometrie erstellen===
V3 = Base.Vector(30,-10,0)
V4 = Base.Vector(0,-10,0)
</syntaxhighlight>
==== Arc ====


Zuerst erstellen wir die individuellen geometrischen Teile dieses Drahtes (Wire). Dabei stellen wir sicher, dass die Teile, die später verbunden werden, dieselben Knoten verwenden.
[[Image:Circel.png|right|Circle]]


Also erstellen wir zuerst die (Knoten-)Punkte (Vertices/Vertexes):
To create an arc of circle we make a helper point and create the arc of
circle through three points:
<syntaxhighlight>
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)
</syntaxhighlight>
==== Line ====


{{Code|code=
[[Image:Line.png|right|Line]]
import FreeCAD as App
import Part
V1 = App.Vector(0, 10, 0)
V2 = App.Vector(30, 10, 0)
V3 = App.Vector(30, -10, 0)
V4 = App.Vector(0, -10, 0)
}}
{{Top}}
<span id="Arc"></span>
===Bogen===


[[Image:Circel.png|Circle]]
The line can be created very simple out of the points:

<syntaxhighlight>

L1 = Part.Line(V1,V2)
Für jeden Bogen benötigen wir einen Hilfspunkt:
# and the second one

L2 = Part.Line(V4,V3)
{{Code|code=
</syntaxhighlight>
VC1 = App.Vector(-10, 0, 0)
==== Putting all together ====
C1 = Part.Arc(V1, VC1, V4)
The last step is to put the geometric base elements together
VC2 = App.Vector(40, 0, 0)
and bake a topological shape:
C2 = Part.Arc(V2, VC2, V3)
<syntaxhighlight>
}}
S1 = Part.Shape([C1,C2,L1,L2])
{{Top}}
</syntaxhighlight>
<span id="Line"></span>
==== Make a prism ====
===Linie===
Now extrude the wire in a direction and make an actual 3D shape:

<syntaxhighlight>
[[Image:Line.png|Line]]


Die Linienabschnitte können aus zwei Punkten erstellt werden:

{{Code|code=
L1 = Part.LineSegment(V1, V2)
L2 = Part.LineSegment(V3, V4)
}}
{{Top}}
<span id="Put_it_all_together"></span>
===Alles zusammensetzen===

Der letzte Schritt besteht darin, die geometrischen Basiselemente zusammenzusetzen und zu einer topologischen Form (Shape) zu vereinigen:

{{Code|code=
S1 = Part.Shape([C1, L1, C2, L2])
}}
{{Top}}
<span id="Make_a_prism"></span>
===Ein prismatisches Objekt erstellen===

Jetzt wird der Draht in eine Richtung extrudiert und so eine wirkliche 3D-Form erstellt:

{{Code|code=
W = Part.Wire(S1.Edges)
W = Part.Wire(S1.Edges)
P = W.extrude(Base.Vector(0,0,10))
P = W.extrude(App.Vector(0, 0, 10))
}}
</syntaxhighlight>
{{Top}}
==== Show it all ====
<span id="Show_it_all"></span>
<syntaxhighlight>
===Alles anzeigen===

{{Code|code=
Part.show(P)
Part.show(P)
}}
</syntaxhighlight>
{{Top}}
== Creating basic shapes ==
<span id="Create_basic_shapes"></span>
You can easily create basic topological objects with the "make...()"
==Grundformen erstellen==
methods from the Part Module:

<syntaxhighlight>
Topologische Grundobjekte können ganz einfach mit den Methoden {{incode|make...()}} aus dem Arbeitsbereich Part erstellen:
b = Part.makeBox(100,100,100)

{{Code|code=
b = Part.makeBox(100, 100, 100)
Part.show(b)
Part.show(b)
}}
</syntaxhighlight>
A couple of other make...() methods available:
* '''makeBox(l,w,h)''': Makes a box located in p and pointing into the direction d with the dimensions (l,w,h)
* '''makeCircle(radius)''': Makes a circle with a given radius
* '''makeCone(radius1,radius2,height)''': Makes a cone with a given radii and height
* '''makeCylinder(radius,height)''': Makes a cylinder with a given radius and height.
* '''makeLine((x1,y1,z1),(x2,y2,z2))''': Makes a line of two points
* '''makePlane(length,width)''': Makes a plane with length and width
* '''makePolygon(list)''': Makes a polygon of a list of points
* '''makeSphere(radius)''': Make a sphere with a given radius
* '''makeTorus(radius1,radius2)''': Makes a torus with a given radii
See the [[Part API]] page for a complete list of available methods of the Part module.


Einige verfügbare {{incode|make...()}} Methoden:
==== Importing the needed modules ====
* {{incode|makeBox(l, w, h, [p, d])}} Erstellt einen Quader, der sich in p befindet und in die Richtung d zeigt, mit den Abmessungen (l,w,h).
First we need to import the Part module so we can use its contents in python.
* {{incode|makeCircle(radius)}} Erstellt einen Kreis mit einem gegebenen Radius.
We'll also import the Base module from inside the FreeCAD module:
* {{incode|makeCone(radius1, radius2, height)}} Erstellt einen Kegel mit den gegebenen Radien und der Höhe.
<syntaxhighlight>
* {{incode|makeCylinder(radius, height)}} Erstellt einen Zylinder mit gegebenen Radius und Höhe.
* {{incode|makeLine((x1, y1, z1), (x2, y2, z2))}} Erstellt eine Linie aus zwei Punkten.
* {{incode|makePlane(length, width)}} Erstellt eine Ebene mit Länge und Breite.
* {{incode|makePolygon(list)}} Erstellt ein Polygon aus einer Liste von Punkten.
* {{incode|makeSphere(radius)}} Erstellt eine Kugel mit einem bestimmten Radius.
* {{incode|makeTorus(radius1, radius2)}} Erstellt einen Torus mit den gegebenen Radien.
Siehe die Seite [[Part_API/de|Part API]] oder diese [https://freecad-python-stubs.readthedocs.io/en/latest/autoapi/Part/ autogenerated Python Part API documentation] für eine vollständige Liste der verfügbaren Methoden des Arbeitsbereichs Part.
{{Top}}
<span id="Import_modules"></span>
===Module Importieren===

Zuerst müssen wir das FreeCAD-Modul und den Arbeitsbereich Part importieren, damit wir ihre Inhalte in Python verwenden können:

{{Code|code=
import FreeCAD as App
import Part
import Part
}}
from FreeCAD import Base
{{Top}}
</syntaxhighlight>
<span id="Create_a_vector"></span>
==== Creating a Vector ====
===Einen Vektor erstellen===
[http://en.wikipedia.org/wiki/Euclidean_vector Vectors] are one of the most

important pieces of information when building shapes. They contain a 3 numbers
[https://de.wikipedia.org/wiki/Vektor#Geometrie Vektoren] gehören zu den wichtigsten Informationsbestandteilen beim Erstellen von Formen. Sie enthalten in der Regel (aber nicht zwangsläufig immer) drei Zahlen, die kartesischen Koordinaten x, y und z. Und so wird ein Vektor erstellt:
usually (but not necessarily always) the x, y and z cartesian coordinates. You

create a vector like this:
{{Code|code=
<syntaxhighlight>
myVector = Base.Vector(3,2,0)
myVector = App.Vector(3, 2, 0)
}}
</syntaxhighlight>

We just created a vector at coordinates x=3, y=2, z=0. In the Part module,
Wir haben soeben einen Vektor mit den Koordinaten x = 3, y = 2, z = 0 erstellt. Im Arbeitsbereich Part werden Vektoren überall verwendet. Part-Formen verwenden auch eine andere Art von Punktdarstellung namens Knoten (Vertex), die einfach ein Behälter für einen Vektor ist. So greift man auf den Vektor eines Knoten zu:
vectors are used everywhere. Part shapes also use another kind of point

representation, called Vertex, which is acually nothing else than a container
{{Code|code=
for a vector. You access the vector of a vertex like this:
<syntaxhighlight>
myVertex = myShape.Vertexes[0]
myVertex = myShape.Vertexes[0]
print myVertex.Point
print(myVertex.Point)
> Vector (3, 2, 0)
> Vector (3, 2, 0)
}}
</syntaxhighlight>
{{Top}}
==== Creating an Edge ====
<span id="Create_an_edge"></span>
An edge is nothing but a line with two vertexes:
===Eine Kante erstellen===
<syntaxhighlight>

edge = Part.makeLine((0,0,0), (10,0,0))
Eine Kante ist nichts anderes als eine Linie mit zwei Knoten:

{{Code|code=
edge = Part.makeLine((0, 0, 0), (10, 0, 0))
edge.Vertexes
edge.Vertexes
> [<Vertex object at 01877430>, <Vertex object at 014888E0>]
> [<Vertex object at 01877430>, <Vertex object at 014888E0>]
}}
</syntaxhighlight>

Note: You can also create an edge by passing two vectors:
Hinweis: Eine Kante kann auch durch Übergabe von zwei Vektoren erstellt werden:
<syntaxhighlight>

vec1 = Base.Vector(0,0,0)
{{Code|code=
vec2 = Base.Vector(10,0,0)
line = Part.Line(vec1,vec2)
vec1 = App.Vector(0, 0, 0)
vec2 = App.Vector(10, 0, 0)
line = Part.LineSegment(vec1, vec2)
edge = line.toShape()
edge = line.toShape()
}}
</syntaxhighlight>

You can find the length and center of an edge like this:
So findet man die Länge und den Mittelpunkt einer Kante:
<syntaxhighlight>

{{Code|code=
edge.Length
edge.Length
> 10.0
> 10.0
edge.CenterOfMass
edge.CenterOfMass
> Vector (5, 0, 0)
> Vector (5, 0, 0)
}}
</syntaxhighlight>
{{Top}}
==== Putting the shape on screen ====
<span id="Put_the_shape_on_screen"></span>
So far we created an edge object, but it doesn't appear anywhere on screen.
===Die Form auf den Bildschirm bringen===
This is because we just manipulated python objects here. The FreeCAD 3D scene

only displays what you tell it to display. To do that, we use this simple
Bisher haben wir ein Kantenobjekt erstellt, das aber nirgendwo auf dem Bildschirm erscheint. Das liegt daran, dass die FreeCAD-3D-Szene nur etwas anzeigt, wenn man ihr sagt, dass sie es anzeigen soll. Um das zu tun, verwenden wir folgende einfache Methode:
method:

<syntaxhighlight>
{{Code|code=
Part.show(edge)
Part.show(edge)
}}
</syntaxhighlight>

An object will be created in our FreeCAD document, and our "edge" shape
Die Anzeigefunktion (.show) erzeugt ein Objekt in unserem FreeCAD-Dokument und weist ihm unsere Form "edge" zu. Sie wird verwendet, wenn es an der Zeit ist, das Erstellte auf dem Bildschirm anzuzeigen.
will be attributed to it. Use this whenever it's time to display your
{{Top}}
creation on screen.
<span id="Create_a_wire"></span>
===Einen Draht erstellen===

Ein Draht (Wire) ist eine Linie aus mehreren Kanten und kann aus einer Liste von Kanten oder sogar einer Liste von Drähten erstellt werden:


{{Code|code=
==== Creating a Wire ====
edge1 = Part.makeLine((0, 0, 0), (10, 0, 0))
A wire is a multi-edge line and can be created from a list of edges
edge2 = Part.makeLine((10, 0, 0), (10, 10, 0))
or even a list of wires:
wire1 = Part.Wire([edge1, edge2])
<syntaxhighlight>
edge1 = Part.makeLine((0,0,0), (10,0,0))
edge3 = Part.makeLine((10, 10, 0), (0, 10, 0))
edge2 = Part.makeLine((10,0,0), (10,10,0))
edge4 = Part.makeLine((0, 10, 0), (0, 0, 0))
wire1 = Part.Wire([edge1,edge2])
wire2 = Part.Wire([edge3, edge4])
edge3 = Part.makeLine((10,10,0), (0,10,0))
wire3 = Part.Wire([wire1, wire2])
edge4 = Part.makeLine((0,10,0), (0,0,0))
wire2 = Part.Wire([edge3,edge4])
wire3 = Part.Wire([wire1,wire2])
wire3.Edges
wire3.Edges
> [<Edge object at 016695F8>, <Edge object at 0197AED8>, <Edge object at 01828B20>, <Edge object at 0190A788>]
> [<Edge object at 016695F8>, <Edge object at 0197AED8>, <Edge object at 01828B20>, <Edge object at 0190A788>]
Part.show(wire3)
Part.show(wire3)
}}
</syntaxhighlight>

Part.show(wire3) will display the 4 edges that compose our wire. Other
{{incode|Part.show(wire3)}} zeigt die 4 Kanten, die unseren Draht bilden (in der 3D-Ansicht) an. Weitere nützliche Informationen können leicht abgerufen werden:
useful information can be easily retrieved:

<syntaxhighlight>
{{Code|code=
wire3.Length
wire3.Length
> 40.0
> 40.0
Line 200: Line 245:
wire2.isClosed()
wire2.isClosed()
> False
> False
}}
</syntaxhighlight>
{{Top}}
==== Creating a Face ====
<span id="Create_a_face"></span>
Only faces created from closed wires will be valid. In this example, wire3
===Eine Fläche erstellen===
is a closed wire but wire2 is not a closed wire (see above)

<syntaxhighlight>
Nur Flächen (Faces), die aus geschlossenen Drähten erstellt wurden, sind gültig. In diesem Beispiel ist wire3 ein geschlossener Draht, aber wire2 ist kein geschlossener Draht (siehe oben).

{{Code|code=
face = Part.Face(wire3)
face = Part.Face(wire3)
face.Area
face.Area
> 99.999999999999972
> 99.99999999999999
face.CenterOfMass
face.CenterOfMass
> Vector (5, 5, 0)
> Vector (5, 5, 0)
Line 215: Line 263:
> True
> True
sface = Part.Face(wire2)
sface = Part.Face(wire2)
face.isValid()
sface.isValid()
> False
> False
}}
</syntaxhighlight>

Only faces will have an area, not wires nor edges.
Nur Flächen haben einen Flächeninhalt (area), Drähte und Kanten haben keinen.
{{Top}}
<span id="Create_a_circle"></span>
===Einen Kreis erstellen===

So kann ein Kreis erstellt werden:


{{Code|code=
==== Creating a Circle ====
A circle can be created as simply as this:
<syntaxhighlight>
circle = Part.makeCircle(10)
circle = Part.makeCircle(10)
circle.Curve
circle.Curve
> Circle (Radius : 10, Position : (0, 0, 0), Direction : (0, 0, 1))
> Circle (Radius : 10, Position : (0, 0, 0), Direction : (0, 0, 1))
}}
</syntaxhighlight>

If you want to create it at certain position and with certain direction:
Wenn er an einer bestimmten Stelle und mit einer bestimmten Ausrichtung erstellt werden soll:
<syntaxhighlight>

ccircle = Part.makeCircle(10, Base.Vector(10,0,0), Base.Vector(1,0,0))
{{Code|code=
ccircle = Part.makeCircle(10, App.Vector(10, 0, 0), App.Vector(1, 0, 0))
ccircle.Curve
ccircle.Curve
> Circle (Radius : 10, Position : (10, 0, 0), Direction : (1, 0, 0))
> Circle (Radius : 10, Position : (10, 0, 0), Direction : (1, 0, 0))
}}
</syntaxhighlight>

ccircle will be created at distance 10 from origin on x and will be facing
ccircle wird mit dem Abstand 10 vom X-Ursprung erstellt und ist nach außen entlang der X-Achse ausgerichtet. Hinweis: {{incode|makeCircle()}} akzeptiert nur einen {{incode|App.Vector()}} für die Position und normale Parameter, keine Tupel. Du kannst auch einen Teil des Kreises durch Angabe eines Anfangs- und eines Endwinkels erstellen:
towards x axis. Note: makeCircle only accepts Base.Vector() for position

and normal but not tuples. You can also create part of the circle by giving
{{Code|code=
start angle and end angle as:
<syntaxhighlight>
from math import pi
from math import pi
arc1 = Part.makeCircle(10, Base.Vector(0,0,0), Base.Vector(0,0,1), 0, 180)
arc1 = Part.makeCircle(10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 180)
arc2 = Part.makeCircle(10, Base.Vector(0,0,0), Base.Vector(0,0,1), 180, 360)
arc2 = Part.makeCircle(10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 180, 360)
}}
</syntaxhighlight>

Both arc1 and arc2 jointly will make a circle. Angles should be provided in
Winkel sollten in Grad angegeben werden. Liegt ein Wert in Bogenmaß vor, wird er einfach mit folgender Formel umgewandelt:
degrees, if you have radians simply convert them using formula:
{{incode|Grad <nowiki>=</nowiki> Bogenmaß * 180/pi}} oder mit Hilfe des Python-Moduls {{incode|math}}:
degrees = radians * 180/PI or using python's math module (after doing import

math, of course):
{{Code|code=
<syntaxhighlight>
import math
degrees = math.degrees(radians)
degrees = math.degrees(radians)
}}
</syntaxhighlight>
{{Top}}
==== Creating an Arc along points ====
<span id="Create_an_arc_along_points"></span>
Unfortunately there is no makeArc function but we have Part.Arc function to
===Einen Bogen über Punkte erstellen===
create an arc along three points. Basically it can be supposed as an arc

joining start point and end point along the middle point. Part.Arc creates
Leider gibt es keine Funktion {{incode|makeArc()}}, aber wir haben die Funktion {{incode|Part.Arc()}} um einen Bogen (Arc) durch drei Punkte zu erzeugen. Sie erzeugt ein Arc-Objekt, das den Startpunktes mit dem Endpunkt über den Mittelpunkt verbindet. Die Funktion {{incode|toShape()}} des Arc-Objekts muss aufgerufen werden, um ein Edge-Objekt zu erhalten, wie bei der Verwendung von {{incode|Part.LineSegment}} anstelle von {{incode|Part.makeLine}}.
an arc object on which .toShape() has to be called to get the edge object,

the same way as when using Part.Line instead of Part.makeLine.
{{Code|code=
<syntaxhighlight>
arc = Part.Arc(Base.Vector(0,0,0),Base.Vector(0,5,0),Base.Vector(5,5,0))
arc = Part.Arc(App.Vector(0, 0, 0), App.Vector(0, 5, 0), App.Vector(5, 5, 0))
arc
arc
> <Arc object>
> <Arc object>
arc_edge = arc.toShape()
arc_edge = arc.toShape()
Part.show(arc_edge)
</syntaxhighlight>
}}
Arc only accepts Base.Vector() for points but not tuples. arc_edge is what

we want which we can display using Part.show(arc_edge). You can also obtain
{{incode|Arc()}} akzeptiert nur {{incode|App.Vector()}} für Punkte, aber keine Tupel. Einen Bogen kann man auch durch Verwendung eines Kreisabschnitts erhalten:
an arc by using a portion of a circle:

<syntaxhighlight>
{{Code|code=
from math import pi
from math import pi
circle = Part.Circle(Base.Vector(0,0,0),Base.Vector(0,0,1),10)
circle = Part.Circle(App.Vector(0, 0, 0), App.Vector(0, 0, 1), 10)
arc = Part.Arc(c,0,pi)
arc = Part.Arc(circle,0,pi)
}}
</syntaxhighlight>

Arcs are valid edges, like lines. So they can be used in wires too.
Bögen sind gültige Kanten wie Linien, so dass sie auch in Drähten verwendet werden können.
{{Top}}
<span id="Create_a_polygon"></span>
===Ein Vieleck erstellen===

Ein Vieleck (Polygon) ist einfach ein Draht mit mehreren geraden Kanten. Die Funktion {{incode|makePolygon()}} nimmt eine Liste von Punkten entgegen und erstellt einen Draht durch diese Punkte:

{{Code|code=
lshape_wire = Part.makePolygon([App.Vector(0, 5, 0), App.Vector(0, 0, 0), App.Vector(5, 0, 0)])
}}
{{Top}}
<span id="Create_a_Bézier_curve"></span>
===Eine Bézier-Kurve erstellen===

Bézier-Kurven werden verwendet, um weiche Kurven mit einer Reihe von Polen (Punkten) und optionalen Gewichten zu modellieren. Die folgende Funktion erstellt eine {{incode|Part.BezierCurve()}} aus einer Reihe von {{incode|FreeCAD.Vector()}} Punkten. (Hinweis: Soll ein einzelner Pol oder ein Gewicht mit "get" und "set" (-Methoden und Indizes) angesprochen werden, beginnen die Indizes bei 1, nicht bei 0.)


{{Code|code=
==== 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:
<syntaxhighlight>
lshape_wire = Part.makePolygon([Base.Vector(0,5,0),Base.Vector(0,0,0),Base.Vector(5,0,0)])
</syntaxhighlight>
==== Creating a Bezier curve ====
Bézier curves are used to model smooth curves using a series of poles (points) and optional weights. The function below makes a Part.BezierCurve from a series of FreeCAD.Vector points. (Note: when "getting" and "setting" a single pole or weight indices start at 1, not 0.)
<syntaxhighlight>
def makeBCurveEdge(Points):
def makeBCurveEdge(Points):
geomCurve = Part.BezierCurve()
geomCurve = Part.BezierCurve()
Line 285: Line 347:
edge = Part.Edge(geomCurve)
edge = Part.Edge(geomCurve)
return(edge)
return(edge)
}}
</syntaxhighlight>
{{Top}}
==== Creating a Plane ====
<span id="Create_a_plane"></span>
A Plane is simply a flat rectangular surface. The method used to create one is
===Eine Ebene erstellen===
this: '''makePlane(length,width,[start_pnt,dir_normal])'''. By default

start_pnt = Vector(0,0,0) and dir_normal = Vector(0,0,1). Using dir_normal = Vector(0,0,1)
Eine Ebene (Plane) ist eine ebene rechteckige Fläche. Die Methode, mit der eine Ebene erstellt wird, ist {{incode|makePlane(length, width, [start_pnt, dir_normal])}}. Standardmäßig sind start_pnt = Vektor(0, 0, 0) und dir_normal = Vektor(0, 0, 1). Ist dir_normal = Vector(0, 0, 1) wird eine Ebene, die in Richtung der positiven Z-Achse zeigt, erstellt, während dir_normal = Vector(1, 0, 0) eine Ebene erzeugt, die in Richtung der positiven X-Achse zeigt:
will create the plane facing z axis, while dir_normal = Vector(1,0,0) will create the

plane facing x axis:
{{Code|code=
<syntaxhighlight>
plane = Part.makePlane(2,2)
plane = Part.makePlane(2, 2)
plane
plane
><Face object at 028AF990>
> <Face object at 028AF990>
plane = Part.makePlane(2,2, Base.Vector(3,0,0), Base.Vector(0,1,0))
plane = Part.makePlane(2, 2, App.Vector(3, 0, 0), App.Vector(0, 1, 0))
plane.BoundBox
plane.BoundBox
> BoundBox (3, 0, 0, 5, 0, 2)
> BoundBox (3, 0, 0, 5, 0, 2)
}}
</syntaxhighlight>
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 in y axis is zero,
since our shape is totally flat.


{{incode|BoundBox}} ist ein Quader, der die Ebene einschließt, mit einer Diagonale, die bei (3, 0, 0) beginnt und bei (5, 0, 2) endet. Hier ist die Ausdehnung der {{incode|BoundBox}} entlang der Y-Achse Null, da unsere Form völlig eben ist.
Note: makePlane only accepts Base.Vector() for start_pnt and dir_normal but not tuples


Hinweis: {{incode|makePlane()}} akzeptiert nur {{incode|App.Vector()}} für start_pnt und dir_normal, nicht aber Tupel.
==== Creating an ellipse ====
{{Top}}
To create an ellipse there are several ways:
<span id="Create_an_ellipse"></span>
<syntaxhighlight>
===Eine Ellipse erstellen===

Es gibt mehrere Möglichkeiten, eine Ellipse zu erstellen:

{{Code|code=
Part.Ellipse()
Part.Ellipse()
}}
</syntaxhighlight>

Creates an ellipse with major radius 2 and minor radius 1 with the center in (0,0,0)
Erzeugt eine Ellipse mit Hauptradius 2 und Nebenradius 1 mit dem Mittelpunkt bei (0,0,0).
<syntaxhighlight>

{{Code|code=
Part.Ellipse(Ellipse)
Part.Ellipse(Ellipse)
}}
</syntaxhighlight>

Create a copy of the given ellipse
Erstellt eine Kopie der angegebenen Ellipse.
<syntaxhighlight>

Part.Ellipse(S1,S2,Center)
{{Code|code=
</syntaxhighlight>
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,
Erzeugt eine Ellipse, die auf den Punkt Mitte zentriert ist, an dem die Ebene der Ellipse definiert ist durch Mittelpunkt, S1 und S2, ihre Hauptachse definiert ist durch Mittelpunkt und S1, sein Hauptradius ist der Abstand zwischen Mittelpunkt und S1, und sein kleiner Radius ist der Abstand zwischen S2 und der Hauptachse.
and its minor radius is the distance between S2 and the major axis.

<syntaxhighlight>
{{Code|code=
Part.Ellipse(Center,MajorRadius,MinorRadius)
Part.Ellipse(Center, MajorRadius, MinorRadius)
</syntaxhighlight>
}}
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)
Erstellt eine Ellipse mit Haupt- und Nebenradien Hauptradius und Nebenradius,
<syntaxhighlight>
die sich in der durch den Mittelpunkt definierten Ebene und der Normalen (0,0,1) befinden.
eli = Part.Ellipse(Base.Vector(10,0,0),Base.Vector(0,5,0),Base.Vector(0,0,0))

{{Code|code=
eli = Part.Ellipse(App.Vector(10, 0, 0), App.Vector(0, 5, 0), App.Vector(0, 0, 0))
Part.show(eli.toShape())
Part.show(eli.toShape())
}}
</syntaxhighlight>

In the above code we have passed S1, S2 and center. Similarly to Arc,
Im obigen Code haben wir S1, S2 und Mitte überschritten. Ähnlich wie {{incode|Arc}},
Ellipse also creates an ellipse object but not edge, so we need to
{{incode|Ellipse}} erzeugt ein Ellipsenobjekt, aber keine Kante, also müssen wir es in eine Kante mit {{incode|toShape()}} zur Anzeige konvertieren.
convert it into edge using toShape() to display.

Hinweis: {{incode|Ellipse()}} akzeptiert nur {{incode|App.Vector()}} für Punkte, nicht aber für Tupel.


{{Code|code=
Note: Arc only accepts Base.Vector() for points but not tuples
eli = Part.Ellipse(App.Vector(0, 0, 0), 10, 5)
<syntaxhighlight>
eli = Part.Ellipse(Base.Vector(0,0,0),10,5)
Part.show(eli.toShape())
Part.show(eli.toShape())
}}
</syntaxhighlight>

for the above Ellipse constructor we have passed center, MajorRadius and MinorRadius
Für den obigen Ellipsenkonstruktor haben wir Mitte, HauptRadius und NebenRadius überschritten.
{{Top}}
<span id="Create_a_torus"></span>
===Erstellen eines Torus===

Verwende {{incode|makeTorus(radius1, radius2, [pnt, dir, Winkel1, Winkel2, Winkel])}}.
Standardmäßig ist pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1), Winkel1 = 0, Winkel2 = 360 und Winkel = 360.
Betrachte einen Torus als kleinen Kreis, der entlang eines großen Kreises verläuft. Radius1 ist der
Radius des großen Kreises, Radius2 ist der Radius des kleinen Kreises, pnt ist der Mittelpunkt
des Torus und dir ist die Normalenrichtung. winkel1 und winkel2 sind Winkel in
Grad für den kleinen Kreis; der letzte Winkelparameter besteht darin, einen Schnitt von
den Torus:


{{Code|code=
==== Creating a Torus ====
Using the method '''makeTorus(radius1,radius2,[pnt,dir,angle1,angle2,angle])'''. By
default pnt=Vector(0,0,0),dir=Vector(0,0,1),angle1=0,angle2=360 and angle=360.
Consider a torus as small circle sweeping along a big circle. Radius1 is the
radius of big cirlce, radius2 is the radius of small circle, pnt is the center
of torus and dir is the normal direction. angle1 and angle2 are angles in
radians for the small circle, the last parameter angle is to make a section of
the torus:
<syntaxhighlight>
torus = Part.makeTorus(10, 2)
torus = Part.makeTorus(10, 2)
}}
</syntaxhighlight>

The above code will create a torus with diameter 20(radius 10) and thickness 4
Der obige Code erzeugt einen Torus mit Durchmesser 20 (Radius 10) und Dicke 4
(small cirlce radius 2)
(kleiner Kreisradius 2)
<syntaxhighlight>

tor=Part.makeTorus(10,5,Base.Vector(0,0,0),Base.Vector(0,0,1),0,180)
{{Code|code=
</syntaxhighlight>
tor=Part.makeTorus(10, 5, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 180)
The above code will create a slice of the torus
}}
<syntaxhighlight>

tor=Part.makeTorus(10,5,Base.Vector(0,0,0),Base.Vector(0,0,1),0,360,180)
Der obige Code erzeugt eine Scheibe des Torus.
</syntaxhighlight>

The above code will create a semi torus, only the last parameter is changed
{{Code|code=
i.e the angle and remaining angles are defaults. Giving the angle 180 will
tor=Part.makeTorus(10, 5, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 360, 180)
create the torus from 0 to 180, that is, a half torus.
}}

Der obige Code erzeugt einen Halbtorus; nur der letzte Parameter wird geändert.
d.h. die restlichen Winkel sind Standardwerte. Die Angabe des Winkels 180 bewirkt
den Torus von 0 bis 180, d.h. einen halben Torus, erzeugen.
{{Top}}
<span id="Create_a_box_or_cuboid"></span>
===Kasten oder Quader erstellen===

Verwendung von {{incode|makeBox(Länge, Breite, Höhe, [pnt, dir])}}.
Standardmäßig werden pnt = Vektor(0, 0, 0) und dir = Vektor(0, 0, 1) verwendet.


{{Code|code=
==== Creating a box or cuboid ====
Using '''makeBox(length,width,height,[pnt,dir])'''.
box = Part.makeBox(10, 10, 10)
By default pnt=Vector(0,0,0) and dir=Vector(0,0,1)
<syntaxhighlight>
box = Part.makeBox(10,10,10)
len(box.Vertexes)
len(box.Vertexes)
> 8
> 8
}}
</syntaxhighlight>
{{Top}}
==== Creating a Sphere ====
<span id="Create_a_sphere"></span>
Using '''makeSphere(radius,[pnt, dir, angle1,angle2,angle3])'''. By default
===Erstelle eine Kugel===
pnt=Vector(0,0,0), dir=Vector(0,0,1), angle1=-90, angle2=90 and angle3=360.

angle1 and angle2 are the vertical minimum and maximum of the sphere, angle3
Mit {{incode|makeSphere(radius, [pnt, dir, winkel1, winkel2, winkel3])}}. Standardmäßig
is the sphere diameter itself.
pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1), Winkel1 = -90, Winkel2 = 90 und Winkel3 = 360. Winkel1 und Winkel2 sind das vertikale Minimum und Maximum der Kugel, Winkel3 ist der Kugeldurchmesser.
<syntaxhighlight>

{{Code|code=
sphere = Part.makeSphere(10)
sphere = Part.makeSphere(10)
hemisphere = Part.makeSphere(10,Base.Vector(0,0,0),Base.Vector(0,0,1),-90,90,180)
hemisphere = Part.makeSphere(10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), -90, 90, 180)
}}
</syntaxhighlight>
{{Top}}
==== Creating a Cylinder ====
<span id="Create_a_cylinder"></span>
Using '''makeCylinder(radius,height,[pnt,dir,angle])'''. By default
===Erstellen eines Zylinders===
pnt=Vector(0,0,0),dir=Vector(0,0,1) and angle=360
<syntaxhighlight>
cylinder = Part.makeCylinder(5,20)
partCylinder = Part.makeCylinder(5,20,Base.Vector(20,0,0),Base.Vector(0,0,1),180)
</syntaxhighlight>
==== Creating a Cone ====
Using '''makeCone(radius1,radius2,height,[pnt,dir,angle])'''. By default
pnt=Vector(0,0,0), dir=Vector(0,0,1) and angle=360
<syntaxhighlight>
cone = Part.makeCone(10,0,20)
semicone = Part.makeCone(10,0,20,Base.Vector(20,0,0),Base.Vector(0,0,1),180)
</syntaxhighlight>
== Modifying shapes ==
There are several ways to modify shapes. Some are simple transformation operations
such as moving or rotating shapes, other are more complex, such as unioning and
subtracting one shape from another. Be aware that


Verwende {{incode|makeCylinder(Radius, Höhe, [pnt, dir, Winkel])}}. Standardmäßig
=== Transform operations ===
pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1) und Winkel = 360.


{{Code|code=
==== Translating a shape ====
cylinder = Part.makeCylinder(5, 20)
Translating is the act of moving a shape from one place to another.
partCylinder = Part.makeCylinder(5, 20, App.Vector(20, 0, 0), App.Vector(0, 0, 1), 180)
Any shape (edge, face, cube, etc...) can be translated the same way:
}}
<syntaxhighlight>
{{Top}}
myShape = Part.makeBox(2,2,2)
<span id="Create_a_cone"></span>
myShape.translate(Base.Vector(2,0,0))
===Erstellen eines Kegels===
</syntaxhighlight>

This will move our shape "myShape" 2 units in the x direction.
Verwendung {{incode|makeCone(radius1, radius2, höhe, [pnt, dir, winkel])}}. Standardmäßig
pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1) und Winkel = 360.

{{Code|code=
cone = Part.makeCone(10, 0, 20)
semicone = Part.makeCone(10, 0, 20, App.Vector(20, 0, 0), App.Vector(0, 0, 1), 180)
}}
{{Top}}
<span id="Modify_shapes"></span>
==Formen ändern==

Es gibt verschiedene Möglichkeiten, Formen zu ändern. Einige sind einfache Transformationsoperationen wie das Verschieben oder Drehen von Formen, andere sind komplexer, wie die Vereinigung und die Differenz, das
Subtrahieren einer Form von einer anderen.
{{Top}}
<span id="Transform_operations"></span>
==Transformationsvorgänge==

<span id="Translate_a_shape"></span>
===Verschieben einer Form===

Verschieben ist das Bewegen einer Form von einem Ort zum anderen. Jede Form (Kante, Fläche, Würfel, usw...) kann auf die gleiche Weise verschoben werden:

{{Code|code=
myShape = Part.makeBox(2, 2, 2)
myShape.translate(App.Vector(2, 0, 0))
}}

Dadurch wird die Form "myShape" um 2 Einheiten in X-Richtung verschoben.
{{Top}}
<span id="Rotate_a_shape"></span>
===Drehen einer Form===

Um eine Form zu drehen, muss ein Drehpunkt (auf der Achse), die (Ausrichtung der) Achse und der Drehwinkel angegeben werden:

{{Code|code=
myShape.rotate(App.Vector(0, 0, 0),App.Vector(0, 0, 1), 180)
}}

Der obige Code dreht die Form um 180° um die Z-Achse.
{{Top}}
<span id="Matrix_transformations"></span>
===Matrix-Transformationen===


Eine Matrix ist eine sehr bequeme Möglichkeit, in der 3D Welt Transformationen zu speichern. In einer einzigen Matrix können Werte für das Verschieben, Drehen und Skalieren festgelegt werden, die auf ein Objekt angewendet werden sollen. Zum Beispiel:
==== Rotating a shape ====
To rotate a shape, you need to specify the rotation center, the axis,
and the rotation angle:
<syntaxhighlight>
myShape.rotate(Vector(0,0,0),Vector(0,0,1),180)
</syntaxhighlight>
The above code will rotate the shape 180 degrees around the Z Axis.


{{Code|code=
==== Generic transformations with matrixes ====
myMat = App.Matrix()
A matrix is a very convenient way to store transformations in the 3D
myMat.move(App.Vector(2, 0, 0))
world. In a single matrix, you can set translation, rotation and scaling
values to be applied to an object. For example:
<syntaxhighlight>
myMat = Base.Matrix()
myMat.move(Base.Vector(2,0,0))
myMat.rotateZ(math.pi/2)
myMat.rotateZ(math.pi/2)
}}
</syntaxhighlight>

Note: FreeCAD matrixes work in radians. Also, almost all matrix operations
Hinweis: FreeCAD-Matrizen arbeiten mit Bogenmaß. Außerdem können fast alle Matrix-Operationen die einen Vektor akzeptieren, auch drei Zahlen akzeptieren, so dass diese beiden Zeilen dasselbe tun:
that take a vector can also take 3 numbers, so those 2 lines do the same thing:

<syntaxhighlight>
{{Code|code=
myMat.move(2,0,0)
myMat.move(Base.Vector(2,0,0))
myMat.move(2, 0, 0)
myMat.move(App.Vector(2, 0, 0))
</syntaxhighlight>
}}
When our matrix is set, we can apply it to our shape. FreeCAD provides 2

methods to do that: transformShape() and transformGeometry(). The difference
Wenn unsere Matrix einmal festgelegt ist, können wir sie auf unsere Form anwenden. FreeCAD bietet zwei Methoden, um das zu tun: {{incode|transformShape()}} und {{incode|transformGeometry()}}. Der Unterschied ist, dass man bei der ersten sicher sein kann, dass keine Verformungen auftreten (siehe [[#Skalieren einer Form|Skalieren einer Form]] unten). Wir können unsere Transformation wie folgt anwenden:
is that with the first one, you are sure that no deformations will occur (see

"scaling a shape" below). So we can apply our transformation like this:
{{Code|code=
<syntaxhighlight>
myShape.trasformShape(myMat)
myShape.transformShape(myMat)
}}
</syntaxhighlight>

or
oder
<syntaxhighlight>

{{Code|code=
myShape.transformGeometry(myMat)
myShape.transformGeometry(myMat)
}}
</syntaxhighlight>
{{Top}}
==== Scaling a shape ====
<span id="Scale_a_shape"></span>
Scaling a shape is a more dangerous operation because, unlike translation
===Skalieren einer Form===
or rotation, scaling non-uniformly (with different values for x, y and z)

can modify the structure of the shape. For example, scaling a circle with
Das Skalieren einer Form ist eine gefährlichere Operation, denn im Gegensatz zum Verschieben oder Drehen kann ungleichmäßiges Skalieren (mit unterschiedlichen Werten für X, Y und Z) die Struktur der Form verändern. Beispielsweise kann das Skalieren eines Kreises, mit einem höheren Wert für horizontal als für vertikal, ihn in eine Ellipse umwandeln, die sich mathematisch ganz anders verhält. Für das Skalieren kann {{incode|transformShape()}} nicht verwendet werden, wir müssen {{incode|transformGeometry()}} verwenden:
a higher value horizontally than vertically will transform it into an

ellipse, which behaves mathematically very differenty. For scaling, we
{{Code|code=
can't use the transformShape, we must use transformGeometry():
myMat = App.Matrix()
<syntaxhighlight>
myMat = Base.Matrix()
myMat.scale(2, 1, 1)
myMat.scale(2,1,1)
myShape=myShape.transformGeometry(myMat)
myShape=myShape.transformGeometry(myMat)
}}
</syntaxhighlight>
{{Top}}
=== Boolean Operations ===
<span id="Boolean_operations"></span>
==Boolesche Operationen==


==== Subtraction ====
<span id="Subtraction"></span>
===Differenz===
Subtracting a shape from another one is called "cut" in OCC/FreeCAD jargon

and is done like this:
Das Subtrahieren einer Form von einer anderen Form wird in FreeCAD "Differenz" genannt (engl. Cut), und so wird es gemacht:
<syntaxhighlight>

cylinder = Part.makeCylinder(3,10,Base.Vector(0,0,0),Base.Vector(1,0,0))
{{Code|code=
sphere = Part.makeSphere(5,Base.Vector(5,0,0))
cylinder = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
sphere = Part.makeSphere(5, App.Vector(5, 0, 0))
diff = cylinder.cut(sphere)
diff = cylinder.cut(sphere)
}}
</syntaxhighlight>
{{Top}}
==== Intersection ====
<span id="Intersection"></span>
The same way, the intersection between 2 shapes is called "common" and is done
===Schnitt===
this way:

<syntaxhighlight>
Die Überschneidung zweier Formen, also das "gemeinsame" (engl. Common) Volumen, wird "Schnitt"(-objekt,) genannt, und so wird es gemacht:
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))
{{Code|code=
cylinder1 = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
cylinder2 = Part.makeCylinder(3, 10, App.Vector(5, 0, -5), App.Vector(0, 0, 1))
common = cylinder1.common(cylinder2)
common = cylinder1.common(cylinder2)
}}
</syntaxhighlight>
{{Top}}
==== Union ====
<span id="Union"></span>
Union is called "fuse" and works the same way:
===Vereinigung===
<syntaxhighlight>

cylinder1 = Part.makeCylinder(3,10,Base.Vector(0,0,0),Base.Vector(1,0,0))
Das zusammenfügen von Formen wird "Vereinigung" genannt und funktioniert auf dieselbe Weise:
cylinder2 = Part.makeCylinder(3,10,Base.Vector(5,0,-5),Base.Vector(0,0,1))

{{Code|code=
cylinder1 = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
cylinder2 = Part.makeCylinder(3, 10, App.Vector(5, 0, -5), App.Vector(0, 0, 1))
fuse = cylinder1.fuse(cylinder2)
fuse = cylinder1.fuse(cylinder2)
}}
</syntaxhighlight>
{{Top}}
==== Section ====
<span id="Section"></span>
A Section is the intersection between a solid shape and a plane shape.
===Schnittkurve===
It will return an intersection curve, a compound with edges

<syntaxhighlight>
Eine "Schnittkurve" ist der Schnitt (der Hüllflächen) einer Festkörper-Form und einer ebenen Form. Rückgabeobjekt ist eine Schnittkurve, eine Verbundkurve, die aus Kanten besteht.
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))
{{Code|code=
cylinder1 = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
cylinder2 = Part.makeCylinder(3, 10, App.Vector(5, 0, -5), App.Vector(0, 0, 1))
section = cylinder1.section(cylinder2)
section = cylinder1.section(cylinder2)
section.Wires
section.Wires
Line 498: Line 615:
<Edge object at 0D86DE18>, <Edge object at 0D9B8E80>, <Edge object at 012A3640>,
<Edge object at 0D86DE18>, <Edge object at 0D9B8E80>, <Edge object at 012A3640>,
<Edge object at 0D8F4BB0>]
<Edge object at 0D8F4BB0>]
}}
</syntaxhighlight>
{{Top}}
==== Extrusion ====
===Extrusion===
Extrusion is the act of "pushing" a flat shape in a certain direction resulting in

a solid body. Think of a circle becoming a tube by "pushing it out":
Extrusion ist das Bewegen einer flachen Form in eine bestimmte Richtung, und hat als Ergebnis einen Festkörper. Ein ungefüllter Kreis (circle) wird durch Verschieben zu einem Hohlzylinder (tube):
<syntaxhighlight>

{{Code|code=
circle = Part.makeCircle(10)
circle = Part.makeCircle(10)
tube = circle.extrude(Base.Vector(0,0,2))
tube = circle.extrude(App.Vector(0, 0, 2))
}}
</syntaxhighlight>

If your circle is hollow, you will obtain a hollow tube. If your circle is actually
Ist der Kreis gefüllt, also eine Scheibe/Fläche (disc), erhält man einen Festkörper-Zylinder:
a disc, with a filled face, you will obtain a solid cylinder:

<syntaxhighlight>
{{Code|code=
wire = Part.Wire(circle)
wire = Part.Wire(circle)
disc = Part.Face(wire)
disc = Part.Face(wire)
cylinder = disc.extrude(Base.Vector(0,0,2))
cylinder = disc.extrude(App.Vector(0, 0, 2))
}}
</syntaxhighlight>
{{Top}}
== Exploring shapes ==
<span id="Explore_shapes"></span>
You can easily explore the topological data structure:
==Formen untersuchen==
<syntaxhighlight>

Du kannst die topologische Datenstruktur leicht erkunden:

{{Code|code=
import Part
import Part
b = Part.makeBox(100,100,100)
b = Part.makeBox(100, 100, 100)
b.Wires
b.Wires
w = b.Wires[0]
w = b.Wires[0]
Line 529: Line 653:
v = e.Vertexes[0]
v = e.Vertexes[0]
v.Point
v.Point
}}
</syntaxhighlight>

By typing the lines above in the python interpreter, you will gain a good
Durch tippen der obigen Zeilen in den Python Interpreter, erhälst du eine gutes Verständnis der Struktur von Teilobjekten. Hier hat unser {{incode|makeBox()}} Befehl eine feste Form geschaffen. Dieser Volumenkörper enthält, wie alle Teil Volumenkörper, Flächen. Flächen enthalten immer Drähte, d.h. Listen von Kanten, die die Fläche begrenzen. Jede Fläche hat mindestens einen geschlossenen Draht (sie kann mehr haben, wenn die Fläche ein Loch hat). In dem Draht können wir jede Kante einzeln betrachten, und innerhalb jeder Kante können wir siehe die Eckpunkte. Gerade Kanten haben offensichtlich nur zwei Knoten.
understanding of the structure of Part objects. Here, our makeBox() command
{{Top}}
created a solid shape. This solid, like all Part solids, contains faces.
<span id="Edge_analysis"></span>
Faces always contain wires, which are lists of edges that border the face.
===Kantenanalyse===
Each face has at least one closed wire (it can have more if the face has a hole).

In the wire, we can look at each edge separately, and inside each edge, we can
Im Falle einer Kante, die eine willkürliche Kurve ist, ist es am wahrscheinlichsten, dass du
see the vertexes. Straight edges have only two vertexes, obviously.
eine Diskretisierung durchführen möchtest. In FreeCAD werden die Kanten durch ihre Länge parametrisiert.
Das bedeutet, dass du eine Kante/Kurve anhand ihrer Länge entlang laufen kannst:


{{Code|code=
=== Edge analysis ===
In case of an edge, which is an arbitrary curve, it's most likely you want to
do a discretization. In FreeCAD the edges are parametrized by their lengths.
That means you can walk an edge/curve by its length:
<syntaxhighlight>
import Part
import Part
box = Part.makeBox(100,100,100)
box = Part.makeBox(100, 100, 100)
anEdge = box.Edges[0]
anEdge = box.Edges[0]
print anEdge.Length
print(anEdge.Length)
}}
</syntaxhighlight>

Now you can access a lot of properties of the edge by using the length as a
Jetzt kannst du auf viele Eigenschaften der Kante zugreifen, indem du die Länge als
position. That means if the edge is 100mm long the start position is 0 and
Position verwendest. Das heißt, wenn die Kante 100 mm lang ist, ist die Startposition 0 und
the end position 100.
die Endposition 100.
<syntaxhighlight>

anEdge.tangentAt(0.0) # tangent direction at the beginning
{{Code|code=
anEdge.valueAt(0.0) # Point at the beginning
anEdge.valueAt(100.0) # Point at the end of the edge
anEdge.tangentAt(0.0) # tangent direction at the beginning
anEdge.derivative1At(50.0) # first derivative of the curve in the middle
anEdge.valueAt(0.0) # Point at the beginning
anEdge.derivative2At(50.0) # second derivative of the curve in the middle
anEdge.valueAt(100.0) # Point at the end of the edge
anEdge.derivative3At(50.0) # third derivative of the curve in the middle
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.centerOfCurvatureAt(50) # center of the curvature for that position
anEdge.curvatureAt(50.0) # the curvature
anEdge.curvatureAt(50.0) # the curvature
anEdge.normalAt(50) # normal vector at that position (if defined)
anEdge.normalAt(50) # normal vector at that position (if defined)
}}
</syntaxhighlight>
{{Top}}
=== Using the selection ===
<span id="Use_a_selection"></span>
Here we see now how we can use the selection the user did in the viewer.
===Verwendung einer Auswahl===
First of all we create a box and shows it in the viewer

<syntaxhighlight>
Hier sehen wir nun, wie wir eine Auswahl verwenden können, die der Benutzer im Betrachter getroffen hat. Zuerst erstellen wir einen Kasten und zeigen ihn im Betrachter an.

{{Code|code=
import Part
import Part
Part.show(Part.makeBox(100,100,100))
Part.show(Part.makeBox(100, 100, 100))
Gui.SendMsgToActiveView("ViewFit")
Gui.SendMsgToActiveView("ViewFit")
}}
</syntaxhighlight>

Select now some faces or edges. With this script you can
Wähle nun einige Flächen oder Kanten aus. Mit diesem Skript kannst du über alle ausgewählten Objekte und deren Unterelemente iterieren:
iterate all selected objects and their sub elements:

<syntaxhighlight>
{{Code|code=
for o in Gui.Selection.getSelectionEx():
for o in Gui.Selection.getSelectionEx():
print o.ObjectName
print(o.ObjectName)
for s in o.SubElementNames:
for s in o.SubElementNames:
print "name: ",s
print("name: ", s)
for s in o.SubObjects:
for s in o.SubObjects:
print "object: ",s
print("object: ", s)
}}
</syntaxhighlight>

Select some edges and this script will calculate the length:
Wähle einige Kanten aus und dieses Skript berechnet die Länge:
<syntaxhighlight>

{{Code|code=
length = 0.0
length = 0.0
for o in Gui.Selection.getSelectionEx():
for o in Gui.Selection.getSelectionEx():
for s in o.SubObjects:
for s in o.SubObjects:
length += s.Length
length += s.Length

print "Length of the selected edges:" ,length
print("Length of the selected edges: ", length)
</syntaxhighlight>
}}
== Complete example: The OCC bottle ==
{{Top}}
A typical example found in the
<span id="Example:_The_OCC_bottle"></span>
[http://www.opencascade.com/doc/occt-6.9.0/overview/html/occt__tutorial.html#sec1 OpenCasCade Technology Tutorial]
==Beispiel: Die OCC Flasche==
is how to build a bottle. This is a good exercise for FreeCAD too. In fact,

you can follow our example below and the OCC page simultaneously, you will
Ein typisches Beispiel, das auf der [https://www.opencascade.com/doc/occt-6.9.0/overview/html/occt__tutorial.html OpenCasCade Technology Website] zu finden ist, ist der Bau einer Flasche. Dies ist auch eine gute Übung für FreeCAD. Wenn du unserem Beispiel unten und der OCC-Seite gleichzeitig folgst, wirst du sehen, wie gut OCC Strukturen in FreeCAD implementiert sind. Das Skript ist in der FreeCAD Installation enthalten (innerhalb des Ordners {{FileName|Mod/Part}}) und kann vom Python Interpreter durch Eintippen aufgerufen werden:
understand well how OCC structures are implemented in FreeCAD. The complete script

below is also included in FreeCAD installation (inside the Mod/Part folder) and
{{Code|code=
can be called from the python interpreter by typing:
<syntaxhighlight>
import Part
import Part
import MakeBottle
import MakeBottle
bottle = MakeBottle.makeBottle()
bottle = MakeBottle.makeBottle()
Part.show(bottle)
Part.show(bottle)
}}
</syntaxhighlight>
{{Top}}
=== The complete script ===
<span id="The_script"></span>
Here is the complete MakeBottle script:
===Das Skript====
<syntaxhighlight>

import Part, FreeCAD, math
Für die Zwecke dieses Tutoriums werden wir eine reduzierte Version des Skripts in Betracht ziehen. In dieser Version wird die Flasche nicht ausgehöhlt, und der Flaschenhals wird nicht mit einem Gewinde versehen.
from FreeCAD import Base

{{Code|code=
def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0):
import FreeCAD as App
aPnt1=Base.Vector(-myWidth/2.,0,0)
import Part, math
aPnt2=Base.Vector(-myWidth/2.,-myThickness/4.,0)

aPnt3=Base.Vector(0,-myThickness/2.,0)
aPnt4=Base.Vector(myWidth/2.,-myThickness/4.,0)
def makeBottleTut(myWidth = 50.0, myHeight = 70.0, myThickness = 30.0):
aPnt5=Base.Vector(myWidth/2.,0,0)
aPnt1=App.Vector(-myWidth / 2., 0, 0)
aPnt2=App.Vector(-myWidth / 2., -myThickness / 4., 0)
aPnt3=App.Vector(0, -myThickness / 2., 0)
aArcOfCircle = Part.Arc(aPnt2,aPnt3,aPnt4)
aPnt4=App.Vector(myWidth / 2., -myThickness / 4., 0)
aSegment1=Part.Line(aPnt1,aPnt2)
aPnt5=App.Vector(myWidth / 2., 0, 0)
aSegment2=Part.Line(aPnt4,aPnt5)

aEdge1=aSegment1.toShape()
aEdge2=aArcOfCircle.toShape()
aArcOfCircle = Part.Arc(aPnt2, aPnt3, aPnt4)
aSegment1=Part.LineSegment(aPnt1, aPnt2)
aEdge3=aSegment2.toShape()
aWire=Part.Wire([aEdge1,aEdge2,aEdge3])
aSegment2=Part.LineSegment(aPnt4, aPnt5)

aTrsf=Base.Matrix()
aEdge1=aSegment1.toShape()
aEdge2=aArcOfCircle.toShape()
aTrsf.rotateZ(math.pi) # rotate around the z-axis
aEdge3=aSegment2.toShape()
aWire=Part.Wire([aEdge1, aEdge2, aEdge3])
aMirroredWire=aWire.transformGeometry(aTrsf)

myWireProfile=Part.Wire([aWire,aMirroredWire])
aTrsf=App.Matrix()
myFaceProfile=Part.Face(myWireProfile)
aTrsf.rotateZ(math.pi) # rotate around the z-axis
aPrismVec=Base.Vector(0,0,myHeight)

myBody=myFaceProfile.extrude(aPrismVec)
aMirroredWire=aWire.copy()
myBody=myBody.makeFillet(myThickness/12.0,myBody.Edges)
aMirroredWire.transformShape(aTrsf)
neckLocation=Base.Vector(0,0,myHeight)
myWireProfile=Part.Wire([aWire, aMirroredWire])
neckNormal=Base.Vector(0,0,1)

myNeckRadius = myThickness / 4.
myFaceProfile=Part.Face(myWireProfile)
myNeckHeight = myHeight / 10
aPrismVec=App.Vector(0, 0, myHeight)
myNeck = Part.makeCylinder(myNeckRadius,myNeckHeight,neckLocation,neckNormal)
myBody = myBody.fuse(myNeck)
myBody=myFaceProfile.extrude(aPrismVec)

myBody=myBody.makeFillet(myThickness / 12.0, myBody.Edges)
faceToRemove = 0

zMax = -1.0
neckLocation=App.Vector(0, 0, myHeight)
neckNormal=App.Vector(0, 0, 1)
for xp in myBody.Faces:

try:
myNeckRadius = myThickness / 4.
surf = xp.Surface
myNeckHeight = myHeight / 10.
if type(surf) == Part.Plane:
myNeck = Part.makeCylinder(myNeckRadius, myNeckHeight, neckLocation, neckNormal)
z = surf.Position.z
myBody = myBody.fuse(myNeck)
if z > zMax:

zMax = z
return myBody
faceToRemove = xp

except:
el = makeBottleTut()
continue
Part.show(el)
}}
myBody = myBody.makeThickness([faceToRemove],-myThickness/50 , 1.e-3)
{{Top}}
<span id="Detailed_explanation"></span>
return myBody
===Detaillierte Erklärung===
</syntaxhighlight>

=== Detailed explanation ===
{{Code|code=
<syntaxhighlight>
import Part, FreeCAD, math
import FreeCAD as App
import Part, math
from FreeCAD import Base
}}
</syntaxhighlight>

We will need,of course, the Part module, but also the FreeCAD.Base module,
Wir benötigen natürlich das Modul {{incode|FreeCAD}} und den Arbeitsbereich {{incode|Part}}.
which contains basic FreeCAD structures like vectors and matrixes.

<syntaxhighlight>
{{Code|code=
def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0):
def makeBottleTut(myWidth = 50.0, myHeight = 70.0, myThickness = 30.0):
aPnt1=Base.Vector(-myWidth/2.,0,0)
aPnt2=Base.Vector(-myWidth/2.,-myThickness/4.,0)
aPnt1=App.Vector(-myWidth / 2., 0, 0)
aPnt3=Base.Vector(0,-myThickness/2.,0)
aPnt2=App.Vector(-myWidth / 2., -myThickness / 4., 0)
aPnt4=Base.Vector(myWidth/2.,-myThickness/4.,0)
aPnt3=App.Vector(0, -myThickness / 2., 0)
aPnt5=Base.Vector(myWidth/2.,0,0)
aPnt4=App.Vector(myWidth / 2., -myThickness / 4., 0)
aPnt5=App.Vector(myWidth / 2., 0, 0)
</syntaxhighlight>
}}
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,
Hier definieren wir unsere {{incode|makeBottleTut}} Funktion. Diese Funktion kann aufgerufen werden ohne
and thickness will be used. Then, we define a couple of points that will be used
Argumente, wie wir es oben getan haben, in diesem Fall Standardwerte für Breite und Höhe, und Dicke verwendet werden. Dann definieren wir ein paar Punkte, die verwendet werden für den Aufbau unseres Basisprofils.
for building our base profile.

<syntaxhighlight>
{{Code|code=
aArcOfCircle = Part.Arc(aPnt2,aPnt3,aPnt4)
...
aSegment1=Part.Line(aPnt1,aPnt2)
aSegment2=Part.Line(aPnt4,aPnt5)
aArcOfCircle = Part.Arc(aPnt2, aPnt3, aPnt4)
aSegment1=Part.LineSegment(aPnt1, aPnt2)
</syntaxhighlight>
aSegment2=Part.LineSegment(aPnt4, aPnt5)
Here we actually define the geometry: an arc, made of 3 points, and two
}}
line segments, made of 2 points.

<syntaxhighlight>
Hier definieren wir die Geometrie: einen Bogen, der aus drei Punkten besteht, und zwei Liniensegmente, die aus zwei Punkten bestehen.
aEdge1=aSegment1.toShape()

aEdge2=aArcOfCircle.toShape()
{{Code|code=
aEdge3=aSegment2.toShape()
...
aWire=Part.Wire([aEdge1,aEdge2,aEdge3])
aEdge1=aSegment1.toShape()
</syntaxhighlight>
aEdge2=aArcOfCircle.toShape()
Remember the difference between geometry and shapes? Here we build
aEdge3=aSegment2.toShape()
shapes out of our construction geometry. 3 edges (edges can be straight
aWire=Part.Wire([aEdge1, aEdge2, aEdge3])
or curved), then a wire made of those three edges.
}}
<syntaxhighlight>

aTrsf=Base.Matrix()
Erinnerst du dich an den Unterschied zwischen Geometrie und Formen? Hier bauen wir Formen aus unserer Konstruktionsgeometrie. Drei Kanten (Kanten können gerade sein oder gebogen), dann einen Draht hergestellt aus diesen drei Kanten.
aTrsf.rotateZ(math.pi) # rotate around the z-axis

aMirroredWire=aWire.transformGeometry(aTrsf)
{{Code|code=
myWireProfile=Part.Wire([aWire,aMirroredWire])
...
</syntaxhighlight>
aTrsf=App.Matrix()
Until now we built only a half profile. Easier than building the whole profile
aTrsf.rotateZ(math.pi) # rotate around the z-axis
the same way, we can just mirror what we did, and glue both halfs together.

So we first create a matrix. A matrix is a very common way to apply transformations
aMirroredWire=aWire.copy()
to objects in the 3D world, since it can contain in one structure all basic
aMirroredWire.transformShape(aTrsf)
transformations that 3D objects can suffer (move, rotate and scale). Here,
myWireProfile=Part.Wire([aWire, aMirroredWire])
after we create the matrix, we mirror it, and 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.
Bislang haben wir nur ein halbes Profil erstellt. Anstatt das ganze Profil zu bauen
<syntaxhighlight>
Auf die gleiche Weise können wir einfach spiegeln, was wir getan haben, und beide Hälften zusammenkleben. Zuerst erstellen wir eine Matrix. Eine Matrix ist ein sehr gebräuchlicher Weg, um Transformationen auf Objekte in der 3D Welt anzuwenden, da sie in einer Struktur alle grundlegenden Transformationen, denen 3D Objekte unterzogen werden können (Verschieben, Drehen und Skalieren) enthalten. Nachdem wir die Matrix erstellt haben, spiegeln wir sie, dann erstellen wir eine Kopie unseres Drahtes und wenden die Transformationsmatrix darauf an. Wir haben jetzt zwei Drähte, und können wir einen dritten Draht aus ihnen machen, da Drähte eigentlich Listen von Kanten sind.
myFaceProfile=Part.Face(myWireProfile)

aPrismVec=Base.Vector(0,0,myHeight)
{{Code|code=
myBody=myFaceProfile.extrude(aPrismVec)
...
myBody=myBody.makeFillet(myThickness/12.0,myBody.Edges)
myFaceProfile=Part.Face(myWireProfile)
</syntaxhighlight>
aPrismVec=App.Vector(0, 0, myHeight)
Now that we have a closed wire, it can be turned into a face. Once we have a face,
myBody=myFaceProfile.extrude(aPrismVec)
we can extrude it. Doing so, we actually made a solid. Then we apply a nice little

fillet to our object because we care about good design, don't we?
myBody=myBody.makeFillet(myThickness / 12.0, myBody.Edges)
<syntaxhighlight>
}}
neckLocation=Base.Vector(0,0,myHeight)

neckNormal=Base.Vector(0,0,1)
Nun, da wir einen geschlossenen Draht haben, kann er in eine Fläche verwandelt werden. Sobald wir eine Fläche haben, können wir es extrudieren. Auf diese Weise machen wir einen Festkörper. Dann wenden wir eine schöne kleine Verrundung auf unser Objekt an, weil wir uns um gutes Design kümmern, nicht wahr?
myNeckRadius = myThickness / 4.

myNeckHeight = myHeight / 10
{{Code|code=
myNeck = Part.makeCylinder(myNeckRadius,myNeckHeight,neckLocation,neckNormal)
...
</syntaxhighlight>
neckLocation=App.Vector(0, 0, myHeight)
Then, the body of our bottle is made, we still need to create a neck. So we
neckNormal=App.Vector(0, 0, 1)
make a new solid, with a cylinder.

<syntaxhighlight>
myNeckRadius = myThickness / 4.
myBody = myBody.fuse(myNeck)
myNeckHeight = myHeight / 10.
</syntaxhighlight>
myNeck = Part.makeCylinder(myNeckRadius, myNeckHeight, neckLocation, neckNormal)
The fuse operation, which in other apps is sometimes called union, is very
}}
powerful. It will take care of gluing what needs to be glued and remove parts that

need to be removed.
An diesem Punkt ist der Körper unserer Flasche hergestellt, aber wir müssen noch einen Hals schaffen. Wir stellen einen neuen Körper mit einem Zylinder her.
<syntaxhighlight>

return myBody
{{Code|code=
</syntaxhighlight>
...
Then, we return our Part solid as the result of our function. That Part solid,
myBody = myBody.fuse(myNeck)
like any other Part shape, can be attributed to an object in a FreeCAD document, with:
}}
<syntaxhighlight>

myObject = FreeCAD.ActiveDocument.addObject("Part::Feature","myObject")
Der Verschmelzungsoperation ist sehr leistungsstark. Sie kümmert sich um das Kleben, was geklebt werden muss, und entfernt Teile, die entfernt werden müssen.
myObject.Shape = bottle

</syntaxhighlight>
{{Code|code=
or, more simple:
...
<syntaxhighlight>
return myBody
Part.show(bottle)
}}
</syntaxhighlight>

==Box pierced==
Dann geben wir als Ergebnis unserer Funktion unseren Part Volumenkörper zurück.
Here a complete example of building a box pierced.

{{Code|code=
el = makeBottleTut()
Part.show(el)
}}

Schließlich rufen wir die Funktion auf, um das Teil tatsächlich zu erstellen und es dann sichtbar zu machen.
{{Top}}
<span id="Example:_Pierced_box"></span>
==Beispiel: Durchbohrter Quader==

Hier ist ein vollständiges Beispiel für den Bau eines durchbohrten Quaders.

Der Aufbau erfolgt von einer Seite nach der anderen. Wenn der Würfel fertig ist, wird er durch das Durchschneiden eines Zylinders ausgehöhlt.


{{Code|code=
The construction is done side by side and when the cube is finished, it is hollowed out of a cylinder through.
import FreeCAD as App
<syntaxhighlight>
import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, PyQt4
import Part, math
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base


size = 10
size = 10
poly = Part.makePolygon( [ (0,0,0), (size, 0, 0), (size, 0, size), (0, 0, size), (0, 0, 0)])
poly = Part.makePolygon([(0, 0, 0), (size, 0, 0), (size, 0, size), (0, 0, size), (0, 0, 0)])


face1 = Part.Face(poly)
face1 = Part.Face(poly)
Line 762: Line 903:
face6 = Part.Face(poly)
face6 = Part.Face(poly)
myMat = FreeCAD.Matrix()
myMat = App.Matrix()

myMat.rotateZ(math.pi/2)
myMat.rotateZ(math.pi / 2)
face2.transformShape(myMat)
face2.transformShape(myMat)
face2.translate(FreeCAD.Vector(size, 0, 0))
face2.translate(App.Vector(size, 0, 0))


myMat.rotateZ(math.pi/2)
myMat.rotateZ(math.pi / 2)
face3.transformShape(myMat)
face3.transformShape(myMat)
face3.translate(FreeCAD.Vector(size, size, 0))
face3.translate(App.Vector(size, size, 0))


myMat.rotateZ(math.pi/2)
myMat.rotateZ(math.pi / 2)
face4.transformShape(myMat)
face4.transformShape(myMat)
face4.translate(FreeCAD.Vector(0, size, 0))
face4.translate(App.Vector(0, size, 0))

myMat = App.Matrix()


myMat = FreeCAD.Matrix()
myMat.rotateX(-math.pi / 2)
myMat.rotateX(-math.pi/2)
face5.transformShape(myMat)
face5.transformShape(myMat)


face6.transformShape(myMat)
face6.transformShape(myMat)
face6.translate(FreeCAD.Vector(0,0,size))
face6.translate(App.Vector(0, 0, size))

myShell = Part.makeShell([face1,face2,face3,face4,face5,face6])


myShell = Part.makeShell([face1, face2, face3, face4, face5, face6])
mySolid = Part.makeSolid(myShell)
mySolid = Part.makeSolid(myShell)
mySolidRev = mySolid.copy()
mySolidRev.reverse()


myCyl = Part.makeCylinder(2,20)
myCyl = Part.makeCylinder(2, 20)
myCyl.translate(FreeCAD.Vector(size/2, size/2, 0))
myCyl.translate(App.Vector(size / 2, size / 2, 0))


cut_part = mySolidRev.cut(myCyl)
cut_part = mySolid.cut(myCyl)


Part.show(cut_part)
Part.show(cut_part)
}}
</syntaxhighlight>
{{Top}}
== Loading and Saving ==
<span id="Loading_and_saving"></span>
There are several ways to save your work in the Part module. You can
==Laden und Speichern==
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.
Es gibt mehrere Möglichkeiten, deine Arbeit zu speichern. Du kannst natürlich dein FreeCAD Dokument speichern, aber Du kannst auch [[Part_Workbench/de|Part]] Objekte direkt in gängigen CAD Formaten wie BREP, IGS, STEP und STL speichern.

Das Speichern einer Form in einer Datei ist einfach. Es stehen die Methoden {{incode|exportBrep()}}, {{incode|exportIges()}}, {{incode|exportStep()}} und {{incode|exportStl()}} für alle Formobjekte zur Verfügung. Also, ausführen:


{{Code|code=
Saving a shape to a file is easy. There are exportBrep(), exportIges(),
exportStl() and exportStep() methods availables for all shape objects.
So, doing:
<syntaxhighlight>
import Part
import Part
s = Part.makeBox(0,0,0,10,10,10)
s = Part.makeBox(10, 10, 10)
s.exportStep("test.stp")
s.exportStep("test.stp")
}}
</syntaxhighlight>

this will save our box into a STEP file. To load a BREP,
wird unseren Quader in eine STEP Datei gespeichert. Um eine BREP , IGES oder STEP Datei zu laden:
IGES or STEP file, simply do the contrary:

<syntaxhighlight>
{{Code|code=
import Part
import Part
s = Part.Shape()
s = Part.Shape()
s.read("test.stp")
s.read("test.stp")
}}
</syntaxhighlight>

To convert an '''.stp''' in '''.igs''' file simply :
Um eine STEP Datei in eine IGS Datei umzuwandeln:
<syntaxhighlight>

{{Code|code=
import Part
import Part
s = Part.Shape()
s = Part.Shape()
s.read("file.stp") # incoming file igs, stp, stl, brep
s.read("file.stp") # incoming file igs, stp, stl, brep
s.exportIges("file.igs") # outbound file igs
s.exportIges("file.igs") # outbound file igs
}}
</syntaxhighlight>
{{Top}}
Note that importing or opening BREP, IGES or STEP files can also be done
directly from the File -> Open or File -> Import menu, while exporting
is with File -> Export


{{Docnav/de
{{docnav|Mesh Scripting|Mesh to Part}}
|[[FreeCAD_Scripting_Basics/de|FreeCAD Grundlagen Skripten]]

|[[Mesh_Scripting|Netz Skripten]]
[[Category:Poweruser Documentation/de]] [[Category:Python Code/de]]
}}


{{Powerdocnavi{{#translation:}}}}

[[Category:Developer Documentation{{#translation:}}]]
{{clear}}
[[Category:Python Code{{#translation:}}]]
<languages/>

Latest revision as of 12:41, 13 October 2023

Einleitung

Hier wird erklärt, wie sich der Arbeitsbereich Part direkt aus dem FreeCAD-Python-Interpreter oder aus einem externen Skript heraus steuern lässt. Unter Skripten und FreeCAD Grundlagen Skripten finden sich weitere Informationen über die Funktionsweise von Python-Skripten in FreeCAD. Für Python-Anfänger ist es eine gute Idee, zuerst die Einführung in Python zu lesen.

Siehe auch

Klassendiagramm

Dies ist ein Überblick über die wesentlichen Klassen des Arbeitsbereichs Part in Form eines UML-Diagramms. Siehe Unified Modeling Language :

Python-Klassen des Arbeitsbereichs Part
Python-Klassen des Arbeitsbereichs Part

Anfang

Geometrie

Geometrische Objekte sind die Bausteine aller topologischen Objekte:

  • Geom Basisklasse der geometrischen Objekte
  • Line Eine gerade Linie im Raum, definiert durch den Start- und Endpunkt
  • Circle Kreis oder Kreissegment, definiert durch einen Mittelpunkt sowie Start- und Endpunkt
  • Usw.

Anfang

Topologie

Die folgenden topologischen Datentypen stehen zur Verfügung:

  • Compound Eine Gruppe von beliebigen topologischen Objekten.
  • Compsolid Ein zusammengesetzter Körper (composite solid) ist ein Satz (eine Menge) von Körpern, die über ihre Flächen verbunden sind. Dies erweitert das Konzept von WIRE and SHELL auf (Fest-)Körper (solids).
  • Solid Ein Teil des (Konstruktion-)Raumes, der durch eine geschlossene Hülle begrenzt ist. Ein Solid (Festkörper) ist dreidimensional.
  • Shell Hülle = Ein Satz (eine Menge) von über ihre Kanten verbundenen Flächen. Eine Hülle kann offen oder geschlossen sein.
  • Face In 2D ist es ein Teil einer Ebene; in 3D ist es ein Teil einer Oberfläche (Trägerfläche). Die Form wird durch Konturen begrenzt (getrimmt). Ein Face (eine Fläche) ist zweidimensional (hat keine Wandstärke).
  • Wire Ein Satz von über ihre Endpunkten verknüpften Kanten. Ein "Wire" kann eine offene oder geschlossene Form haben, je nach dem ob Start- und Endpunkt verbunden sind oder nicht.
  • Edge Ein topologisches Element (Kante) das einer begrenzten Kurve entspricht. Eine Kante ist generell durch Knoten(-punkte) (Vertizes) begrenzt. Eine Kante (Edge) ist eindimensional (hat keine radiale Ausdehnung).
  • Vertex Ein topologisches Element das einem (Knoten-)Punkt entspricht. Es ist nulldimensional.
  • Shape (Form) ist der Oberbegriff für all die zuvor aufgezählten Elemente.

Anfang

Beispiel: Einfache Topologie erstellen

Wire

Wir werden nun eine Topologie erstellen, indem wir sie mit einfacheren Geometrien konstruieren. Als Beispiel verwenden wir ein Teil, wie im Bild zu sehen, das aus vier Knoten, zwei Kreisen und zwei Linien besteht.

Anfang

Geometrie erstellen

Zuerst erstellen wir die individuellen geometrischen Teile dieses Drahtes (Wire). Dabei stellen wir sicher, dass die Teile, die später verbunden werden, dieselben Knoten verwenden.

Also erstellen wir zuerst die (Knoten-)Punkte (Vertices/Vertexes):

import FreeCAD as App
import Part
V1 = App.Vector(0, 10, 0)
V2 = App.Vector(30, 10, 0)
V3 = App.Vector(30, -10, 0)
V4 = App.Vector(0, -10, 0)

Anfang

Bogen

Circle


Für jeden Bogen benötigen wir einen Hilfspunkt:

VC1 = App.Vector(-10, 0, 0)
C1 = Part.Arc(V1, VC1, V4)
VC2 = App.Vector(40, 0, 0)
C2 = Part.Arc(V2, VC2, V3)

Anfang

Linie

Line


Die Linienabschnitte können aus zwei Punkten erstellt werden:

L1 = Part.LineSegment(V1, V2)
L2 = Part.LineSegment(V3, V4)

Anfang

Alles zusammensetzen

Der letzte Schritt besteht darin, die geometrischen Basiselemente zusammenzusetzen und zu einer topologischen Form (Shape) zu vereinigen:

S1 = Part.Shape([C1, L1, C2, L2])

Anfang

Ein prismatisches Objekt erstellen

Jetzt wird der Draht in eine Richtung extrudiert und so eine wirkliche 3D-Form erstellt:

W = Part.Wire(S1.Edges)
P = W.extrude(App.Vector(0, 0, 10))

Anfang

Alles anzeigen

Part.show(P)

Anfang

Grundformen erstellen

Topologische Grundobjekte können ganz einfach mit den Methoden make...() aus dem Arbeitsbereich Part erstellen:

b = Part.makeBox(100, 100, 100)
Part.show(b)

Einige verfügbare make...() Methoden:

  • makeBox(l, w, h, [p, d]) Erstellt einen Quader, der sich in p befindet und in die Richtung d zeigt, mit den Abmessungen (l,w,h).
  • makeCircle(radius) Erstellt einen Kreis mit einem gegebenen Radius.
  • makeCone(radius1, radius2, height) Erstellt einen Kegel mit den gegebenen Radien und der Höhe.
  • makeCylinder(radius, height) Erstellt einen Zylinder mit gegebenen Radius und Höhe.
  • makeLine((x1, y1, z1), (x2, y2, z2)) Erstellt eine Linie aus zwei Punkten.
  • makePlane(length, width) Erstellt eine Ebene mit Länge und Breite.
  • makePolygon(list) Erstellt ein Polygon aus einer Liste von Punkten.
  • makeSphere(radius) Erstellt eine Kugel mit einem bestimmten Radius.
  • makeTorus(radius1, radius2) Erstellt einen Torus mit den gegebenen Radien.

Siehe die Seite Part API oder diese autogenerated Python Part API documentation für eine vollständige Liste der verfügbaren Methoden des Arbeitsbereichs Part.

Anfang

Module Importieren

Zuerst müssen wir das FreeCAD-Modul und den Arbeitsbereich Part importieren, damit wir ihre Inhalte in Python verwenden können:

import FreeCAD as App
import Part

Anfang

Einen Vektor erstellen

Vektoren gehören zu den wichtigsten Informationsbestandteilen beim Erstellen von Formen. Sie enthalten in der Regel (aber nicht zwangsläufig immer) drei Zahlen, die kartesischen Koordinaten x, y und z. Und so wird ein Vektor erstellt:

myVector = App.Vector(3, 2, 0)

Wir haben soeben einen Vektor mit den Koordinaten x = 3, y = 2, z = 0 erstellt. Im Arbeitsbereich Part werden Vektoren überall verwendet. Part-Formen verwenden auch eine andere Art von Punktdarstellung namens Knoten (Vertex), die einfach ein Behälter für einen Vektor ist. So greift man auf den Vektor eines Knoten zu:

myVertex = myShape.Vertexes[0]
print(myVertex.Point)
> Vector (3, 2, 0)

Anfang

Eine Kante erstellen

Eine Kante ist nichts anderes als eine Linie mit zwei Knoten:

edge = Part.makeLine((0, 0, 0), (10, 0, 0))
edge.Vertexes
> [<Vertex object at 01877430>, <Vertex object at 014888E0>]

Hinweis: Eine Kante kann auch durch Übergabe von zwei Vektoren erstellt werden:

vec1 = App.Vector(0, 0, 0)
vec2 = App.Vector(10, 0, 0)
line = Part.LineSegment(vec1, vec2)
edge = line.toShape()

So findet man die Länge und den Mittelpunkt einer Kante:

edge.Length
> 10.0
edge.CenterOfMass
> Vector (5, 0, 0)

Anfang

Die Form auf den Bildschirm bringen

Bisher haben wir ein Kantenobjekt erstellt, das aber nirgendwo auf dem Bildschirm erscheint. Das liegt daran, dass die FreeCAD-3D-Szene nur etwas anzeigt, wenn man ihr sagt, dass sie es anzeigen soll. Um das zu tun, verwenden wir folgende einfache Methode:

Part.show(edge)

Die Anzeigefunktion (.show) erzeugt ein Objekt in unserem FreeCAD-Dokument und weist ihm unsere Form "edge" zu. Sie wird verwendet, wenn es an der Zeit ist, das Erstellte auf dem Bildschirm anzuzeigen.

Anfang

Einen Draht erstellen

Ein Draht (Wire) ist eine Linie aus mehreren Kanten und kann aus einer Liste von Kanten oder sogar einer Liste von Drähten erstellt werden:

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) zeigt die 4 Kanten, die unseren Draht bilden (in der 3D-Ansicht) an. Weitere nützliche Informationen können leicht abgerufen werden:

wire3.Length
> 40.0
wire3.CenterOfMass
> Vector (5, 5, 0)
wire3.isClosed()
> True
wire2.isClosed()
> False

Anfang

Eine Fläche erstellen

Nur Flächen (Faces), die aus geschlossenen Drähten erstellt wurden, sind gültig. In diesem Beispiel ist wire3 ein geschlossener Draht, aber wire2 ist kein geschlossener Draht (siehe oben).

face = Part.Face(wire3)
face.Area
> 99.99999999999999
face.CenterOfMass
> Vector (5, 5, 0)
face.Length
> 40.0
face.isValid()
> True
sface = Part.Face(wire2)
sface.isValid()
> False

Nur Flächen haben einen Flächeninhalt (area), Drähte und Kanten haben keinen.

Anfang

Einen Kreis erstellen

So kann ein Kreis erstellt werden:

circle = Part.makeCircle(10)
circle.Curve
> Circle (Radius : 10, Position : (0, 0, 0), Direction : (0, 0, 1))

Wenn er an einer bestimmten Stelle und mit einer bestimmten Ausrichtung erstellt werden soll:

ccircle = Part.makeCircle(10, App.Vector(10, 0, 0), App.Vector(1, 0, 0))
ccircle.Curve
> Circle (Radius : 10, Position : (10, 0, 0), Direction : (1, 0, 0))

ccircle wird mit dem Abstand 10 vom X-Ursprung erstellt und ist nach außen entlang der X-Achse ausgerichtet. Hinweis: makeCircle() akzeptiert nur einen App.Vector() für die Position und normale Parameter, keine Tupel. Du kannst auch einen Teil des Kreises durch Angabe eines Anfangs- und eines Endwinkels erstellen:

from math import pi
arc1 = Part.makeCircle(10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 180)
arc2 = Part.makeCircle(10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 180, 360)

Winkel sollten in Grad angegeben werden. Liegt ein Wert in Bogenmaß vor, wird er einfach mit folgender Formel umgewandelt: Grad = Bogenmaß * 180/pi oder mit Hilfe des Python-Moduls math:

import math
degrees = math.degrees(radians)

Anfang

Einen Bogen über Punkte erstellen

Leider gibt es keine Funktion makeArc(), aber wir haben die Funktion Part.Arc() um einen Bogen (Arc) durch drei Punkte zu erzeugen. Sie erzeugt ein Arc-Objekt, das den Startpunktes mit dem Endpunkt über den Mittelpunkt verbindet. Die Funktion toShape() des Arc-Objekts muss aufgerufen werden, um ein Edge-Objekt zu erhalten, wie bei der Verwendung von Part.LineSegment anstelle von Part.makeLine.

arc = Part.Arc(App.Vector(0, 0, 0), App.Vector(0, 5, 0), App.Vector(5, 5, 0))
arc
> <Arc object>
arc_edge = arc.toShape()
Part.show(arc_edge)

Arc() akzeptiert nur App.Vector() für Punkte, aber keine Tupel. Einen Bogen kann man auch durch Verwendung eines Kreisabschnitts erhalten:

from math import pi
circle = Part.Circle(App.Vector(0, 0, 0), App.Vector(0, 0, 1), 10)
arc = Part.Arc(circle,0,pi)

Bögen sind gültige Kanten wie Linien, so dass sie auch in Drähten verwendet werden können.

Anfang

Ein Vieleck erstellen

Ein Vieleck (Polygon) ist einfach ein Draht mit mehreren geraden Kanten. Die Funktion makePolygon() nimmt eine Liste von Punkten entgegen und erstellt einen Draht durch diese Punkte:

lshape_wire = Part.makePolygon([App.Vector(0, 5, 0), App.Vector(0, 0, 0), App.Vector(5, 0, 0)])

Anfang

Eine Bézier-Kurve erstellen

Bézier-Kurven werden verwendet, um weiche Kurven mit einer Reihe von Polen (Punkten) und optionalen Gewichten zu modellieren. Die folgende Funktion erstellt eine Part.BezierCurve() aus einer Reihe von FreeCAD.Vector() Punkten. (Hinweis: Soll ein einzelner Pol oder ein Gewicht mit "get" und "set" (-Methoden und Indizes) angesprochen werden, beginnen die Indizes bei 1, nicht bei 0.)

def makeBCurveEdge(Points):
   geomCurve = Part.BezierCurve()
   geomCurve.setPoles(Points)
   edge = Part.Edge(geomCurve)
   return(edge)

Anfang

Eine Ebene erstellen

Eine Ebene (Plane) ist eine ebene rechteckige Fläche. Die Methode, mit der eine Ebene erstellt wird, ist makePlane(length, width, [start_pnt, dir_normal]). Standardmäßig sind start_pnt = Vektor(0, 0, 0) und dir_normal = Vektor(0, 0, 1). Ist dir_normal = Vector(0, 0, 1) wird eine Ebene, die in Richtung der positiven Z-Achse zeigt, erstellt, während dir_normal = Vector(1, 0, 0) eine Ebene erzeugt, die in Richtung der positiven X-Achse zeigt:

plane = Part.makePlane(2, 2)
plane
> <Face object at 028AF990>
plane = Part.makePlane(2, 2, App.Vector(3, 0, 0), App.Vector(0, 1, 0))
plane.BoundBox
> BoundBox (3, 0, 0, 5, 0, 2)

BoundBox ist ein Quader, der die Ebene einschließt, mit einer Diagonale, die bei (3, 0, 0) beginnt und bei (5, 0, 2) endet. Hier ist die Ausdehnung der BoundBox entlang der Y-Achse Null, da unsere Form völlig eben ist.

Hinweis: makePlane() akzeptiert nur App.Vector() für start_pnt und dir_normal, nicht aber Tupel.

Anfang

Eine Ellipse erstellen

Es gibt mehrere Möglichkeiten, eine Ellipse zu erstellen:

Part.Ellipse()

Erzeugt eine Ellipse mit Hauptradius 2 und Nebenradius 1 mit dem Mittelpunkt bei (0,0,0).

Part.Ellipse(Ellipse)

Erstellt eine Kopie der angegebenen Ellipse.

Part.Ellipse(S1, S2, Center)

Erzeugt eine Ellipse, die auf den Punkt Mitte zentriert ist, an dem die Ebene der Ellipse definiert ist durch Mittelpunkt, S1 und S2, ihre Hauptachse definiert ist durch Mittelpunkt und S1, sein Hauptradius ist der Abstand zwischen Mittelpunkt und S1, und sein kleiner Radius ist der Abstand zwischen S2 und der Hauptachse.

Part.Ellipse(Center, MajorRadius, MinorRadius)

Erstellt eine Ellipse mit Haupt- und Nebenradien Hauptradius und Nebenradius, die sich in der durch den Mittelpunkt definierten Ebene und der Normalen (0,0,1) befinden.

eli = Part.Ellipse(App.Vector(10, 0, 0), App.Vector(0, 5, 0), App.Vector(0, 0, 0))
Part.show(eli.toShape())

Im obigen Code haben wir S1, S2 und Mitte überschritten. Ähnlich wie Arc, Ellipse erzeugt ein Ellipsenobjekt, aber keine Kante, also müssen wir es in eine Kante mit toShape() zur Anzeige konvertieren.

Hinweis: Ellipse() akzeptiert nur App.Vector() für Punkte, nicht aber für Tupel.

eli = Part.Ellipse(App.Vector(0, 0, 0), 10, 5)
Part.show(eli.toShape())

Für den obigen Ellipsenkonstruktor haben wir Mitte, HauptRadius und NebenRadius überschritten.

Anfang

Erstellen eines Torus

Verwende makeTorus(radius1, radius2, [pnt, dir, Winkel1, Winkel2, Winkel]). Standardmäßig ist pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1), Winkel1 = 0, Winkel2 = 360 und Winkel = 360. Betrachte einen Torus als kleinen Kreis, der entlang eines großen Kreises verläuft. Radius1 ist der Radius des großen Kreises, Radius2 ist der Radius des kleinen Kreises, pnt ist der Mittelpunkt des Torus und dir ist die Normalenrichtung. winkel1 und winkel2 sind Winkel in Grad für den kleinen Kreis; der letzte Winkelparameter besteht darin, einen Schnitt von den Torus:

torus = Part.makeTorus(10, 2)

Der obige Code erzeugt einen Torus mit Durchmesser 20 (Radius 10) und Dicke 4 (kleiner Kreisradius 2)

tor=Part.makeTorus(10, 5, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 180)

Der obige Code erzeugt eine Scheibe des Torus.

tor=Part.makeTorus(10, 5, App.Vector(0, 0, 0), App.Vector(0, 0, 1), 0, 360, 180)

Der obige Code erzeugt einen Halbtorus; nur der letzte Parameter wird geändert. d.h. die restlichen Winkel sind Standardwerte. Die Angabe des Winkels 180 bewirkt den Torus von 0 bis 180, d.h. einen halben Torus, erzeugen.

Anfang

Kasten oder Quader erstellen

Verwendung von makeBox(Länge, Breite, Höhe, [pnt, dir]). Standardmäßig werden pnt = Vektor(0, 0, 0) und dir = Vektor(0, 0, 1) verwendet.

box = Part.makeBox(10, 10, 10)
len(box.Vertexes)
> 8

Anfang

Erstelle eine Kugel

Mit makeSphere(radius, [pnt, dir, winkel1, winkel2, winkel3]). Standardmäßig pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1), Winkel1 = -90, Winkel2 = 90 und Winkel3 = 360. Winkel1 und Winkel2 sind das vertikale Minimum und Maximum der Kugel, Winkel3 ist der Kugeldurchmesser.

sphere = Part.makeSphere(10)
hemisphere = Part.makeSphere(10, App.Vector(0, 0, 0), App.Vector(0, 0, 1), -90, 90, 180)

Anfang

Erstellen eines Zylinders

Verwende makeCylinder(Radius, Höhe, [pnt, dir, Winkel]). Standardmäßig pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1) und Winkel = 360.

cylinder = Part.makeCylinder(5, 20)
partCylinder = Part.makeCylinder(5, 20, App.Vector(20, 0, 0), App.Vector(0, 0, 1), 180)

Anfang

Erstellen eines Kegels

Verwendung makeCone(radius1, radius2, höhe, [pnt, dir, winkel]). Standardmäßig pnt = Vektor(0, 0, 0), dir = Vektor(0, 0, 1) und Winkel = 360.

cone = Part.makeCone(10, 0, 20)
semicone = Part.makeCone(10, 0, 20, App.Vector(20, 0, 0), App.Vector(0, 0, 1), 180)

Anfang

Formen ändern

Es gibt verschiedene Möglichkeiten, Formen zu ändern. Einige sind einfache Transformationsoperationen wie das Verschieben oder Drehen von Formen, andere sind komplexer, wie die Vereinigung und die Differenz, das Subtrahieren einer Form von einer anderen.

Anfang

Transformationsvorgänge

Verschieben einer Form

Verschieben ist das Bewegen einer Form von einem Ort zum anderen. Jede Form (Kante, Fläche, Würfel, usw...) kann auf die gleiche Weise verschoben werden:

myShape = Part.makeBox(2, 2, 2)
myShape.translate(App.Vector(2, 0, 0))

Dadurch wird die Form "myShape" um 2 Einheiten in X-Richtung verschoben.

Anfang

Drehen einer Form

Um eine Form zu drehen, muss ein Drehpunkt (auf der Achse), die (Ausrichtung der) Achse und der Drehwinkel angegeben werden:

myShape.rotate(App.Vector(0, 0, 0),App.Vector(0, 0, 1), 180)

Der obige Code dreht die Form um 180° um die Z-Achse.

Anfang

Matrix-Transformationen

Eine Matrix ist eine sehr bequeme Möglichkeit, in der 3D Welt Transformationen zu speichern. In einer einzigen Matrix können Werte für das Verschieben, Drehen und Skalieren festgelegt werden, die auf ein Objekt angewendet werden sollen. Zum Beispiel:

myMat = App.Matrix()
myMat.move(App.Vector(2, 0, 0))
myMat.rotateZ(math.pi/2)

Hinweis: FreeCAD-Matrizen arbeiten mit Bogenmaß. Außerdem können fast alle Matrix-Operationen die einen Vektor akzeptieren, auch drei Zahlen akzeptieren, so dass diese beiden Zeilen dasselbe tun:

myMat.move(2, 0, 0)
myMat.move(App.Vector(2, 0, 0))

Wenn unsere Matrix einmal festgelegt ist, können wir sie auf unsere Form anwenden. FreeCAD bietet zwei Methoden, um das zu tun: transformShape() und transformGeometry(). Der Unterschied ist, dass man bei der ersten sicher sein kann, dass keine Verformungen auftreten (siehe Skalieren einer Form unten). Wir können unsere Transformation wie folgt anwenden:

myShape.transformShape(myMat)

oder

myShape.transformGeometry(myMat)

Anfang

Skalieren einer Form

Das Skalieren einer Form ist eine gefährlichere Operation, denn im Gegensatz zum Verschieben oder Drehen kann ungleichmäßiges Skalieren (mit unterschiedlichen Werten für X, Y und Z) die Struktur der Form verändern. Beispielsweise kann das Skalieren eines Kreises, mit einem höheren Wert für horizontal als für vertikal, ihn in eine Ellipse umwandeln, die sich mathematisch ganz anders verhält. Für das Skalieren kann transformShape() nicht verwendet werden, wir müssen transformGeometry() verwenden:

myMat = App.Matrix()
myMat.scale(2, 1, 1)
myShape=myShape.transformGeometry(myMat)

Anfang

Boolesche Operationen

Differenz

Das Subtrahieren einer Form von einer anderen Form wird in FreeCAD "Differenz" genannt (engl. Cut), und so wird es gemacht:

cylinder = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
sphere = Part.makeSphere(5, App.Vector(5, 0, 0))
diff = cylinder.cut(sphere)

Anfang

Schnitt

Die Überschneidung zweier Formen, also das "gemeinsame" (engl. Common) Volumen, wird "Schnitt"(-objekt,) genannt, und so wird es gemacht:

cylinder1 = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
cylinder2 = Part.makeCylinder(3, 10, App.Vector(5, 0, -5), App.Vector(0, 0, 1))
common = cylinder1.common(cylinder2)

Anfang

Vereinigung

Das zusammenfügen von Formen wird "Vereinigung" genannt und funktioniert auf dieselbe Weise:

cylinder1 = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
cylinder2 = Part.makeCylinder(3, 10, App.Vector(5, 0, -5), App.Vector(0, 0, 1))
fuse = cylinder1.fuse(cylinder2)

Anfang

Schnittkurve

Eine "Schnittkurve" ist der Schnitt (der Hüllflächen) einer Festkörper-Form und einer ebenen Form. Rückgabeobjekt ist eine Schnittkurve, eine Verbundkurve, die aus Kanten besteht.

cylinder1 = Part.makeCylinder(3, 10, App.Vector(0, 0, 0), App.Vector(1, 0, 0))
cylinder2 = Part.makeCylinder(3, 10, App.Vector(5, 0, -5), App.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>]

Anfang

Extrusion

Extrusion ist das Bewegen einer flachen Form in eine bestimmte Richtung, und hat als Ergebnis einen Festkörper. Ein ungefüllter Kreis (circle) wird durch Verschieben zu einem Hohlzylinder (tube):

circle = Part.makeCircle(10)
tube = circle.extrude(App.Vector(0, 0, 2))

Ist der Kreis gefüllt, also eine Scheibe/Fläche (disc), erhält man einen Festkörper-Zylinder:

wire = Part.Wire(circle)
disc = Part.Face(wire)
cylinder = disc.extrude(App.Vector(0, 0, 2))

Anfang

Formen untersuchen

Du kannst die topologische Datenstruktur leicht erkunden:

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

Durch tippen der obigen Zeilen in den Python Interpreter, erhälst du eine gutes Verständnis der Struktur von Teilobjekten. Hier hat unser makeBox() Befehl eine feste Form geschaffen. Dieser Volumenkörper enthält, wie alle Teil Volumenkörper, Flächen. Flächen enthalten immer Drähte, d.h. Listen von Kanten, die die Fläche begrenzen. Jede Fläche hat mindestens einen geschlossenen Draht (sie kann mehr haben, wenn die Fläche ein Loch hat). In dem Draht können wir jede Kante einzeln betrachten, und innerhalb jeder Kante können wir siehe die Eckpunkte. Gerade Kanten haben offensichtlich nur zwei Knoten.

Anfang

Kantenanalyse

Im Falle einer Kante, die eine willkürliche Kurve ist, ist es am wahrscheinlichsten, dass du eine Diskretisierung durchführen möchtest. In FreeCAD werden die Kanten durch ihre Länge parametrisiert. Das bedeutet, dass du eine Kante/Kurve anhand ihrer Länge entlang laufen kannst:

import Part
box = Part.makeBox(100, 100, 100)
anEdge = box.Edges[0]
print(anEdge.Length)

Jetzt kannst du auf viele Eigenschaften der Kante zugreifen, indem du die Länge als Position verwendest. Das heißt, wenn die Kante 100 mm lang ist, ist die Startposition 0 und die Endposition 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)

Anfang

Verwendung einer Auswahl

Hier sehen wir nun, wie wir eine Auswahl verwenden können, die der Benutzer im Betrachter getroffen hat. Zuerst erstellen wir einen Kasten und zeigen ihn im Betrachter an.

import Part
Part.show(Part.makeBox(100, 100, 100))
Gui.SendMsgToActiveView("ViewFit")

Wähle nun einige Flächen oder Kanten aus. Mit diesem Skript kannst du über alle ausgewählten Objekte und deren Unterelemente iterieren:

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)

Wähle einige Kanten aus und dieses Skript berechnet die Länge:

length = 0.0
for o in Gui.Selection.getSelectionEx():
    for s in o.SubObjects:
        length += s.Length

print("Length of the selected edges: ", length)

Anfang

Beispiel: Die OCC Flasche

Ein typisches Beispiel, das auf der OpenCasCade Technology Website zu finden ist, ist der Bau einer Flasche. Dies ist auch eine gute Übung für FreeCAD. Wenn du unserem Beispiel unten und der OCC-Seite gleichzeitig folgst, wirst du sehen, wie gut OCC Strukturen in FreeCAD implementiert sind. Das Skript ist in der FreeCAD Installation enthalten (innerhalb des Ordners Mod/Part) und kann vom Python Interpreter durch Eintippen aufgerufen werden:

import Part
import MakeBottle
bottle = MakeBottle.makeBottle()
Part.show(bottle)

Anfang

Das Skript=

Für die Zwecke dieses Tutoriums werden wir eine reduzierte Version des Skripts in Betracht ziehen. In dieser Version wird die Flasche nicht ausgehöhlt, und der Flaschenhals wird nicht mit einem Gewinde versehen.

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)

Anfang

Detaillierte Erklärung

import FreeCAD as App
import Part, math

Wir benötigen natürlich das Modul FreeCAD und den Arbeitsbereich Part.

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)

Hier definieren wir unsere makeBottleTut Funktion. Diese Funktion kann aufgerufen werden ohne Argumente, wie wir es oben getan haben, in diesem Fall Standardwerte für Breite und Höhe, und Dicke verwendet werden. Dann definieren wir ein paar Punkte, die verwendet werden für den Aufbau unseres Basisprofils.

...
    aArcOfCircle = Part.Arc(aPnt2, aPnt3, aPnt4)
    aSegment1=Part.LineSegment(aPnt1, aPnt2)
    aSegment2=Part.LineSegment(aPnt4, aPnt5)

Hier definieren wir die Geometrie: einen Bogen, der aus drei Punkten besteht, und zwei Liniensegmente, die aus zwei Punkten bestehen.

...
    aEdge1=aSegment1.toShape()
    aEdge2=aArcOfCircle.toShape()
    aEdge3=aSegment2.toShape()
    aWire=Part.Wire([aEdge1, aEdge2, aEdge3])

Erinnerst du dich an den Unterschied zwischen Geometrie und Formen? Hier bauen wir Formen aus unserer Konstruktionsgeometrie. Drei Kanten (Kanten können gerade sein oder gebogen), dann einen Draht hergestellt aus diesen drei Kanten.

...
    aTrsf=App.Matrix()
    aTrsf.rotateZ(math.pi) # rotate around the z-axis

    aMirroredWire=aWire.copy()
    aMirroredWire.transformShape(aTrsf)
    myWireProfile=Part.Wire([aWire, aMirroredWire])

Bislang haben wir nur ein halbes Profil erstellt. Anstatt das ganze Profil zu bauen Auf die gleiche Weise können wir einfach spiegeln, was wir getan haben, und beide Hälften zusammenkleben. Zuerst erstellen wir eine Matrix. Eine Matrix ist ein sehr gebräuchlicher Weg, um Transformationen auf Objekte in der 3D Welt anzuwenden, da sie in einer Struktur alle grundlegenden Transformationen, denen 3D Objekte unterzogen werden können (Verschieben, Drehen und Skalieren) enthalten. Nachdem wir die Matrix erstellt haben, spiegeln wir sie, dann erstellen wir eine Kopie unseres Drahtes und wenden die Transformationsmatrix darauf an. Wir haben jetzt zwei Drähte, und können wir einen dritten Draht aus ihnen machen, da Drähte eigentlich Listen von Kanten sind.

...
    myFaceProfile=Part.Face(myWireProfile)
    aPrismVec=App.Vector(0, 0, myHeight)
    myBody=myFaceProfile.extrude(aPrismVec)

    myBody=myBody.makeFillet(myThickness / 12.0, myBody.Edges)

Nun, da wir einen geschlossenen Draht haben, kann er in eine Fläche verwandelt werden. Sobald wir eine Fläche haben, können wir es extrudieren. Auf diese Weise machen wir einen Festkörper. Dann wenden wir eine schöne kleine Verrundung auf unser Objekt an, weil wir uns um gutes Design kümmern, nicht wahr?

...
    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)

An diesem Punkt ist der Körper unserer Flasche hergestellt, aber wir müssen noch einen Hals schaffen. Wir stellen einen neuen Körper mit einem Zylinder her.

...
    myBody = myBody.fuse(myNeck)

Der Verschmelzungsoperation ist sehr leistungsstark. Sie kümmert sich um das Kleben, was geklebt werden muss, und entfernt Teile, die entfernt werden müssen.

...
    return myBody

Dann geben wir als Ergebnis unserer Funktion unseren Part Volumenkörper zurück.

el = makeBottleTut()
Part.show(el)

Schließlich rufen wir die Funktion auf, um das Teil tatsächlich zu erstellen und es dann sichtbar zu machen.

Anfang

Beispiel: Durchbohrter Quader

Hier ist ein vollständiges Beispiel für den Bau eines durchbohrten Quaders.

Der Aufbau erfolgt von einer Seite nach der anderen. Wenn der Würfel fertig ist, wird er durch das Durchschneiden eines Zylinders ausgehöhlt.

import FreeCAD as App
import Part, math

size = 10
poly = Part.makePolygon([(0, 0, 0), (size, 0, 0), (size, 0, size), (0, 0, size), (0, 0, 0)])

face1 = Part.Face(poly)
face2 = Part.Face(poly)
face3 = Part.Face(poly)
face4 = Part.Face(poly)
face5 = Part.Face(poly)
face6 = Part.Face(poly)
     
myMat = App.Matrix()

myMat.rotateZ(math.pi / 2)
face2.transformShape(myMat)
face2.translate(App.Vector(size, 0, 0))

myMat.rotateZ(math.pi / 2)
face3.transformShape(myMat)
face3.translate(App.Vector(size, size, 0))

myMat.rotateZ(math.pi / 2)
face4.transformShape(myMat)
face4.translate(App.Vector(0, size, 0))

myMat = App.Matrix()

myMat.rotateX(-math.pi / 2)
face5.transformShape(myMat)

face6.transformShape(myMat)               
face6.translate(App.Vector(0, 0, size))

myShell = Part.makeShell([face1, face2, face3, face4, face5, face6])   
mySolid = Part.makeSolid(myShell)

myCyl = Part.makeCylinder(2, 20)
myCyl.translate(App.Vector(size / 2, size / 2, 0))

cut_part = mySolid.cut(myCyl)

Part.show(cut_part)

Anfang

Laden und Speichern

Es gibt mehrere Möglichkeiten, deine Arbeit zu speichern. Du kannst natürlich dein FreeCAD Dokument speichern, aber Du kannst auch Part Objekte direkt in gängigen CAD Formaten wie BREP, IGS, STEP und STL speichern.

Das Speichern einer Form in einer Datei ist einfach. Es stehen die Methoden exportBrep(), exportIges(), exportStep() und exportStl() für alle Formobjekte zur Verfügung. Also, ausführen:

import Part
s = Part.makeBox(10, 10, 10)
s.exportStep("test.stp")

wird unseren Quader in eine STEP Datei gespeichert. Um eine BREP , IGES oder STEP Datei zu laden:

import Part
s = Part.Shape()
s.read("test.stp")

Um eine STEP Datei in eine IGS Datei umzuwandeln:

import Part
 s = Part.Shape()
 s.read("file.stp")       # incoming file igs, stp, stl, brep
 s.exportIges("file.igs") # outbound file igs

Anfang