def TDPyTest(): path = os.path.dirname(os.path.abspath(__file__)) print('TDPy path: ' + path) FreeCAD.newDocument("TDPy") FreeCAD.setActiveDocument("TDPy") FreeCAD.ActiveDocument = FreeCAD.getDocument("TDPy") direction = FreeCAD.Vector(0.0, 1.0, 0.0) box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box") result = TechDraw.project( box.Shape, direction) #visible hard & smooth, hidden hard & smooth print("project result: {0}".format(result)) # Part.show(result[0]) result = TechDraw.projectEx( box.Shape, direction) #visible & hidden hard, smooth, seam, outline, iso print("projectEx result: {0}".format(result)) # Part.show(result[0]) SVGResult = TechDraw.projectToSVG(box.Shape, direction, "ShowHiddenLines", 0.10) #SVG string print("SVG result: {0}".format(SVGResult)) result = TechDraw.projectToDXF(box.Shape, direction) #DXF string print("DXF result: {0}".format(result)) result = TechDraw.removeSvgTags(SVGResult) print("remove tags result: {0}".format(result))
def computeAreas(self,obj): """Compute the area, perimeter length, and volume of the terrain shape. Compute the area of the terrain projected onto an XY hyperplane, IE: the area of the terrain if viewed from a birds eye view. Compute the length of the perimeter of this birds eye view area. Compute the volume of the terrain that needs to be subtracted and added on account of the Additions and Subtractions to the site. Assign these values to their respective site properties. """ if not obj.Shape: return if obj.Shape.isNull(): return if not obj.Shape.isValid(): return if not obj.Shape.Faces: return if not hasattr(obj,"Perimeter"): # check we have a latest version site return if not obj.Terrain: return # compute area fset = [] for f in obj.Shape.Faces: if f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1)) < 1.5707: fset.append(f) if fset: import TechDraw, Part pset = [] for f in fset: try: pf = Part.Face(Part.Wire(TechDraw.project(f,FreeCAD.Vector(0,0,1))[0].Edges)) except Part.OCCError: # error in computing the area. Better set it to zero than show a wrong value if obj.ProjectedArea.Value != 0: print("Error computing areas for ",obj.Label) obj.ProjectedArea = 0 else: pset.append(pf) if pset: self.flatarea = pset.pop() for f in pset: self.flatarea = self.flatarea.fuse(f) self.flatarea = self.flatarea.removeSplitter() if obj.ProjectedArea.Value != self.flatarea.Area: obj.ProjectedArea = self.flatarea.Area # compute perimeter lut = {} for e in obj.Shape.Edges: lut.setdefault(e.hashCode(),[]).append(e) l = 0 for e in lut.values(): if len(e) == 1: # keep only border edges l += e[0].Length if l: if obj.Perimeter.Value != l: obj.Perimeter = l # compute volumes if obj.Terrain.Shape.Solids: shapesolid = obj.Terrain.Shape.copy() else: shapesolid = obj.Terrain.Shape.extrude(obj.ExtrusionVector) addvol = 0 subvol = 0 for sub in obj.Subtractions: subvol += sub.Shape.common(shapesolid).Volume for sub in obj.Additions: addvol += sub.Shape.cut(shapesolid).Volume if obj.SubtractionVolume.Value != subvol: obj.SubtractionVolume = subvol if obj.AdditionVolume.Value != addvol: obj.AdditionVolume = addvol