# Path: trimesh/io/stl.py
# def load_stl(file_obj, file_type=None):
#     '''
#     Load an STL file from a file object.
# 
#     Arguments
#     ----------
#     file_obj: open file- like object
#     file_type: not used
# 
#     Returns
#     ----------
#     loaded: kwargs for a Trimesh constructor with keys:
#               vertices:     (n,3) float, vertices
#               faces:        (m,3) int, indexes of vertices
#               face_normals: (m,3) float, normal vector of each face
#     '''
#     # save start of file obj
#     file_pos = file_obj.tell()
#     try:
#         # check the file for a header which matches the file length
#         # if that is true, it is almost certainly a binary STL file
#         # if the header doesn't match the file length a HeaderError will be
#         # raised
#         return load_stl_binary(file_obj)
#     except HeaderError:
#         # move the file back to where it was initially
#         file_obj.seek(file_pos)
#         # try to load the file as an ASCII STL
#         # if the header doesn't match the file length a HeaderError will be
#         # raised
#         return load_stl_ascii(file_obj)


from ..io.stl import load_stl
from string import Template
from tempfile import NamedTemporaryFile
from subprocess import check_call
from os import remove

    def __init__(self,
                 meshes,
                 script):
        self.meshes = meshes
        self.script = script

    def __enter__(self):
        # windows has problems with multiple programs using open files so we close
        # them at the end of the enter call, and delete them ourselves at the
        # exit
        self.mesh_pre = [NamedTemporaryFile(suffix='.STL',
                                            mode='wb',
                                            delete=False) for i in self.meshes]
        self.mesh_post = NamedTemporaryFile(suffix='.STL',
                                            mode='rb',
                                            delete=False)
        self.script_out = NamedTemporaryFile(mode='wb',
                                             delete=False)

        # export the meshes to a temporary STL container
        for mesh, file_obj in zip(self.meshes, self.mesh_pre):
            mesh.export(file_type='stl', file_obj=file_obj.name)

        self.replacement = {
            'mesh_' + str(i): m.name for i, m in enumerate(self.mesh_pre)}
        self.replacement['mesh_pre'] = str([i.name for i in self.mesh_pre])
        self.replacement['mesh_post'] = self.mesh_post.name
        self.replacement['script'] = self.script_out.name


# Path: trimesh/io/stl.py
# def load_stl(file_obj, file_type=None):
#     '''
#     Load an STL file from a file object.
# 
#     Arguments
#     ----------
#     file_obj: open file- like object
#     file_type: not used
# 
#     Returns
#     ----------
#     loaded: kwargs for a Trimesh constructor with keys:
#               vertices:     (n,3) float, vertices
#               faces:        (m,3) int, indexes of vertices
#               face_normals: (m,3) float, normal vector of each face
#     '''
#     # save start of file obj
#     file_pos = file_obj.tell()
#     try:
#         # check the file for a header which matches the file length
#         # if that is true, it is almost certainly a binary STL file
#         # if the header doesn't match the file length a HeaderError will be
#         # raised
#         return load_stl_binary(file_obj)
#     except HeaderError:
#         # move the file back to where it was initially
#         file_obj.seek(file_pos)
#         # try to load the file as an ASCII STL
#         # if the header doesn't match the file length a HeaderError will be
#         # raised
#         return load_stl_ascii(file_obj)


# Path: trimesh/interfaces/generic.py
from ..io.stl import load_stl
from string import Template
from tempfile import NamedTemporaryFile
from subprocess import check_call
from os import remove


    def __init__(self,
                 meshes,
                 script):
        self.meshes = meshes
        self.script = script

    def __enter__(self):
        # windows has problems with multiple programs using open files so we close
        # them at the end of the enter call, and delete them ourselves at the
        # exit
        self.mesh_pre = [NamedTemporaryFile(suffix='.STL',
                                            mode='wb',
                                            delete=False) for i in self.meshes]
        self.mesh_post = NamedTemporaryFile(suffix='.STL',
                                            mode='rb',
                                            delete=False)
        self.script_out = NamedTemporaryFile(mode='wb',
                                             delete=False)

        # export the meshes to a temporary STL container
        for mesh, file_obj in zip(self.meshes, self.mesh_pre):
            mesh.export(file_type='stl', file_obj=file_obj.name)

        self.replacement = {
            'mesh_' + str(i): m.name for i, m in enumerate(self.mesh_pre)}
        self.replacement['mesh_pre'] = str([i.name for i in self.mesh_pre])
        self.replacement['mesh_post'] = self.mesh_post.name
        self.replacement['script'] = self.script_out.name


        script_text = Template(self.script).substitute(self.replacement)