PythonSCAD is a programmatic 3D modeling application. It allows you to turn simple code into 3D models suitable for 3D printing.
It is a fork of OpenSCAD which not only adds support for using Python as a native language, but also adds new features and improves existing ones.
- When to not use PythonSCAD
- Difference to OpenSCAD
- Installing
- Example code
- Documentation
- Building PythonSCAD from source
If you need to create complex organic shapes, animate models, or produce visual effects, PythonSCAD is not the ideal choice. You will probably be much happier using Blender or similar tools, especially for creative, visual, and animation tasks.
PythonSCAD is optimized for script-based, parametric, and engineering-oriented modeling. If you prefer a point-and-click style design approach you might want to try FreeCAD.
PythonSCAD is a direct fork of OpenSCAD and thus includes all functionality from OpenSCAD and it is closely kept in sync with it's upstream project.
This section should help you decide whether OpenSCAD or PythonSCAD is better suited for your needs.
OpenSCAD has some intentional limitations:
- variables are immutable
- file i/o is limited (you can include other OpenSCAD scripts or import graphics files for example)
- the number of iterations is limited
The intention is to prevent scripts to do bad things like reading arbitrary data from the filesystem, overwriting user files, leaking data via the internet, etc. so the script-sharing culture could be safe.
Using Python as the scripting language on the one hand lifts those limitations, but it also comes with the responsibility to carefully check code you have not written yourself.
On the plus side you have the whole Python ecosystem at your disposal. You could host your code on PyPI and use libraries developed by other people, you could use your favorite IDE, use linting tools, etc..
If you already know how to program in Python, you don't need to learn yet another domain-specific language and will feel right at home from the start.
All of this however doesn't make OpenSCAD inferior in any way. The choice to have a safe scripting language is a valid one. PythonSCAD just uses a slightly different route towards the same goal: Making 3D design fully scriptable and more accessible.
Without all the efforts and contributions of the team and the open source community towards OpenSCAD, PythonSCAD would not be possible and the authors and contributors of PythonSCAD are very grateful for that.
In PythonSCAD all solids are 1st class objects and they can easily be
a function parameter or return value. Any object doubles as a
dictionary to store arbitrary data. If you like object oriented
programming, just do so, you can even easily subclass the openscad
type.
There are many additional methods over OpenSCAD, for example fillets or the possibility of accessing single model vertices. Arrays of Objects are implicitly unioned. Together with Python's List comprehension, you can very effectively duplicate variants of your model detail in one readable line.
Finally just export your model (or model parts) by script into many supported 3D model formats.
One obvious difference is that you can us Python when programming in PythonSCAD. While part of the Python support has been merged to OpenSCAD already, not all of it is in there yet, so you probably will have a better experience when using PythonSCAD for writing models in Python.
This is especially beneficial if you have some experience in programming with Python or even other languages.
PythonSCAD follows a functional language model while OpenSCAD is closer to a descriptive language. Both have their pro's and con's.
Pre-built binaries are available at https://www.pythonscad.org/downloads.php.
You could also build PythonSCAD from source.
# Import the openscad module's contents
from openscad import *
# Create a cube and tint it red
c = cube([10, 20, 30]).color("Tomato")
# Render the cube
show(c)
Have a look at the PythonSCAD Homepage (https://pythonscad.org/tutorial/site/index.html) for a small tutorial
To build PythonSCAD from source, follow the instructions for the platform applicable to you below.
To build PythonSCAD, you need some libraries and tools. The version numbers in brackets specify the versions which have been used for development. Other versions may or may not work as well.
If you're using a newer version of Ubuntu, you can install these libraries with the built in package manager. If you're using Mac, or an older Linux/BSD, there are build scripts that download and compile the libraries from source.
Follow the instructions for the platform you're compiling on below.
- A C++ compiler supporting C++17
- cmake (3.5 ->)
- Qt (5.12 ->)
- QScintilla2 (2.9 ->)
- CGAL (5.4 ->)
- GMP (5.x)
- MPFR (3.x)
- boost (1.70 ->)
- curl (7.58 ->)
- OpenCSG (1.4.2 ->)
- GLEW (1.5.4 ->)
- Eigen (3.x)
- glib2 (2.x)
- fontconfig (2.10 -> )
- freetype2 (2.4 -> )
- harfbuzz (0.9.19 -> )
- libzip (0.10.1 -> )
- Bison (2.4 -> )
- Flex (2.5.35 -> )
- pkg-config (0.26 -> )
- double-conversion (2.0.1 -> )
- python (3.8 -> )
Install git (https://git-scm.com/) onto your system. Then run a clone:
git clone https://github.com/pythonscad/pythonscad.git
This will download the latest sources into a directory named
pythonscad
.
cd pythonscad
git submodule update --init --recursive
sudo ./scripts/uni-get-dependencies.sh
mkdir build
cd build
cmake -DEXPERIMENTAL=1 -DENABLE_PYTHON=1 -DENABLE_LIBFIVE=1 ..
make
make test
sudo make install