Commit 62ab2b95 authored by sumpfralle's avatar sumpfralle

r578@erker: lars | 2010-02-05 00:02:11 +0100

 added "export stl model" function


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@101 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 051cf5b7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright: 2010 by Lars Kruse <devel@sumpfralle.de>
# License: GNU GPL v3 or higher (http://www.gnu.org/licenses/gpl-3.0.txt)
#
import datetime
import os
class STLExporter:
def __init__(self, model, name="model", created_by="pycam", linesep=None):
self.model = model
self.name = name
self.created_by = created_by
if linesep is None:
self.linesep = os.linesep
else:
self.linesep = linesep
def __str__(self):
return self.linesep.join(self.get_output_lines)
def write(self, stream):
for line in self.get_output_lines():
stream.write(line)
stream.write(self.linesep)
def get_output_lines(self):
date = datetime.date.today().isoformat()
yield """solid "%s"; Produced by %s, %s""" % (self.name, self.created_by, date)
for tr in self.model._triangles:
norm = tr.normal().normalize()
yield "facet normal %f %f %f" % (norm.x, norm.y, norm.z)
yield " outer loop"
for p in (tr.p1, tr.p2, tr.p3):
yield " vertex %f %f %f" % (p.x, p.y, p.z)
yield " endloop"
yield "endfacet"
yield "endsolid"
list = [ "SimpleGCodeExporter", "SVGExporter"] list = [ "SimpleGCodeExporter", "SVGExporter", "STLExporter" ]
__all__ = list __all__ = list
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment