pythonfile-conversionopenscad

Converting scad file format to stl in Python


Is there a way of converting SCAD files to STL format efficiently in Python? I have around 3000 files to be converted to STL. Plus, there are some different formats.

I tried searching on the internet for some libraries but was not able to find any suitable one (I am using Windows OS) Anyone has any idea?


Solution

  • you can run openscad from command line, see documentation, and prepare every command by python (example in python3)

    from os import listdir
    from subprocess import call
    
    files = listdir('.')
    for f in files:
        if f.find(".scad") >= 0:            # get all .scad files in directory
            of = f.replace('.scad', '.stl') # name of the outfile .stl
            cmd = 'call (["openscad",  "-o", "{}",  "{}"])'.format(of, f)   #create openscad command
            exec(cmd)
    

    in python3.5 and higher subprocess.call should be replaced by subrocess.run()