Part scripting/fr

Script
La structure de données principale utilisée dans le module Part est le type de données de OpenCascade. Presque tous les contenus et types d'objet du module Part sont disponibles à l'aide de scripts Python. Cela inclut les primitives géométriques, telles que Line et Circle (ou Arc), et toute la gamme de TopoShapes, telles que les vertex, les arêtes, les fils, les faces, les solides et les composés. Plusieurs méthodes de création existent pour chacun de ces objets. Pour certaines d’entre elles, en particulier TopoShapes, des opérations avancées telles que union booléenne/différence/intersection booléenne sont également disponibles. Explorez le contenu du module Part comme décrit dans la page Débuter avec les scripts pour en savoir plus.

Exemples
Pour créer un élément ligne, passer à la console Python et taper :

Let's go through the above python example step by step:

loads the Part module and creates a new document

Line is actually a line segment, hence the start and endpoint.

This adds a Part object type to the document and assigns the shape representation of the line segment to the 'Shape' property of the added object. It is important to understand here that we used a geometric primitive (the Part.LineSegment) to create a TopoShape out of it (the toShape method). Only Shapes can be added to the document. In FreeCAD, geometry primitives are used as "building structures" for Shapes.

Updates the document. This also prepares the visual representation of the new part object.

Note that a Line Segment can be created by specifying its start and endpoint directly in the constructor, for example Part.LineSegment(point1,point2), or we can create a default line and set its properties afterwards, as we did here.

A circle can be created in a similar way:

Note again, we used the circle (geometry primitive) to construct a shape out of it. We can of course still access our construction geometry afterwards, by doing:

Here we take the shape of our object f, then we take its list of edges. In this case there will be only one because we made the whole shape out of a single circle, so we take only the first item of the Edges list, and we takes its curve. Every Edge has a Curve, which is the geometry primitive it is based on.

Head to the Topological data scripting page if you would like to know more.