def export(exportList, filename): "called when freecad exports a file" faces = [] edges = [] # getting faces and edges for ob in exportList: if ob.Shape.Faces: for f in ob.Shape.Faces: faces.append(f) else: for e in ob.Shape.Edges: edges.append(e) if not (edges or faces): print "oca: found no data to export" return # writing file oca = pythonopen(filename, 'wb') oca.write("#oca file generated from FreeCAD\r\n") oca.write("# edges\r\n") count = 1 for e in edges: if isinstance(e.Curve, Part.Line): oca.write("L" + str(count) + "=") oca.write(writepoint(e.Vertexes[0].Point)) oca.write(" ") oca.write(writepoint(e.Vertexes[-1].Point)) oca.write("\r\n") elif isinstance(e.Curve, Part.Circle): if (len(e.Vertexes) > 1): oca.write("C" + str(count) + "=ARC ") oca.write(writepoint(e.Vertexes[0].Point)) oca.write(" ") oca.write(writepoint(fcgeo.findMidpoint(e))) oca.write(" ") oca.write(writepoint(e.Vertexes[-1].Point)) else: oca.write("C" + str(count) + "= ") oca.write(writepoint(e.Curve.Center)) oca.write(" ") oca.write(str(e.Curve.Radius)) oca.write("\r\n") count += 1 oca.write("# faces\r\n") for f in faces: oca.write("A" + str(count) + "=S(POL") for v in f.Vertexes: oca.write(" ") oca.write(writepoint(v.Point)) oca.write(" ") oca.write(writepoint(f.Vertexes[0].Point)) oca.write(")\r\n") count += 1 # closing oca.close() FreeCAD.Console.PrintMessage("successfully exported " + filename)
def export(exportList,filename): "called when freecad exports a file" faces = [] edges = [] # getting faces and edges for ob in exportList: if ob.Shape.Faces: for f in ob.Shape.Faces: faces.append(f) else: for e in ob.Shape.Edges: edges.append(e) if not (edges or faces): print "oca: found no data to export" return # writing file oca = pythonopen(filename,'wb') oca.write("#oca file generated from FreeCAD\r\n") oca.write("# edges\r\n") count = 1 for e in edges: if isinstance(e.Curve,Part.Line): oca.write("L"+str(count)+"=") oca.write(writepoint(e.Vertexes[0].Point)) oca.write(" ") oca.write(writepoint(e.Vertexes[-1].Point)) oca.write("\r\n") elif isinstance(e.Curve,Part.Circle): if (len(e.Vertexes) > 1): oca.write("C"+str(count)+"=ARC ") oca.write(writepoint(e.Vertexes[0].Point)) oca.write(" ") oca.write(writepoint(fcgeo.findMidpoint(e))) oca.write(" ") oca.write(writepoint(e.Vertexes[-1].Point)) else: oca.write("C"+str(count)+"= ") oca.write(writepoint(e.Curve.Center)) oca.write(" ") oca.write(str(e.Curve.Radius)) oca.write("\r\n") count += 1 oca.write("# faces\r\n") for f in faces: oca.write("A"+str(count)+"=S(POL") for v in f.Vertexes: oca.write(" ") oca.write(writepoint(v.Point)) oca.write(" ") oca.write(writepoint(f.Vertexes[0].Point)) oca.write(")\r\n") count += 1 # closing oca.close() FreeCAD.Console.PrintMessage("successfully exported "+filename)
def snapToMidpoint(self,shape): "returns a list of midpoints snap locations" snaps = [] if self.isEnabled("midpoint"): if isinstance(shape,Part.Edge): mp = fcgeo.findMidpoint(shape) if mp: snaps.append([mp,'midpoint',mp]) return snaps
def make_curves(self): item = "" edges=[] s=Gui.Selection.getSelectionEx() for i in s: for e in i.SubElementNames: edges.append(getattr(i.Object.Shape,e)) sorted_edges = [] sorted_edges = fcgeo.sortEdges(edges) #item += '#another test after sorted_edges \n' def isSameVertex(V1, V2):#borrowed from yorik's fcgeo.py- thanks yorik! ''' Test if vertexes have same coordinates with precision 10E(-precision)''' if round(V1.X-V2.X,1)==0 and round(V1.Y-V2.Y,1)==0 and round(V1.Z-V2.Z,1)==0 : return True else : return False start=sorted_edges[0] end=sorted_edges[-1] startingZ = start.Vertexes[0].Z #set starting depth to same Z as starting curve element self.form.lineEditStartDepth.setText(str(start.Vertexes[0].Z)) item += "curve = area.Curve()\n" if isSameVertex(start.Vertexes[0],end.Vertexes[1]) : item += '#closed path\n' path = 'closedpath' else: item += '#open path\n' path = 'openpath' if path == 'openpath' : item += "curve.append(area.Point(" + str(start.Vertexes[0].X) + "," + str(start.Vertexes[0].Y)+ "))\n" for s in sorted_edges: #edges.append(s) if (isinstance(s.Curve,Part.Circle)): mp = fcgeo.findMidpoint(s) ce = s.Curve.Center tang1 = s.Curve.tangent(s.ParameterRange[0]) ; tang2 = s.Curve.tangent(s.ParameterRange[1]) cross1 = Vector.cross(Base.Vector(tang1[0][0],tang1[0][1],tang1[0][2]),Base.Vector(tang2[0][0],tang2[0][1],tang2[0][2])) if cross1[2] > 0: direct = '1 ' #we seem to be working in a rh system in FreeCAD else: direct = '-1 ' item += "curve.append(area.Vertex("+str(direct)+ ", area.Point( "+ str(s.Vertexes[-1].Point[0])+", "+str(s.Vertexes[-1].Point[1])+ "), area.Point("+str(s.Curve.Center [0])+ ", " + str(s.Curve.Center[1])+ ")))\n" elif (isinstance(s.Curve,Part.Line)): item += "curve.append(area.Point( "+str(s.Vertexes[-1].Point[0])+", " +str(s.Vertexes[-1].Point[1])+ "))\n" else: pass #export curve elements to heekscnc #to reverse the curve: #item += "curve.append(area.Point(" + str(end.Vertexes[0].X) + "," + str(end.Vertexes[0].Y) + "))" if path == 'closedpath': item += "curve.append(area.Point(" + str(start.Vertexes[1].X) + "," + str(start.Vertexes[1].Y)+ "))\n" item += "curve.Reverse()\n" self.form.textEditCurve.append(item)