#!/bin/bash
###################################
# author: Matthieu Hendriks
# date: 01-2024
# license: free to use and adept, no warranty grom the author
# title: scad2stl
# description:
# generate an STL file for every module starting with "print_"
# this is only possible on scad file whith an automatic generated run section with script scad4include
#
string=$1;			# $1 contain projectname of openscadfilename
file=${string%.*};		# skip extension
# create stl files
echo "Create stl files"
BASEDIR=$(dirname "$file");
grep module $file.scad | awk '{print $2}' | awk -F '(' '{print $1}' | while read -r line ; do

if [[  "$line" ==  "print_"* ]]; then
echo "$BASEDIR/$line";
	openscad -q --enable manifold -D 'run="'$line'"' $file.scad  -o "$BASEDIR/$line.stl"		# set run variable, run openscad and export to stl
fi

done
echo "Done STL print_module files";


