I copied a code in OpenSCAD to generate keychain files, and I have a variable "name" that I change to adjust the file. Now, I want to use a list of names from a "names.txt" file to export multiple files with the adjusted names.
Here is the shellscript I am currently using:
#!/bin/bash
# Check if the names.txt file exists
if [ ! -f names.txt ]; then
echo "Error: names.txt file does not exist!"
exit 1
fi
# Get the names from the names.txt file
names=$(cat names.txt)
# Generate the STL files
for name in $names; do
# Generate the STL file
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -o "$name".stl -D name="$name" generator.scad
# Check for errors
if [ $? -ne 0 ]; then
echo "Error generating STL file for $name"
exit 1
fi
done
The script seems to run correctly, but I get a warning:
WARNING: Ignoring unknown variable 'EVA' in file keychain_nametag_generator.scad, line 85
(The variable "EVA" is the first name in my list)
The OpenSCAD file starts with this line:
name = read_string();
The files are generated, but without the names. I have spent most of the night trying to fix it, but I can't figure out what's wrong.
Apparently you overlooked this in the OpenSCAD User Manual:
So you could write: