mesh2img.py is a Python script for Blender that converts STL and PLY mesh files into images.
- Convert a whole directory of mesh files into images for easy previewing
- Specify multiple sets of dimensions and image formats for each mesh file (a 200x200 jpg and an 800x600 png per mesh? no problem)
- No dependencies other than Blender 2.5+ and its bundled Python 3 interpreter.
- For easy usage, make sure your Blender directory is in your operating system's PATH variable.
- Place this Python script anywhere
- Use
blender -P /path/to/mesh2img.py
to execute. See Usage below for more details.
# Don't do this
$ python mesh2img.py # doesn't work
Because this Python script is not meant to be called directly, but rather by Blender's built-in Python interpreter, you must execute the script like this:
/path/to/blender -b -P /path/to/mesh2img.py -- [mesh2img.py arguments here]
- The
-b
flag will tell Blender not to launch the user interface and operate only here on the command line. - The
-P
flag gives Blender a path to a Python script. That's what this is! - The
--
in the middle tells Blender to not look at the rest of the flags. They're only for mesh2img.py at this point. - Some
mesh2img.py
arguments are covered below
After this runs, each mesh file will have a PNG in the same folder with the same name and _200
appended to it.
blender -b -P mesh2img.py -- --paths /all/my/meshes_folder --dimensions 200
blender -b -P mesh2img.py -- --paths /some/mesh/file.stl --dimensions 200 800,600 2048 -i jpg
blender -b -P mesh2img.py -- --paths /some/mesh/file.stl --dimensions 300 -m gold
blender -b -P mesh2img.py -- --paths /half/my/meshes "/other/meshes folder" \
--dimensions 200 -o "/some/output/folder/{exec_time}/{basename}_{width}.{ext}"
blender -b -P mesh2img.py -- --help
Several functions and the Mesh2Img class can be imported from this script into your own Python scripts. Just place this script in the same directory as your script or in the 2.XX/python/lib
folder of your Blender directory.
from mesh2img import delete_object_by_name, Mesh2Img, scale_mesh
0.1
- More testing
- More control via the command line
MIT