Skip to content
Snippets Groups Projects
Commit eb0b594d authored by Campbell Barton's avatar Campbell Barton
Browse files

include blender version in STL ascii and binary, eg: Exported from Blender-2.62 (sub 3)

parent 2dcebd82
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ Import and export STL files ...@@ -23,7 +23,7 @@ Import and export STL files
Used as a blender script, it load all the stl files in the scene: Used as a blender script, it load all the stl files in the scene:
blender -P stl_utils.py -- file1.stl file2.stl file3.stl ... blender --python stl_utils.py -- file1.stl file2.stl file3.stl ...
''' '''
import struct import struct
...@@ -86,6 +86,11 @@ BINARY_HEADER = 80 ...@@ -86,6 +86,11 @@ BINARY_HEADER = 80
BINARY_STRIDE = 12 * 4 + 2 BINARY_STRIDE = 12 * 4 + 2
def _header_version():
import bpy
return "Exported from Blender-" + bpy.app.version_string
def _is_ascii_file(data): def _is_ascii_file(data):
''' '''
This function returns True if the data represents an ASCII file. This function returns True if the data represents an ASCII file.
...@@ -176,12 +181,13 @@ def _binary_write(filename, faces): ...@@ -176,12 +181,13 @@ def _binary_write(filename, faces):
# header, with correct value now # header, with correct value now
data.seek(0) data.seek(0)
data.write(struct.pack('<80sI', b"Exported from blender", nb)) data.write(struct.pack('<80sI', _header_version().encode('ascii'), nb))
def _ascii_write(filename, faces): def _ascii_write(filename, faces):
with open(filename, 'w') as data: with open(filename, 'w') as data:
data.write('solid Exported from blender\n') header = _header_version()
data.write('solid %s\n' % header)
for face in faces: for face in faces:
data.write('''facet normal 0 0 0\nouter loop\n''') data.write('''facet normal 0 0 0\nouter loop\n''')
...@@ -189,7 +195,7 @@ def _ascii_write(filename, faces): ...@@ -189,7 +195,7 @@ def _ascii_write(filename, faces):
data.write('vertex %f %f %f\n' % vert[:]) data.write('vertex %f %f %f\n' % vert[:])
data.write('endloop\nendfacet\n') data.write('endloop\nendfacet\n')
data.write('endsolid Exported from blender\n') data.write('endsolid %s\n' % header)
def write_stl(filename, faces, ascii=False): def write_stl(filename, faces, ascii=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment