export-all 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. VERSION=0.1.2
  3. function ngc_position {
  4. ifn="$1"
  5. offsetx=10
  6. offsety=15
  7. if [[ "$ifn" == "" ]] ; then
  8. echo "provide file"
  9. exit 1
  10. fi
  11. dos2unix $ifn
  12. sed -i 's/;.*//' $ifn
  13. mx=`ngc_bounds $ifn | grep min_x | cut -f2 -d' '`
  14. my=`ngc_bounds $ifn | grep min_y | cut -f2 -d' '`
  15. shiftx=` echo "-($mx) + $offsetx" | bc -l`
  16. shifty=` echo "-($my) + $offsety" | bc -l`
  17. tfn=`mktemp`
  18. #echo "G0 F5000" > $tfn
  19. grecode -shift "$shiftx" "$shifty" $ifn | \
  20. grep -v '^(' >> $tfn 2> /dev/null
  21. mv $tfn $ifn
  22. rm -f $tfn
  23. }
  24. tmpfn=`mktemp`
  25. for fn in `ls ../Popufare*.scad | grep -v PopufareHousingCommon.scad ` ; do
  26. bfn=`basename $fn .scad`
  27. svg="$bfn.$VERSION.svg"
  28. svg_z="$bfn.z.$VERSION.svg"
  29. ngc="$bfn.$VERSION.ngc"
  30. echo "## $bfn"
  31. basedir=`dirname $( pwd ) `
  32. echo "include <$basedir/$bfn.scad>" > $tmpfn
  33. echo "${bfn}Plate();" >> $tmpfn
  34. openscad -o "$svg" "$tmpfn"
  35. svg2ngc "$svg" 2> /dev/null
  36. ngc_position "$ngc" 2> /dev/null
  37. sed -i 's/F800/F150/g' "$ngc"
  38. sed -i 's/G0\(.*\)S\(.*\)/G0\1 F5000 S\2/g' "$ngc"
  39. cp "$svg" "$svg_z"
  40. sed -i 's/<svg\(.*\) width="\([0-9]*\)"/<svg\1 width="\2mm"/' "$svg_z"
  41. sed -i 's/<svg\(.*\) height="\([0-9]*\)"/<svg\1 height="\2mm"/' "$svg_z"
  42. sed -i 's/ stroke-width="[^"]*"/ stroke-width=".0254"/' "$svg_z"
  43. done
  44. rm $tmpfn