#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?s)(ExportSTL.+?global_scale = .+?default=)(.+?),"
Local $sString = "# ##### BEGIN GPL LICENSE BLOCK #####" & @CRLF & _
"#" & @CRLF & _
"# This program is free software; you can redistribute it and/or" & @CRLF & _
"# modify it under the terms of the GNU General Public License" & @CRLF & _
"# as published by the Free Software Foundation; either version 2" & @CRLF & _
"# of the License, or (at your option) any later version." & @CRLF & _
"#" & @CRLF & _
"# This program is distributed in the hope that it will be useful," & @CRLF & _
"# but WITHOUT ANY WARRANTY; without even the implied warranty of" & @CRLF & _
"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" & @CRLF & _
"# GNU General Public License for more details." & @CRLF & _
"#" & @CRLF & _
"# You should have received a copy of the GNU General Public License" & @CRLF & _
"# along with this program; if not, write to the Free Software Foundation," & @CRLF & _
"# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA." & @CRLF & _
"#" & @CRLF & _
"# ##### END GPL LICENSE BLOCK #####" & @CRLF & _
"" & @CRLF & _
"# <pep8-80 compliant>" & @CRLF & _
"" & @CRLF & _
"bl_info = {" & @CRLF & _
" "name": "STL format"," & @CRLF & _
" "author": "Guillaume Bouchard (Guillaum)"," & @CRLF & _
" "version": (1, 1, 1)," & @CRLF & _
" "blender": (2, 74, 0)," & @CRLF & _
" "location": "File > Import-Export > Stl"," & @CRLF & _
" "description": "Import-Export STL files"," & @CRLF & _
" "warning": ""," & @CRLF & _
" "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"" & @CRLF & _
" "Scripts/Import-Export/STL"," & @CRLF & _
" "support": 'OFFICIAL'," & @CRLF & _
" "category": "Import-Export"," & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"# @todo write the wiki page" & @CRLF & _
"" & @CRLF & _
""""" & @CRLF & _
"Import-Export STL files (binary or ascii)" & @CRLF & _
"" & @CRLF & _
"- Import automatically remove the doubles." & @CRLF & _
"- Export can export with/without modifiers applied" & @CRLF & _
"" & @CRLF & _
"Issues:" & @CRLF & _
"" & @CRLF & _
"Import:" & @CRLF & _
" - Does not handle endien" & @CRLF & _
""""" & @CRLF & _
"" & @CRLF & _
"if "bpy" in locals():" & @CRLF & _
" import importlib" & @CRLF & _
" if "stl_utils" in locals():" & @CRLF & _
" importlib.reload(stl_utils)" & @CRLF & _
" if "blender_utils" in locals():" & @CRLF & _
" importlib.reload(blender_utils)" & @CRLF & _
"" & @CRLF & _
"import os" & @CRLF & _
"" & @CRLF & _
"import bpy" & @CRLF & _
"from bpy.props import (StringProperty," & @CRLF & _
" BoolProperty," & @CRLF & _
" CollectionProperty," & @CRLF & _
" EnumProperty," & @CRLF & _
" FloatProperty," & @CRLF & _
" )" & @CRLF & _
"from bpy_extras.io_utils import (ImportHelper," & @CRLF & _
" ExportHelper," & @CRLF & _
" orientation_helper_factory," & @CRLF & _
" axis_conversion," & @CRLF & _
" )" & @CRLF & _
"from bpy.types import Operator, OperatorFileListElement" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"IOSTLOrientationHelper = orientation_helper_factory("IOSTLOrientationHelper", axis_forward='Y', axis_up='Z')" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"class ImportSTL(Operator, ImportHelper, IOSTLOrientationHelper):" & @CRLF & _
" """Load STL triangle mesh data"""" & @CRLF & _
" bl_idname = "import_mesh.stl"" & @CRLF & _
" bl_label = "Import STL"" & @CRLF & _
" bl_options = {'UNDO'}" & @CRLF & _
"" & @CRLF & _
" filename_ext = ".stl"" & @CRLF & _
"" & @CRLF & _
" filter_glob = StringProperty(" & @CRLF & _
" default="*.stl"," & @CRLF & _
" options={'HIDDEN'}," & @CRLF & _
" )" & @CRLF & _
" files = CollectionProperty(" & @CRLF & _
" name="File Path"," & @CRLF & _
" type=OperatorFileListElement," & @CRLF & _
" )" & @CRLF & _
" directory = StringProperty(" & @CRLF & _
" subtype='DIR_PATH'," & @CRLF & _
" )" & @CRLF & _
"" & @CRLF & _
" global_scale = FloatProperty(" & @CRLF & _
" name="Scale"," & @CRLF & _
" soft_min=0.001, soft_max=1000.0," & @CRLF & _
" min=1e-6, max=1e6," & @CRLF & _
" default=1.0," & @CRLF & _
" )" & @CRLF & _
"" & @CRLF & _
" use_scene_unit = BoolProperty(" & @CRLF & _
" name="Scene Unit"," & @CRLF & _
" description="Apply current scene's unit (as defined by unit scale) to imported data"," & @CRLF & _
" default=False," & @CRLF & _
" )" & @CRLF & _
"" & @CRLF & _
" def execute(self, context):" & @CRLF & _
" from . import stl_utils" & @CRLF & _
" from . import blender_utils" & @CRLF & _
" from mathutils import Matrix" & @CRLF & _
"" & @CRLF & _
" paths = [os.path.join(self.directory, name.name)" & @CRLF & _
" for name in self.files]" & @CRLF & _
"" & @CRLF & _
" scene = context.scene" & @CRLF & _
"" & @CRLF & _
" # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000." & @CRLF & _
" global_scale = self.global_scale" & @CRLF & _
" if scene.unit_settings.system != 'NONE' and self.use_scene_unit:" & @CRLF & _
" global_scale /= scene.unit_settings.scale_length" & @CRLF & _
"" & @CRLF & _
" global_matrix = axis_conversion(from_forward=self.axis_forward," & @CRLF & _
" from_up=self.axis_up," & @CRLF & _
" ).to_4x4() * Matrix.Scale(global_scale, 4)" & @CRLF & _
"" & @CRLF & _
" if not paths:" & @CRLF & _
" paths.append(self.filepath)" & @CRLF & _
"" & @CRLF & _
" if bpy.ops.object.mode_set.poll():" & @CRLF & _
" bpy.ops.object.mode_set(mode='OBJECT')" & @CRLF & _
"" & @CRLF & _
" if bpy.ops.object.select_all.poll():" & @CRLF & _
" bpy.ops.object.select_all(action='DESELECT')" & @CRLF & _
"" & @CRLF & _
" for path in paths:" & @CRLF & _
" objName = bpy.path.display_name(os.path.basename(path))" & @CRLF & _
" tris, pts = stl_utils.read_stl(path)" & @CRLF & _
" blender_utils.create_and_link_mesh(objName, tris, pts, global_matrix)" & @CRLF & _
"" & @CRLF & _
" return {'FINISHED'}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"class ExportSTL(Operator, ExportHelper, IOSTLOrientationHelper):" & @CRLF & _
" """Save STL triangle mesh data from the active object"""" & @CRLF & _
" bl_idname = "export_mesh.stl"" & @CRLF & _
" bl_label = "Export STL"" & @CRLF & _
"" & @CRLF & _
" filename_ext = ".stl"" & @CRLF & _
" filter_glob = StringProperty(default="*.stl", options={'HIDDEN'})" & @CRLF & _
"" & @CRLF & _
" global_scale = FloatProperty(" & @CRLF & _
" name="Scale"," & @CRLF & _
" min=0.01, max=1000.0," & @CRLF & _
" default=1.0," & @CRLF & _
" )" & @CRLF & _
"" & @CRLF & _
" use_scene_unit = BoolProperty(" & @CRLF & _
" name="Scene Unit"," & @CRLF & _
" description="Apply current scene's unit (as defined by unit scale) to exported data"," & @CRLF & _
" default=False," & @CRLF & _
" )" & @CRLF & _
" ascii = BoolProperty(" & @CRLF & _
" name="Ascii"," & @CRLF & _
" description="Save the file in ASCII file format"," & @CRLF & _
" default=False," & @CRLF & _
" )" & @CRLF & _
" use_mesh_modifiers = BoolProperty(" & @CRLF & _
" name="Apply Modifiers"," & @CRLF & _
" description="Apply the modifiers before saving"," & @CRLF & _
" default=False," & @CRLF & _
" )" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
" def execute(self, context):" & @CRLF & _
" from . import stl_utils" & @CRLF & _
" from . import blender_utils" & @CRLF & _
" import itertools" & @CRLF & _
" from mathutils import Matrix" & @CRLF & _
" keywords = self.as_keywords(ignore=("axis_forward"," & @CRLF & _
" "axis_up"," & @CRLF & _
" "global_scale"," & @CRLF & _
" "check_existing"," & @CRLF & _
" "filter_glob"," & @CRLF & _
" "use_scene_unit"," & @CRLF & _
" "use_mesh_modifiers"," & @CRLF & _
" ))" & @CRLF & _
"" & @CRLF & _
" scene = context.scene" & @CRLF & _
"" & @CRLF & _
" # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000." & @CRLF & _
" global_scale = self.global_scale" & @CRLF & _
" if scene.unit_settings.system != 'NONE' and self.use_scene_unit:" & @CRLF & _
" global_scale *= scene.unit_settings.scale_length" & @CRLF & _
"" & @CRLF & _
" global_matrix = axis_conversion(to_forward=self.axis_forward," & @CRLF & _
" to_up=self.axis_up," & @CRLF & _
" ).to_4x4() * Matrix.Scale(global_scale, 4)" & @CRLF & _
"" & @CRLF & _
" faces = itertools.chain.from_iterable(" & @CRLF & _
" blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers)" & @CRLF & _
" for ob in context.selected_objects)" & @CRLF & _
"" & @CRLF & _
" stl_utils.write_stl(faces=faces, **keywords)" & @CRLF & _
"" & @CRLF & _
" return {'FINISHED'}" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"def menu_import(self, context):" & @CRLF & _
" self.layout.operator(ImportSTL.bl_idname, text="Stl (.stl)")" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"def menu_export(self, context):" & @CRLF & _
" default_path = os.path.splitext(bpy.data.filepath)[0] + ".stl"" & @CRLF & _
" self.layout.operator(ExportSTL.bl_idname, text="Stl (.stl)")" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"def register():" & @CRLF & _
" bpy.utils.register_module(__name__)" & @CRLF & _
"" & @CRLF & _
" bpy.types.INFO_MT_file_import.append(menu_import)" & @CRLF & _
" bpy.types.INFO_MT_file_export.append(menu_export)" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"def unregister():" & @CRLF & _
" bpy.utils.unregister_module(__name__)" & @CRLF & _
"" & @CRLF & _
" bpy.types.INFO_MT_file_import.remove(menu_import)" & @CRLF & _
" bpy.types.INFO_MT_file_export.remove(menu_export)" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"if __name__ == "__main__":" & @CRLF & _
" register()" & @CRLF & _
""
Local $sSubst = "${1}10.0,"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm