Fun with OpenSCAD and SolidPython

I have been thinking for a long time to get hands on with OpenSCAD. It is a programmers Solid 3D CAD modeller. Part of my python readings, I was looking for different fields or area of interest where python can be used and went through something called SolidPython. It  is a python frontend for solid modelling that compiles to OpenSCAD. Cool I quickly installed both the packages.

sudo apt-get install openscad

sudo pip install solidpython

I played around an example code and got a cube working. The code is here I will explain how I created the model
end of the blog

#! /usr/bin/env python
# -*- coding: UTF-8 -*-
from __future__ import division
import os, sys, re

from solid import *
from solid.utils import *
from solid import screw_thread

def assembly():
   c = cube(10)
   return  c

if __name__ == '__main__':
   out_dir = sys.argv[1] if len(sys.argv) > 1 else os.curdir
   file_out = os.path.join( out_dir, 'cube.scad')

   a = assembly()
   print(%(__file__)s: SCAD file written to: \n%(file_out)s %vars())
   scad_render_to_file( a, file_out, include_orig_code=True)














I will explain how I created the cube model as shown above.
Save the python code and execute it as follows

$ python SCAD file written to:

This will generate cube.scad file.

Now run the OpenSCAD and open the cube.scad and type ‘F5’ or in the menu Design->Compile.
You will get this output.

3 thoughts on “Fun with OpenSCAD and SolidPython

  • January 19, 2017 at 4:16 am

    Your source is corrupted by the web format. E.g. “==” is missing at line 15 and line 19 makes no sense.

    • January 19, 2017 at 4:16 am

      Correction, the “>” is missing at line 15 (the screenshot helps!)

      • February 12, 2017 at 7:48 pm

        Thank you, Its corrected now.


Leave a Reply

Your email address will not be published. Required fields are marked *