FreeCAD Tips 2 : Arrange your windows

I love creating physical objects directly from Python code. This tip makes it really easy and immediate. If you use the default desktop arrangement for FreeCAD you find yourself flipping between the part view and the code view, which is a bit of a pain. So, what you do is this:

  1. Make sure that you have the code that deletes old elements on each run (see FreeCAD Tip 1).

  2. Select Windows>Tile from the main menu.

  3. Move your views of the code and the CAD workspace so that you can see them both comfortably.

  4. Now, when you run the code you will see your design update right in front of you. No need to open a different window.

This works even if you have zoomed into a particular part of the view.

FreeCAD Tips 1 : Clear your workspace

FreeCAD is a fantastic CAD program which provides access to all the drawing elements from Python. I use it a lot (I might be the only one). Perhaps I should write something all about it. For now though, here’s a tiny bit of code that’s very useful.

# Delete all existing objects in the document
for obj in doc.Objects:
    doc.removeObject(obj.Name)

This allows you replace existing code generated objects with new ones so your workspace doesn’t fill up with stuff. This is useful if you are making objects with software:

frame = Part.makeBox(width, height, depth)

The statement above makes a frame as a 3D object with a particular size. This is a 3D object, but at the moment it isn’t part of a design document. So, let’s make a document:

doc = App.ActiveDocument or App.newDocument("Frame")

This statement makes a new document called doc. Better yet, it only makes a new document if we don’t already have one. Now we can add our frame to the document:

frame_obj = doc.addObject("Part::Feature", "Frame")
frame_obj.Shape = frame

The first statement above adds a feature to the document. the second sets the shape on this feature to the frame that we created. Great stuff. But if you re-run the program you get another feature. Which you don’t want. That’s why the statements at the top are so useful. They work through the document and clear away everything so that you can add new versions.

Importing STL files into FreeCAD

One of the light leaks in my leaky camera was because the lens mount had some mounting holes in it that I’m not using. These made for some thinly printed areas which let light in. I wanted to make a modified version of the part without the holes and with a slightly larger lens opening. The problem was that I only had the file as an STL file, not in something that can be edited using FreeCAD. However, it turned out to be quite easy to import the design and then convert it into a FreeCAD model. The first thing you do is use the import dialog to bring in the STL file, select the loaded mesh and switch to the Part workbench and use the commands Part->Create Shape from mesh and then Part->Covert to solid. After that you can work with the part as you would any other.

Remember to convert at the highest possible resolution

This is powerful magic, as it means you can take any STL mesh and work with it. I’ve put the procedure in the blog so that I know where to look when I need to do it again……

FreeCad Simulator is now on GitHub

FakeFreeCad.png

I’ve made this horrible hack to make it easier to debug my Python macros that run inside FreeCad and design little boxes. It means that I can use all the lovely debugging features of Visual Studio Code to find out why my code don’t work. The hack takes the form of a few simple Python objects that fake part of the FreeCad ones and allows your macros to run in any Python environment you fancy.

If you like the idea of writing Python code that produces physical artefacts you might want to take a look at it. You can find it on GitHub here.

FreeCAD is awesome

I’m starting to really like FreeCAD. I’ve used it for years, but I’ve been cheating in that I’ve used internal Python engine to run programs that design things. However, over the last few days I’ve hit up against things that are a bit hard to do programatically, so I’ve been investigating the tool itself. It’s awesome. I can now draw paths and then use those to create curvy objects like the pipe above, which also has a cutout for the BME280 environmental sensor. And then I found that FreeCAD also supports spreadsheets.

You can bind properties in your drawing to values in a spreadsheet. So, if I want to change properties in my drawing (perhaps increase the base thickness) I just change the value in the spreadsheet and the drawing is automatically updated. Dimensions in the drawing are mapped back to the spreadsheet cells. It’s wonderful.

Making bendy pipes with FreeCAD

Achievement unlocked. I now know how to make “bendy” things in FreeCAD. It’s actually not that hard once you work out what FreeCAD needs to know. Essentially you use one Sketch to define the path of the template and another (which should be at right angles to the path) to define the closed shape to be created. You can even add another closed shape at the end of the path and then have the shape smoothly change from one to the other. I’ve used this to create tapered tubes.

I’m doing this to make another Air Quality sensor. I want to send the air path round a curve that is too tight for pipe. I also want to add a “u-bend” so that it is harder for water to get into the sensor. I’m quite pleased with the above. Now I just have to figure out how to mount it in the case….

Python output in FreeCAD

This is one of those selfish blog posts I make to remind myself how to do something that I'm bound to forget. 

But, if you're using the FreeCAD designer to run Python programs to design robots (as I am) you might find it useful. If you want to be able to print messages from your program onto the report console in FreeCAD you can the following:

App.Console.PrintMessage('hello from the program\n')

For this to work you have to have the output window options in Preferences set to Redirect internal Python output to the report view, but if you do this works a treat. My design programs can now report on progress, which is nice. 

Incidentally, I've now got a lot of experience creating solid objects from Python code using FreeCAD. If anyone would like me to do a talk on this, let me know and we can sort this out.