- Home
- Learn Linux
- Learn Electronics
- Raspberry Pi
- Programming
- Projects
- LPI certification
- News & Reviews
FreeCAD is an open source 3D design program for Linux and Windows. It can be used to design accurate 3D models suitable for 3D printing or laser cutting. If this is your first experience with FreeCAD then you could try my Getting started guide to using FreeCAD.
In addition to allowing you to manipulate your design interactively, FreeCAD also includes macro support. This is essential an API allowing you to control the model using Python programming. In this project I show how you can use this to create animations in FreeCAD, such as the one I included in my video on the Raspberry Pi Pico and Pico Wireless.
In the video I show how you can work out some of the commands to use by viewing the Python console. Here are some examples from the macros used:
FreeCAD.getDocument("rpi_pico_model_1_6").getObject(
"Body"
).Placement = App.Placement(
App.Vector(0, 0, 0), App.Rotation(App.Vector(0, 0, 1), 0)
In this the particular document is selected (note that the rpi_pico_model_1_6 is related to the filename relating to version 1.6 of the document). Then it selects the body named "Body". Note that is the original name of the body. If you rename the body then you will still need to refer to the original object name in the code. It then updates the Placement attribute which determines the position. The App.Rotation method is used to move the object based on an x,y,z vector, in this case the Z-axis.
There are lots of other functions that uses this same process, some of which also include for loops to create a smooth animation effect.
One feature I created was the ability to show and hide pins on the Pico. I achieved this by switching between and earlier position in the edit sequence to a point before I created the pins.
def hide_pins(self):
Gui.Selection.addSelection("rpi_pico_model_1_6", "Body", "LinearPattern005.")
Gui.runCommand("Std_HideSelection", 0)
Gui.Selection.addSelection("rpi_pico_model_1_6", "Body", "Pad013.")
Gui.runCommand("Std_ShowSelection", 0)
Gui.Selection.clearSelection()
In this case the past stage before I added the pins was Pad013, and the final stage after adding the pins is LinearPattern005, so I just did a hide of one and the show the other. The show_pins function does the same, but in reverse.
Note that the colouring of the object had to be repeated for each of the stages. This is because the colour is part of the UI interface and is not part of the actual model itself. This was a bit frustrating, but I haven't found a workaround other than manually recolouring the model for each stage that you want to display to the user.
The above examples are about changing the view of the FreeCAD objects, but you can also change the camera view. In this case I used Macro Rotate View Free to change the camera view. I first copied the macro into my document and then added the code.
self.RotateView (1,0,0, 10)
The implementation of Python also allows for creating a QT GUI using PySide.QtGUI. An explanation of that would go beyond what I have provided in this particular video, you can however look through the source code and it should be simple enough to add some new options using the Vertical Box Layout used in the example.
To record the animation I used Simple Screen Recorder. This is Linux software. There are alternative screen recorders for different operating systems.
FreeCAD is a very powerful CAD design tool. It includes a simple turntable which allows a very basic animation; using your own Python code provides much more flexibilty on the animation. You can even create your own GUI as I have done providing buttons that can animate a model in different ways.
If you want more powerful 3D animation software then you may want to look at my tutorials on using 3D modelling with Blender.
There are more guides to creating 3D models and use of a 3D printer at Penguintutor 3D design and 3D print projects
Also see:
To find out about the updates please:
Subscribe to the PenguinTutor YouTube Channel
and
Follow @penguintutor on Twitter
Please view the copyright information regarding use of the circuits.