Converting scad file format to stl in Python

Question:

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?

Asked By: edyvedy13

||

Answers:

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()

Answered By: a_manthey_67
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.