issue125:freecad
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue125:freecad [2017/09/30 19:18] – créée d52fr | issue125:freecad [2017/10/06 10:46] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | // En cours de traduction, allieurs | + | **In this series, we will be examining the world of FreeCAD, an open-source CAD modelling application that it still in Beta, but has been gaining acceptance in recent years. Naturally, it is readily available in the Ubuntu repositories. In the fifth article on using FreeCAD, we worked on an architectural project in two different ways. In the first place, we used the Arch workbench to create a modern architectural project, in which supplementary information is given to the computer, so using FreeCAD to create a Building Integrated Model (BIM). Since this approach is in an early stage of development, |
+ | |||
+ | In today’s part of this series, we will extend FreeCAD’s possibilities using a little Python programming to create a helicoidal surface in the shape of a mechanical gear wheel.** | ||
+ | |||
+ | Dans cette série, nous examinerons le monde de FreeCAD, une application Open Source de modélisation par CAO qui est encore en bêta, mais qui a reçu un bon accueil ces dernières années. Naturellement, | ||
+ | |||
+ | Dans la nouvelle partie de cette série, nous allons étendre les possibilités de FreeCAD en utilisant un peu de programmation en Python, pour créer une surface hélicoïdale sous la forme d'une roue dentée. | ||
+ | |||
+ | **Programming FreeCAD? And why Python? | ||
+ | |||
+ | As many readers will be aware, the world of program language implementation is divided into two main categories. There are programming languages such as C or Fortran for which the source code needs to be compiled (into our computer’s machine language) in order to be executed. There are also interpreted languages that do not need to be compiled (or “translated”, | ||
+ | |||
+ | FreeCAD has been built in Python, thus an interpreted language. This is quite convenient for several reasons. In the first place, it makes the application more easy to transport to other computer architectures and operating systems, as long as a Python interpreter is available for the desired platform - and Python is getting quite ubiquitous, indeed. In the second place, we can open a console view of FreeCAD’s inner workings by simply choosing menu option View > Views > Python console. Each action we carry out through the User interface is actually converted into Python commands the program’s core logic - and we can see it in real time in this console. If, for instance, I create a new project, switch to the Draft workbench, and draw a line, Below is what actually happens.** | ||
+ | |||
+ | Programmer dans FreeCAD ? Et pourquoi Python ? | ||
+ | |||
+ | Comme le savent de nombreux lecteurs, le monde de l' | ||
+ | |||
+ | FreeCAD est construit en Python, donc en langage interprété. C'est vraiment pratique pour plusieurs raisons. D' | ||
+ | |||
+ | **This is quite neat, since one can learn about the different commands used in an interactive way. Naturally, once one has a grasp of the fundamentals, | ||
+ | |||
+ | To take an example, let us write a simple Python script that will create a simple box shape. Create a new file called “test1.py”, | ||
+ | |||
+ | The Part library contains the tools from the Part workbench. We begin by creating a new project, called “Box Model”. We make this the active document (window), and add a new object based on the “Part:: | ||
+ | |||
+ | To execute our script, switch to a terminal window in the same directory we have the .py file, and issue command: | ||
+ | |||
+ | freecad test1.py | ||
+ | |||
+ | We will see FreeCAD start up and execute our script line-by-line, | ||
+ | |||
+ | C'est très chouette, car on peut apprendre de manière interactive les différentes commandes utilisées. Naturellement, | ||
+ | |||
+ | Pour prendre un exemple, écrivons un script simple en Python qui créera la forme d'une simple boîte. Créez un fichier nommé « test1.py » et copiez-y le code présenté en haut à droite. | ||
+ | |||
+ | La bibliothèque Part contient les outils de l' | ||
+ | |||
+ | Pour exécuter notre script, passons sur une fenêtre de terminal dans le même répertoire que celui de « test1.py » et lançons la commande : | ||
+ | |||
+ | freecad test1.py | ||
+ | |||
+ | Nous verrons FreeCAD démarrer et exécuter notre script ligne par ligne, avec le résultat final tel que montré ci-dessous. | ||
+ | |||
+ | **As a second example, let us build something slightly more complex: the shape of a tin that consists in a flat shape (two arcs connected by straight segments), that will then be extruded to form a volume. Bottom right is the script, in file “test2.py”. | ||
+ | |||
+ | Let us comment on the differences with the previous example. In this case, we begin our new object by creating four vectors V1 to V4, that indicate the positions of the connection points between the arcs and the straight lines. We then create the two straight segments, L1 and L2, and finally the two arcs C1 and C2. We then need to convert these four items into Edge objects, E1 to E4, which are then connected into a Wire object W. This is the outline of our tin’s top. Please ensure lines and arcs are set up in the correct order, otherwise connectivity errors may ensue. Finally, the Wire is converted into a bidimensional Face object F, which is then extruded into a Shape P. A generic volume is derived from “Part:: | ||
+ | |||
+ | As a final note, the finished project can be saved directly from our script, by calling the doc.saveAs procedure. When executed from the terminal, shown below is the result of our script.** | ||
+ | |||
+ | Comme second exemple, construisons quelque chose de légèrement plus complexe : la forme d'une boîte de conserve qui consiste en une forme plate (deux arcs rattachés par des segments droits) qui sera ensuite extrudée pour former un volume. En bas à droite, voici le script, dans le fichier « test2.py ». | ||
+ | |||
+ | Expliquons ce qui diffère de l' | ||
+ | |||
+ | En touche finale, l' | ||
+ | |||
+ | **Lets draw some gears | ||
+ | |||
+ | Scripting can come in useful when we need a shape that contains many similar, but different and calculable parts. In such cases, writing a program to iterate over our shapes can be cost-effective in terms of our time. A typical case is when creating a mechanical gear wheel. Such a wheel can be seen as a combination of an exterior shape, formed by a certain number of teeth or cogs, and an inner shape that delimits the axis. This can be either smooth or splined so that the axis can transfer torque to and from the wheel. Both the interior and the exterior wheel forms are formed of a basic shape or motif, that is iterated at a fixed angular offset between each individual tooth. | ||
+ | |||
+ | Let us concentrate on the exterior shape, slightly more complex than the interior splines. Each individual tooth is centered at a certain radius from the wheel center, or pitch surface. In our case, we specify a 100mm radius. Simplifying somewhat, this is the point at which the other gears connected to this one will transfer their force. Points 3 and 6 in our schematic are on this surface. Going outwards, teeth extend to an outer limit, the top flat. Points 4 and 5 are on this radius, in our case taken at 110 mm. Finally, we need to “make some space” inwards, to accommodate the other wheel’s teeth. So we go inwards to the bottom flat, at radius 90 mm in our case, and holding points 1 and 2. We will iterate this basic shape over the 16 teeth of our wheel.** | ||
+ | |||
+ | Dessinons quelques engrenages | ||
+ | |||
+ | L' | ||
+ | |||
+ | Concentrons-nous sur la forme extérieure, | ||
+ | |||
+ | **Our script (right) will simply draw a series of lines from vertices 1 through 6 of each cog, and then on to vertex 1 of the next cog. Since Python has a mathematical library “math”, sine and cosine functions can be used to calculate a pair of X and Y-axis coordinates for each vertex. The script itself is quite straightforward. As a note, in our example we are using only straight segments. However, in a real gear wheel, the bottom and top flats, and the contact faces, would more usually be drawn with arcs. | ||
+ | |||
+ | Once we have the cog shape in FreeCAD, we can continue using it “by hand” within the normal user interface, as a basis for an extrusion or any other operation we wish. With a similar script to draw the central, crenellated shape for the splines, we can extrude both the external volume of the gear wheel and the volume of the inner axle, and then use a boolean operation to cut one out of the other. We can thus obtain the shape of a traditional straight gear that would be found in many traditional applications such as a four-by-four vehicle’s transfer box. | ||
+ | |||
+ | However, straight teeth do have the disadvantage of creating quite a bit of noise during operation, since, during each rotation, each tooth engages immediately with the other gear wheel’s corresponding tooth along the complete width of the tooth. This produces the typical whining noise that can be heard from some mechanical setups. In most modern applications where smoothness of operation and low noise emissions are valued, such as vehicle gear boxes, helicoidal gears can be preferred.** | ||
+ | |||
+ | Notre script (à droite) dessinera simplement une série de lignes des sommets 1 à 6 puis vers le sommet 1 de la dent suivante. Comme Python a une bibliothèque mathématique « math », les fonctions sinus et cosinus peuvent être utilisées pour calculer une paire de coordonnées X-Y pour chaque sommet. Le script lui-même est vraiment simple. À noter : dans notre exemple, nous utilisons seulement des segments droits. Cependant, dans un engrenage réel, les surfaces de fond et sommitale et les surfaces de contact seraient le plus souvent dessinées avec des arcs. | ||
+ | |||
+ | Une fois que nous avons la forme du pignon dans FreeCAD, nous poursuivons en l' | ||
+ | |||
+ | Cependant, les dents droites ont le désavantage de créer pas mal de bruit à l' | ||
+ | |||
+ | **To draw such a gear wheel, the same tooth pattern can be used, but swept along a helicoidal path instead of using the simple linear extrusion tool. | ||
+ | |||
+ | Start, in the Part workbench, by selecting the Part > Create Primitive menu option. Here, we can select the Helix shape. Since I wished to create a gear wheel 50 mm in width, with teeth sloped at approximately 1:20 across the width of the wheel, I chose a helix height of 50 mm, but a pitch of 1000 mm between helix spires. The external radius of the helix should correspond to the point at which it will be created. Both right-handed and left-handed helices can be used, as needed. | ||
+ | |||
+ | Once the helicoidal line is drawn, it can be used as a path along which to sweep the cog’s external face, using the same tools as when creating a Gothic arch in the previous part of this series. The internal surface will be created using a linear extrusion as before, since even a helicoidal gear wheel’s internal splines tend to be straight so as to facilitate assembly of the wheel on its supporting axle. The resulting wheel is actually a fair approximation of an actual gear. Some aspects would be made better, though, such as bevelling external edges to make them less aggressive, or cutting out part of the gear wheel’s material to make it lighter and use less material in fabrication. These operations can also be done in FreeCAD, and are left as an exercise to the reader (hint: use a revolution surface to create cutouts for each face).** | ||
+ | |||
+ | Pour dessiner un tel engrenage, le même motif de dent peut être utilisé, mais il est balayé le long d'un chemin hélicoïdal plutôt qu' | ||
+ | |||
+ | Commencez, dans l' | ||
+ | |||
+ | Une fois la ligne hélicoïdale tracée, elle peut être utilisée comme chemin le long duquel la face extérieure du pignon peut être balayée, en utilisant les mêmes outils que lors de la création de l' | ||
+ | |||
+ | **What next? | ||
+ | |||
+ | In this article on using FreeCAD, we extended FreeCAD’s possibilities using a little Python programming to create a helicoidal surface in the shape of a gear wheel. Once the basic shape has been drawn using a script, it can be used in combination with any other of the techniques available from the graphical interface to create the final object. Python is a fully-developed programming suite, containing many different libraries both mathematical and for other purposes, that can be used in combination with FreeCAD to create objects that do not exist within the initial library of basic shapes. | ||
+ | |||
+ | In the next part of this series, we will concentrate on a more complex primitive object that allows us to create forms and volumes with less regularity, the mesh.** | ||
+ | |||
+ | Et ensuite ? | ||
+ | |||
+ | Dans cet article sur l' | ||
+ | |||
+ | Dans la prochaine partie de la série, nous nous concentrerons sur un objet à la primitive plus complexe qui nous permettra de créer des formes et des volumes avec moins de régularité, | ||
+ |
issue125/freecad.1506791924.txt.gz · Dernière modification : 2017/09/30 19:18 de d52fr