Outils pour utilisateurs

Outils du site


wiki:tutoriels:freecad_python_script_building
  • *Introduction FreeCAD has been built using the programming language Python. It should be understood that the use of modeling using the Python command line is not required. However, it can be beneficial in certain circumstances: *To design surfaces/curves using a specific mathematical formula *Importing design features from other python based programs/simulations *To create macros/scripts to design parametric libraries for various parts In this tutorial we will focus on the last of the 3 circumstances. It is our goal to design a macro that allows us to create parametrically designed pullies. The basic pulley has been chosen for it's relative simplicity. Once the overall design/programming principles are understood I would like to create macros for: *Internal/External involute gears adapted to laser cutting (this is already included in the FreeCAD package *Roller Bearings for the 3Dprinting / laser cutting *Cam shafts *Screw drives In this tutorial we will be making a very simplified version of this object: STEP 1 - Setup FreeCAD for Python Script Building: When we first open FreeCAD you will not have the “Vue Rapport” nor the “Python Console”. So the first step is to learn how to activate these two menus Open the menu: Edition/Préférences/fenêtre de sortie *Select “Rediriger les messages interne Python vers la vue rapport” *Select “Rediriger les erreurs internes de Python vers la vue rapport” *Select “Appliquer” et “OK” Next we will activate the menus for the Python Console and the Vue Rapport. To do so we must: *Goto the tab menu Affichage/Panneaux *Select “Vue Rapport” *Select “Vue Combinée” *Select “Console Python” Step 2 - Basics**

Now that we have our Python Console open we will start with the very basics. We will simply create a new document named “Python_Pulley” then:

  • Create two cylinders of a diameter = D with a thickness = T
  • Space them apart along the xy plane with a distance =d
  • Create a third cylinder with a thickness =d and a diameter<D
  • Merge all objects together to create our pulley
  • Create a final cylinder with the “diameter of our axel = a” to use to create a hole traversing the entire assembly

In the Python Console we will first type:

  • doc = FreeCAD.newDocument(“Python_Pulley”)
  • this is the equivalent of using the GUI : fichier/noveau document /save as “Python_Pulley”
wiki/tutoriels/freecad_python_script_building.txt · Dernière modification: 2020/10/05 16:39 (modification externe)