5
$\begingroup$

I need to add some simple image renders of STL files to a document. I currently open the STL files in Preview or one of the slicers and grab a screen shot.

Is there an easier or automatic way to generate PNG images from STL files on a Mac?

$\endgroup$
  • $\begingroup$ The answer below sounds pretty good, so I'll just comment that Google turns up a number of options for generating postscript files from STL, and you should be able to convert those to other image formats. I'm not sure how lossy that transition would be (and it'll vary by tool), but figured I'd mention it in case someone comes here looking for e.g. a non-Mac solution... $\endgroup$ – A C May 30 '18 at 2:31
7
$\begingroup$

If you have OpenSCAD installed, this shell script will generate 100x100 pixel PNG images for each STL file in your current directory.

for i in *.stl; do
  T=__tmp__$i
  b=`basename $i`
  echo import\(\"$i\"\)\; >$T
  /Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -o $b.png --imgsize=100,100 $T
  rm $T
done

Credit to 0scar for pointing out STL files can be imported into OpenSCAD.

Update: This code does the same, and generates an html file with annotated images of the files rendered. When I printed a batch of spare parts for my 3D printer I made a hardcopy and stuck it in the box so I could identify the parts later.

n=-1
H=00-catalog.html
echo >$H '<table>'
echo >>$H '  <tr>'
for i in $*; do
  n=`expr $n + 1`
  if test $n = 4; then
      n=0
      echo >>$H '  </tr>'
      echo >>$H '  <tr>'
  fi
  echo $i
  T=__tmp__$i
  B=`basename $i .stl`
  echo import\(\"$i\"\)\; >$T
  /Applications/OpenSCAD.app//Contents/MacOS/OpenSCAD -o $B.png --imgsize=200,200 $T
  echo >>$H
  echo >>$H '    <td>'$i'<br><img src="'$B'.png"></td>'

  rm $T
done
echo >>$H '  </tr>'
echo >>$H '</table>'
| improve this answer | |
$\endgroup$
3
$\begingroup$

Typically you would install a (free) 3D model program as Fusion 360, FreeCAD, or many more options to choose from. Once installed, import the STL file and use menu options to export a picture of your STL.

Alternatively, if you have some programming skills, you could import the STL file in OpenSCAD and render and export a picture from there. Simply create an OpenSCAD file with the code line below and it will import your example.stl.

import("example.stl", convexity=10);

Through the menu you can then export the view to an image. Note that you can do that also from the command line as shown by the OP's own answer (nice example of command line usage of OpenSCAD).

These are not the only options, there are many more. E.g. this is a nice example. It also describes how Thingiverse.com does STL to web image.

| improve this answer | |
$\endgroup$
2
$\begingroup$

If you don't mind using screen grabs, you could use AppleScript or whatever it's called in the latest MacOS versions to build an automated script to open each file, grab screen, save, etc.

| improve this answer | |
$\endgroup$
1
$\begingroup$

You can use OpenSCAD, as stated in the accepted answer. Here is a version of that script that works for Windows for anyone who needs it, as I did.

# Change height and width to the desired output image dimensions, in pixels.
# The path to openscad.exe may also have to be adjusted based on your installation.

height=1080
width=1080

for i in *.stl; do
  T=__tmp__$i
  b=`basename "$i"`
  echo import\(\"./$i\"\)\; > "$T"
  C:/'Program Files'/OpenSCAD/openscad.exe -o "$b".png --autocenter --viewall --imgsize=$width,$height "$T"
  rm "$T"
done
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.