I am using openscad commands on Ubuntu linux to generate models from command line. I finaly was successful at running openscad commands using the -D parameters to override variables values :
$ openscad -o output.stl -D 'param1="name1"' -D 'param2="name2"' openscad-script.scad
EDIT: Notice the way we have to pass -D parameters, both single quotes and double quotes have to be there according to the because the Openscad documentation.
But when I generate & execute the same command from a shell script, openscad fails with error :
$ ./myscript.sh value1 value2
ERROR: Parser error in line XX: syntax error Can't parse file 'openscad-script.scad'!
Where XX = last line of file.
Here is the bash script
#!/bin/bash
# run openscad command
param1="-D 'param1=\"$1\"'"
param2="-D 'param2=\"$2\"'"
echo "openscad -o $1-$2.stl $param1 $param2 openscad-script.scad"
openscad -o $1-$2.stl $param1 $param2 openscad-script.scad
This looks so simple I still cannot figure out what make openscad fail at running the command.
Thanks for your help,
EDIT : I found a way to make it work, may not be the best
#!/bin/bash
# run openscad command
param1="-D 'param1=\"$1\"'"
param2="-D 'param2=\"$2\"'"
command = "openscad -o $1-$2.stl $param1 $param2 openscad-script.scad"
eval $command