From c6c68f77b2b5488f174c16bf022b0ee6585d1b33 Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Fri, 21 Dec 2012 11:26:23 +0100 Subject: [PATCH] proposal for exporter --- src/Mod/OpenSCAD/exportCSG.py | 68 +++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/Mod/OpenSCAD/exportCSG.py b/src/Mod/OpenSCAD/exportCSG.py index 625d5bb4e..d7568c4ec 100644 --- a/src/Mod/OpenSCAD/exportCSG.py +++ b/src/Mod/OpenSCAD/exportCSG.py @@ -146,43 +146,49 @@ def process_object(csg,ob): print "Extrusion" print ob.Base print ob.Base.Name - #if ( ob.Base == "Part::FeaturePython" and ob.Base.Name == "Polygon") : - if ob.Base.Name.startswith("Polygon") : - f = str(ob.Base.FacesNumber) - r = str(ob.Base.Radius) - h = str(ob.Dir[2]) - print "Faces : " + f - print "Radius : " + r - print "Height : " + h - mm = check_multmatrix(csg,ob,0,0,-float(h)/2) - csg.write("cylinder($fn = "+f+", "+fafs+", h = "+h+", r1 = "+r+\ - ", r2 = "+r+", center = "+center(mm)+");\n") - if mm == 1: csg.write("}\n") + if ob.Base.isDerivedFrom('Part::Part2DObjectPython') and \ + hasattr(ob.Base,'Proxy') and hasattr(ob.Base.Proxy,'Type'): + ptype=ob.Base.Proxy.Type + if ptype == "Polygon" : + f = str(ob.Base.FacesNumber) + r = str(ob.Base.Radius) + h = str(ob.Dir[2]) + print "Faces : " + f + print "Radius : " + r + print "Height : " + h + mm = check_multmatrix(csg,ob,0,0,-float(h)/2) + csg.write("cylinder($fn = "+f+", "+fafs+", h = "+h+", r1 = "+r+\ + ", r2 = "+r+", center = "+center(mm)+");\n") + if mm == 1: csg.write("}\n") - elif ob.Base.Name.startswith("circle") : - r = str(ob.Base.Radius) - h = str(ob.Dir[2]) - print "Radius : " + r - print "Height : " + h - mm = check_multmatrix(csg,ob,0,0,-float(h)/2) - csg.write("cylinder($fn = 0, "+fafs+", h = "+h+", r1 = "+r+\ - ", r2 = "+r+", center = "+center(mm)+");\n") - if mm == 1: csg.write("}\n") - - elif ob.Base.Name.startswith("Wire") : - print "Wire extrusion" - print ob.Base - mm = check_multmatrix(csg,ob,0,0,0) - csg.write("linear_extrude(height = "+str(ob.Dir[2])+", center = "+center(mm)+", "+convexity+", twist = 0, slices = 2, $fn = 0, "+fafs+")\n{\n") - csg.write(vertexs2polygon(ob.Base.Shape.Vertexes)) - if mm == 1: csg.write("}\n") + elif ptype == "Circle" : + r = str(ob.Base.Radius) + h = str(ob.Dir[2]) + print "Radius : " + r + print "Height : " + h + mm = check_multmatrix(csg,ob,0,0,-float(h)/2) + csg.write("cylinder($fn = 0, "+fafs+", h = "+h+", r1 = "+r+\ + ", r2 = "+r+", center = "+center(mm)+");\n") + if mm == 1: csg.write("}\n") - elif ob.Base.Name.startswith("square") : + elif ptype == "Wire" : + print "Wire extrusion" + print ob.Base + mm = check_multmatrix(csg,ob,0,0,0) + csg.write("linear_extrude(height = "+str(ob.Dir[2])+", center = "+center(mm)+", "+convexity+", twist = 0, slices = 2, $fn = 0, "+fafs+")\n{\n") + csg.write(vertexs2polygon(ob.Base.Shape.Vertexes)) + if mm == 1: csg.write("}\n") + + elif ob.Base.isDerivedFrom('Part::Plane'): mm = check_multmatrix(csg,ob,0,0,0) csg.write("linear_extrude(height = "+str(ob.Dir[2])+", center = true, "+convexity+", twist = 0, slices = 2, $fn = 0, "+fafs+")\n{\n") csg.write("square (size = ["+str(ob.Base.Length)+", "+str(ob.Base.Width)+"],center = "+center(mm)+";\n}\n") if mm == 1: csg.write("}\n") - + elif ob.Base.Name.startswith('this_is_a_bad_idea'): + pass + else: + pass #There should be a fallback solution + elif ob.Type == "Part::Cut" : print "Cut" csg.write("difference() {\n")