Last active
July 27, 2022 22:52
-
-
Save DreamsVoid/889cc63296997996dde1319373201447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################### | |
# Nice Bash script for generating | |
# | |
# | |
# Based on this answer in StackEchange | |
# https://3dprinting.stackexchange.com/a/6048 | |
################################### | |
# Define the Image Size in Pixels | |
# Height, Width | |
# example: | |
# imageSize=4096,4096 | |
imageSize=4096,4096 | |
# Name of the Output File | |
fileOut="PartsRef" | |
#################################### | |
# Check if OpenSCAD is installed | |
echo "Checking if OpenSCAD is installed" | |
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
echo "Smells like Linux to me" | |
if which openscad >/dev/null; then | |
echo "Looks like OpenSCAD is installed, generating images" | |
openscadCommand=$(which openscad) | |
elif which openscad-nightly >/dev/null; then | |
openscadCommand=$(which openscad-nightly) | |
else | |
echo "OpenSCAD has not been installed, please install before trying this script again" | |
exit | |
fi | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
echo "This smells like a MacOS computer to me" | |
if open -Ra "OpenSCAD" ; then | |
echo "looks like OpenSCAD is installed" | |
openscadCommand="/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD" | |
else | |
echo "Please install OpenSCAD before trying to use this script" | |
exit | |
fi | |
fi | |
################################### | |
echo "Making the directory for images the OpenSCAD images" | |
mkdir -p images | |
touch $fileOut.csv | |
echo "Number, STL, Image, Dimensions, Set" >> $fileOut.csv | |
for i in *.stl; do | |
T=__tmp__$i; | |
b=`basename $i`; | |
echo import\(\"$i\"\)\; >$T; | |
$openscadCommand -o $b.png --imgsize=$imageSize -q $T --colorscheme "Tomorrow"; | |
A="$(cut -d'_' -f1 <<<"$b")"; | |
mv $b.png images/. | |
if [[ $A == 1* ]]; then | |
setName="Base Bloks" | |
elif [[ $A == 2* ]]; then | |
setName="Mechs" | |
elif [[ $A == 3* ]]; then | |
setName="Beasts" | |
elif [[ $A == 4* ]]; then | |
setName="Skyforce" | |
elif [[ $A == 8* ]]; then | |
setName="Electrobloks" | |
elif [[ $A == 9* ]]; then | |
setName="Novelty Bloks" | |
elif [[ $A == P* ]]; then | |
setName="Plated Build Set" | |
else | |
setName="TBD" | |
fi; | |
echo "$A, $i, , ,$setName" >> $fileOut.csv; | |
echo "Image for $i has been created" | |
rm $T; done | |
echo "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment