Commit 1289d3c2 authored by Guillaume Seguin's avatar Guillaume Seguin

Pythonic file handling in stlplater.export_to

parent c3799528
...@@ -314,30 +314,29 @@ class StlPlater(Plater): ...@@ -314,30 +314,29 @@ class StlPlater(Plater):
self.s.drawmodel(model, 2) self.s.drawmodel(model, 2)
def export_to(self, name): def export_to(self, name):
sf = open(name.replace(".", "_") + ".scad", "w") with open(name.replace(".", "_") + ".scad", "w") as sf:
facets = [] facets = []
for model in self.models.values(): for model in self.models.values():
r = model.rot r = model.rot
rot = [0, 0, r] if r else None rot = [0, 0, r] if r else None
o = model.offsets o = model.offsets
co = model.centeroffset co = model.centeroffset
sf.write("translate([%s, %s, %s])" sf.write("translate([%s, %s, %s])"
"rotate([0, 0, %s])" "rotate([0, 0, %s])"
"translate([%s, %s, %s])" "translate([%s, %s, %s])"
"import(\"%s\");\n" % (o[0], o[1], o[2], "import(\"%s\");\n" % (o[0], o[1], o[2],
r, r,
co[0], co[1], co[2], co[0], co[1], co[2],
model.filename)) model.filename))
if any(co): if any(co):
model = model.translate(co) model = model.translate(co)
if rot: if rot:
model = model.rotate(rot) model = model.rotate(rot)
if any(o): if any(o):
model = model.translate(o) model = model.translate(o)
facets += model.facets facets += model.facets
sf.close() stltool.emitstl(name, facets, "plater_export")
stltool.emitstl(name, facets, "plater_export") print _("Wrote plate to %s") % name
print _("Wrote plate to %s") % name
def autoplate(self, event = None): def autoplate(self, event = None):
try: try:
......
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