FreeCAD Findings & Ramblings

This is our page of collected wisdom on the FreeCAD software package.

As we sought to document our accumulated work and knowledge about Maringret we came across the CAD package FreeCAD (Wikipedia article here). Described as “An Open Source parametric 3D CAD modeler” it did a lot of things that we hadn’t previously been able to do. To explain the wordy self-description:

  • Open Source
    – the source code is available without payment and can be used either in part of whole by interested parties
  • parametric
    – a series of values forms a description for an object within the system, a series of series describes a population (i.e. a model of various objects)
  • 3D
    – manipulation is performed in three dimensions at the model level and then portrayed on a 2D screen using either orthographic or perspective representation
  • CAD
    – stands for both “Computer Assisted Design” and “Computer Aided Drawing”, FreeCAD handles both
  • modeler
    – supports the use of models of the real world which exist in software and are optionally displayed on 2D screens

FreeCAD is a bit like the mythical Hydra of ancient times, the one with the multiple heads. We use this analogy in the best sense, FreeCAD has so many facets, each with substantial complexity and capability, that each facet is analogous to a head of the Hydra. Part of the challenge in using FreeCAD is to get on top of the learning curve. There isn’t really any definitive way through this maze, more the way you take, which might be noticeably different from someone else’s route. This page is our route.

In the first instance we set out with specific aims for our undertaking, aims that predated our knowledge of the existence of FreeCAD. Along the way we learned things and discovered other things, all of which were more or less related to our focus (but not always). The documentation (where it existed) was bit chaotic which was another impetus to record the things we found on this page as Google seems to find things matching a search string everywhere and so our hope was that the pieces of knowledge we accumulated would feed back into the system and be of use to others.

Our Purpose

Our intention was to document our boat project, both the factory construction and the work we had done. We had been using some 2D drawing packages with varying degrees of success. We came across FreeCAD through the internet and really only ever viewed it as anything other than a tool to achieve our goals. As will quickly become clear, the portion of FreeCAD we would expose ourselves to in a very small minority of the overall functionality of the package. This is also why we know nothing about certain parts of the package.

History of FreeCAD & Development Model

A page on the FreeCAD Wiki describes the history of the project along with the release dates. The people putting out FreeCAD are unpaid and do it in the time. they have available There is a bug tracking system located at FreeCAD Bug Tracker. Most effort for problem resolution and initial documentation is through the FreeCAD forums.

Package Profile

The modules which are divided by intended purpose are referred to as “workbenches”. There is some overlap but generally they are orthogonal. To give an example of the breadth of FreeCAD this is a list of the workbenches (with a description of the intended purpose if we know it). After the table we will talk about the workbenches we have used:

Package Purpose
Arch  architecture drawings
Draft
Drawing
Fem
Image
Inspection
Mesh Design
OpenSCAD
Part  create complex 3D shapes from 3D primitive shapes
Part Design  create 3D shapes from 2D sketches
Plot
Points
Raytracing
Reverse Engineering
Robot
Ship
Sketcher  A 2D drawing package intended to create diagrams that can then be padded or extruded which are two of the processes by which 2D drawings become 3D objects.
Spreadsheet
Start  This is a web page like starting point for information searching within FreeCAD
Test Framework A testing facility for the package itself as opposed to user created constructs
Web

From the table above, it should be obvious how capable FreeCAD is. Also it should be equally obvious how many areas we know nothing of.

Documentation Topology

FreeCAD has distributed documentation – maybe that reflects the distributed nature of the development. In first approaching the package we found it slightly confusing and are not quite sure we are on top of it yet. A lot of things we have had to ask in the forums which would have felt better being looked up in a static reference (e.g. book, web page, help file, online help). But all our queries were answered and no one seemed to mind us asking. The documentation we have found includes:

  • FreeCAD forums
  • FreeCAD Wiki
  • tutorials – these are reached via the forums or wiki
  • YouTube – search on FreeCAD
  • FreeCAD Bug Tracker

The software package which delivers the forum for FreeCAD is a bit quirky – dropping words in your search string and removing spaces used for indentation of Python code. Other users counselled us to use Google to search into the forum and other sources which is very good advice.

Before starting into this discussion, it is important to say that all comments  are based on FreeCAD version 0.14 which was released on July 1st 2014. Changes between versions can be large in different areas and so comments here may not always apply to the previous or subsequent versions.

This is the list of the tasks we figured out how to do in FreeCAD:

Import Image

  1. Switch to Image Workbench and create a new document
  2. Import image file by clicking the RH icon “Create a Planar Image in 3D Space”
  3. Select the plane for the image
  4. You now have an object which is the image file contents that may be copied/pasted to other documents

Copy/Paste Object

Objects (including hierarchies of objects) may be copied between documents (projects) by copying them in the first document, switching to another document and pasting them.

Python

The FreeCAD kernel is written in C++, most of which is wrapped in Python code. Python is an interpreted language which has been incorporated into FreeCAD. Although version 3.x of Python is released FreeCAD version 0.14 runs Python 2.7 – this is important to remember when searching through Google as there were major changes between 2.x and 3.x and some of the information on the internet pertains to Python 3.x only, but not every page is clear in defining which version it applies to. There is a Python console where interactive Python commands can be entered which then invoke the C++ functionality lying in the package. Most but not all of the functionality of FreeCAD can be accessed from Python. A page of links for Python within FreeCAD is at:

Are you looking for help regarding FreeCAD python scripting?

A simple Python example is:

  1. Open the Python console
    View->Views->Python console
    You will now see the command line prompt of “>>>”
  2. In the Python console type:help()you will now get the help file level. At this point you can start getting help on various topics.
  3. Pressing the Return key will exit the Python Help system and return you to the command line prompt of “>>>”
  4. Enter:print “Hello World”which will generate “Hello World” on the next line of the Python console

That’s about it for console, there is a wealth of information in the web pages accessible from the link above.

Macro Files

Python can be interpreted line by line through the Python console. Once a sequence of Python statements executes properly then it can be saved into a Macro file. In the future only the macro file needs to be selected and executed, the commands don’t need to be either re-typed or copied from somewhere else.

build file

toolbar

clone

development work flow (->move into a separate document)

  • prototype Python code in console in little pieces
  • once a snippet of code is working then move it to a file (TextWrangler is a good solution on the Mac, for other options on other platforms click here)
  • consolidate and save the code in the editor
  • often I build up functions and classes in one file while I put the “main” procedure into another. I then can copy the text from the functions file and paste it into the console – watching for any syntax errors. I then invoke the “main” code by using the execfile(“path and file name”)
  • a hint for finding the path to your Python source file (i.e. the one you are editing), fire up Terminal, drag the Python file and drop it on the Terminal window, Terminal will then fully expand the file path . Copy this text back to the Python console. To avoid misplacing it, I usually put this string as a comment (i.e. prefix it with a “#” character) at the top of the Python file. Then when I loose it or can’t be bothered scrolling through the console to find it again, I just copy it out of the top line of the Python file in the editor.
  • finally once everything is working I combine the two files and either paste it into the console for final testing or invoke it using the “execfile()” command – in combining file remember that the order is:
    – class definitions
    – function definitions
    – inline or “main” code
  • if the code is going to be made into a macro then
    blah
    blah can use text editor to change the xxx.FCMacro code – FreeCAD will ask if it should re-load macro code (answer Yes)
    blah
  • if it is going to be put on a toolbar then
    blah
    blah
    blah
  • the FreeCAD editor is a bit spartan (and the font is microscopically small) so if it is a quick alteration I make it in the FreeCAD editor, anything bigger I open the macro for editing, select all the text, copy, paste it in the external editor (TextWrangler for us) and perform the edits. Test can be made by saving the file and using “execfile()” or creating a new macro and running that.

part of the problem is that the editor can not access the FreeCAD routines (which are the main activity) and once the

http://stackoverflow.com/questions/tagged/python


© The contents of this site are the copyright property of the authors.  Visitors may read, copy, or print any material for their own use, free of charge.  No material printed or copied from this site, electronically or in any other form, may be sold or included in any work to be sold without explicit permission from the authors.