I want export model into stl format in ASCII, which Blender can do. However when I open the exported stl file by text, the first line is always like this:

solid Exported from Blender-2.91.2

And the last line is:

endsolid Exported from Blender-2.91.2

I want to change the string "Exported from Blender-2.91.2" to my stl file name, so I have to open my stl files again and again to change the name. This bothers me a lot and I don't know how to fixed it once and for all. I tried to open the addon folder io_mesh_stl(path:2.91\scripts\addons) and find in file stl_utils,line 75:

return "Exported from Blender-" + bpy.app.version_string

Is it because this line? How can I fix my problem? Thanks a lot if anyone can help!


1 Answer 1


Slippery Slope.

Would investigate doing this in a post pro way, Using something like sed or python, to run thru stl files and automate the bothersome edit, rather than updating the addon code.

That said, a quick edit to change the header when writing to ASCII


def _ascii_write(filepath, faces):
    from mathutils.geometry import normal

    with open(filepath, 'w') as data:
        fw = data.write
        header = _header_version()
        fw('solid %s\n' % header)

        for face in faces:
            # calculate face normal
            fw('facet normal %f %f %f\nouter loop\n' % normal(*face)[:])
            for vert in face:
                fw('vertex %f %f %f\n' % vert[:])

        fw('endsolid %s\n' % header)

change the code (circa line 205) from

header = _header_version()


header = filepath

or to hack it just to use the filepath stem "/path/foo/bar/stem.extension"

from pathlib import Path
header = Path(filepath).stem

or to hack it just to use the filname (with extension) "/path/foo/bar/filename"

from pathlib import Path
header = Path(filepath).name
  • $\begingroup$ Thanks a lot. Your solution seems working. Now it changes to my file path. However I want to change it to my file name rather than my file path. Is there any way to achieve that? $\endgroup$
    – Aidy4309
    Feb 24, 2021 at 7:42
  • $\begingroup$ Seems? Added code to add just the stem of a filepath "/path/foo/bar/stem.extension" $\endgroup$
    – batFINGER
    Feb 24, 2021 at 8:01
  • $\begingroup$ I already tried your way. What I mean is that now the stl file change to: solid C:\Users\-\Desktop\filename.stl but I want it to be: solid filename (just the file name) $\endgroup$
    – Aidy4309
    Feb 24, 2021 at 8:19
  • $\begingroup$ Thanks! I used the third way. Now it's working perfectly. The exist of extension doesn't bother me. $\endgroup$
    – Aidy4309
    Feb 24, 2021 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .