Manual:Creating and manipulating geometry/de: Difference between revisions

From FreeCAD Documentation
(Created page with "Beachte, wie wir myObj.Shape gehandhabt haben, und beachte, dass wir es genauso gemacht haben wie im vorherigen Kapitel, als wir andere Eigenschaften eines Objekts geändert h...")
(Created page with "Lasse uns nun unsere Teilformen genauer untersuchen. Am Ende des Kapitels über Manual:Traditional modeling, the CSG way/de|Traditionelle Modellierung mit dem Part Arbeitsbe...")
Line 44: Line 44:
Beachte, wie wir myObj.Shape gehandhabt haben, und beachte, dass wir es genauso gemacht haben wie im vorherigen Kapitel, als wir andere Eigenschaften eines Objekts geändert haben, z. B. box.Height = 5 . In der Tat ist '''Form''' ebenfalls eine Eigenschaft, genau wie '''Höhe'''. Nur dass sie einer Part Form und nicht eine Zahl annimmt. Im nächsten Kapitel werden wir uns genauer ansehen, wie diese parametrischen Objekte aufgebaut sind.
Beachte, wie wir myObj.Shape gehandhabt haben, und beachte, dass wir es genauso gemacht haben wie im vorherigen Kapitel, als wir andere Eigenschaften eines Objekts geändert haben, z. B. box.Height = 5 . In der Tat ist '''Form''' ebenfalls eine Eigenschaft, genau wie '''Höhe'''. Nur dass sie einer Part Form und nicht eine Zahl annimmt. Im nächsten Kapitel werden wir uns genauer ansehen, wie diese parametrischen Objekte aufgebaut sind.


For now, let's explore our Part Shapes in more detail. At the end of the chapter about [[Manual:Traditional modeling, the CSG way|traditional modeling with the Part Workbench]] we showed a table that explains how Part Shapes are constructed, and their different components (Vertices, edges, faces, etc). The exact same components exist here and can be retrieved from Python. Part Shapes always have the following attributes: Vertexes, Edges, Wires, Faces, Shells and Solids. All of them are lists, that can contain any number of elements or be empty:
Lasse uns nun unsere Teilformen genauer untersuchen. Am Ende des Kapitels über [[Manual:Traditional modeling, the CSG way/de|Traditionelle Modellierung mit dem Part Arbeitsbereich]] haben wir eine Tabelle gezeigt, die erklärt, wie Part Formen konstruiert werden und aus welchen Komponenten sie bestehen (Knoten, Kanten, Flächen, usw.). Die gleichen Komponenten sind auch hier vorhanden und können über Python abgerufen werden. Part Formen haben immer die folgenden Attribute: Knoten, Kanten, Drähte, Flächen, Schalen und Volumenkörper. Alle sind Listen, die eine beliebige Anzahl von Elementen enthalten oder leer sein können:


{{Code|code=
{{Code|code=

Revision as of 10:53, 22 August 2021

In den vorangegangenen Kapiteln haben wir die verschiedenen Arbeitsbereiche von FreeCAD kennengelernt, und wie jede von ihnen ihre eigenen Werkzeuge und Geometrietypen implementiert. Das gleiche Konzept gilt für die Arbeit mit Python Code.

Wir haben auch gesehen, dass die große Mehrheit der FreeCAD Arbeitsbereiche von einem sehr grundlegenden Arbeitsbereich abhängt: dem Part Arbeitsbereich. Tatsächlich tun viele andere Arbeitsbereiche, wie z.B. Entwurf und Architektur, genau das, was wir in diesem Kapitel tun werden: Python Code verwenden, um Part Geometrie zu erstellen und handzuhaben.

Das erste, was wir tun müssen, um mit der Formteil Geometrie zu arbeiten, ist das Python Äquivalent zum Wechsel zum Part Arbeitsbereich: Importiere das Part Modul:

import Part

Nimm dir eine Minute Zeit, um den Inhalt des Part Moduls zu erkunden, indem du Part eingibst und die verschiedenen verfügbaren Methoden durchgehst. Das Part Modul bietet mehrere praktische Funktionen wie makeBox, makeCircle usw., die dir sofort ein Objekt erstellen. Probiere zum Beispiel dies aus:

Part.makeBox(3,5,7)

Wenn du nach der Eingabe der obigen Zeile die Eingabetaste drückst, wird in der 3D Ansicht nichts angezeigt, aber auf der Python Konsole wird etwas wie das Folgende ausgegeben

<Solid object at 0x5f43600>

An dieser Stelle kommt ein wichtiges Konzept zum Tragen. Was wir hier erstellt haben, ist eine Part Form. Es handelt sich (noch) nicht um ein FreeCAD Dokumentenobjekt. In FreeCAD sind Objekte und ihre Geometrie unabhängig. Stelle dir ein FreeCAD Dokumentenobjekt als einen Behälter vor, der eine Form beherbergt. Parametrische Objekte haben auch Eigenschaften wie Länge und Breite und berechnen ihre Form "spontan" neu, wenn sich eine der Eigenschaften ändert. Wir haben hier eine Form manuell berechnet.

Wir können nun ganz einfach ein "unspezifisches" Dokumentobjekt im aktuellen Dokument erstellen (stelle sicher, dass du mindestens ein neues Dokument geöffnet hast) und ihm eine Kastenform wie die eben erstellte gibst:

boxShape = Part.makeBox(3,5,7)
 myObj = FreeCAD.ActiveDocument.addObject("Part::Feature","MyNewBox")
 myObj.Shape = boxShape
 FreeCAD.ActiveDocument.recompute()

Beachte, wie wir myObj.Shape gehandhabt haben, und beachte, dass wir es genauso gemacht haben wie im vorherigen Kapitel, als wir andere Eigenschaften eines Objekts geändert haben, z. B. box.Height = 5 . In der Tat ist Form ebenfalls eine Eigenschaft, genau wie Höhe. Nur dass sie einer Part Form und nicht eine Zahl annimmt. Im nächsten Kapitel werden wir uns genauer ansehen, wie diese parametrischen Objekte aufgebaut sind.

Lasse uns nun unsere Teilformen genauer untersuchen. Am Ende des Kapitels über Traditionelle Modellierung mit dem Part Arbeitsbereich haben wir eine Tabelle gezeigt, die erklärt, wie Part Formen konstruiert werden und aus welchen Komponenten sie bestehen (Knoten, Kanten, Flächen, usw.). Die gleichen Komponenten sind auch hier vorhanden und können über Python abgerufen werden. Part Formen haben immer die folgenden Attribute: Knoten, Kanten, Drähte, Flächen, Schalen und Volumenkörper. Alle sind Listen, die eine beliebige Anzahl von Elementen enthalten oder leer sein können:

print(boxShape.Vertexes)
 print(boxShape.Edges)
 print(boxShape.Wires)
 print(boxShape.Faces)
 print(boxShape.Shells)
 print(boxShape.Solids)

For example, let's find the area of each face of our box shape above:

for f in boxShape.Faces:
   print(f.Area)

Or, for each edge, its start point and end point:

for e in boxShape.Edges:
   print("New edge")
   print("Start point:")
   print(e.Vertexes[0].Point)
   print("End point:")
   print(e.Vertexes[1].Point)

As you see, if our boxShape has a "Vertexes" attribute, each Edge of the boxShape also has a "Vertexes" attribute. As we can expect, the boxShape will have 8 vertices, while the edge will only have 2, which are both part of the list of 8.

We can always check what is the type of a shape:

print(boxShape.ShapeType)
 print(boxShape.Faces[0].ShapeType)
 print(boxShape.Vertexes[2].ShapeType)

So to resume the topic of Part Shapes: Everything starts with Vertices. With one or two vertices, you form an Edge (full circles have only one vertex). With one or more Edges, you form a Wire. With one or more closed Wires, you form a Face (the additional Wires become "holes" in the Face). With one or more Faces, you form a Shell. When a Shell is fully closed (watertight), you can form a Solid from it. And finally, you can join any number of Shapes of any types together, which is then called a Compound.

We can now try creating complex shapes from scratch, by constructing all their components one by one. For example, let's try to create a volume like this:

We will start by creating a planar shape like this:

First, let's create the four base points:

V1 = FreeCAD.Vector(0,10,0)
 V2 = FreeCAD.Vector(30,10,0)
 V3 = FreeCAD.Vector(30,-10,0)
 V4 = FreeCAD.Vector(0,-10,0)

Then we can create the two linear segments:

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

Note that we didn't need to create Vertices. We could immediately create Part.LineSegments from FreeCAD Vectors. This is because here we haven't created Edges yet. A Part.LineSegment (as well as Part.Circle, Part.Arc, Part.Ellipse or Part.BSpline) does not create an Edge, but rather a base geometry on which an Edge will be created. Edges are always made from such a base geometry, which is stored in its Curve attribute. So if you have an Edge, doing:

print(Edge.Curve)

will show you what kind of Edge it is, i.e. if it's based on a line, an arc, etc... But let's come back to our exercise, and build the arc segments. For this, we will need a third point, so we can use the convenient Part.Arc, which takes 3 points:

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

Now we have 2 lines (L1 and L2) and 2 arcs (C1 and C2). We need to turn them into edges:

E1 = Part.Edge(L1)
 E2 = Part.Edge(L2)
 E3 = Part.Edge(C1)
 E4 = Part.Edge(C2)

Alternatively, base geometries also have a toShape() function that do exactly the same thing:

E1 = L1.toShape()
 E2 = L2.toShape()
 ...

Once we have a series of Edges, we can now form a Wire, by giving it a list of Edges. We do need to take care of the order.

W = Part.Wire([E1,E4,E2,E3])

And we can check if our Wire was correctly understood, and that it is correctly closed:

print( W.isClosed() )

Which will print "True" or "False". In order to make a Face, we need closed Wires, so it is always a good idea to check that before creating the Face. Now we can create a Face, by giving it a single Wire (or a list of Wires if we want holes):

F = Part.Face(W)

Then we extrude it:

P = F.extrude(FreeCAD.Vector(0,0,10))

Note that P is already a Solid:

print(P.ShapeType)

This is because when we extrude a single Face, we always get a Solid. This wouldn't be the case, for example, if we had extruded the Wire instead:

S = W.extrude(FreeCAD.Vector(0,0,10))
 print(s.ShapeType)

Which will of course give us a hollow shell, with the top and bottom faces missing.

Now that we have our final Shape, we are anxious to see it on screen! So let's create a generic object, and assign our new Solid to it:

myObj2 = FreeCAD.ActiveDocument.addObject("Part::Feature","My_Strange_Solid")
 myObj2.Shape = P
 FreeCAD.ActiveDocument.recompute()

Alternatively, the Part module also provides a shortcut that does the above operation quicker (but you cannot choose the name of the object):

Part.show(P)

All of the above, and much more, is explained in detail on the Part Scripting page, together with examples.

Mehr lesen: