billtubbs / python-occ-demos

Testing out various Python tools for generating, editing and converting CAD drawing files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python CAD scripting libraries and tools

Wanted to try out methods for generating 3D CAD drawings parametrically (i.e. programatically).

There seem to be quite a few libraries to do this and I know very little about CAD. I tested 2 or 3 here with mixed results.

pythonOCC

This library was mentioned in this stackoverflow post in 2013. It's actually a wrapper for a comprehensive CAD scripting package called OpenCASCADE C++ (hence the acronym OCC) and has been under development since 2008.

I installed it from here:

It was a bit of a pain. Had to install a few other bits and bobs (e.g. Qt5) and then it still didn't work. Had to uninstall and reinstall and then it worked.

The only documentation I could find is here and it's quite limited (parts are out of date):

However there are lots of example scripts and notebooks which seem to be up to date.

I wanted to try out the exporting of models to files. STEP(.stp), X3D and STL (.stl) seem to work, but STEP seems to be the most widely used.

However, I didn't find Python-OCC very user-friendly. I think if you are already an expert in OCC this package would be a great addition but otherwise, the learning curve is pretty steep.

CadQuery

Had one installation issue which was promptly fixed by installing with conda instead of pip, thanks to a response from the developers.

I found this quite easy to use. It is a heavily object-oriented programming library with quite high level, useful functionality such as splines and sweeps which is what I was looking for. It also has an editor so you can view your construction. In fact the python script is embedded in the editor (not run from the console on your machine), so you could say it is an IDE (integrated development environment). It also exports drawing files to STEP.

See this example script I made:

PyMesh

I also tried out PyMesh but I'm not that experienced with Docker so it took me a while to get it working. It seems to be more low-level than CADQuery and focussed on processing very complex meshes. Might be more useful for 3D printing or making 3D game objects than CAD drawings for regular manufacturing.

Open3D

Seems to be a numerical tool for automatically generating a 3D mesh out of a point cloud. See this article in Towards Data Science:

FreeCAD

I downloaded and successfully installed FreeCAD. This is a complete, open source CAD design application which happens to utilise Python for automating many operations as well as parametric modelling and design. Quite impressive, all-round CAD software application.

Documentation is here and looks comprehensive:

Here is a page introducing the Python scripting capabilities:

About

Testing out various Python tools for generating, editing and converting CAD drawing files


Languages

Language:Jupyter Notebook 90.8%Language:Python 9.2%