def joinFaces(objectslist): """makes one big face from selected objects, if possible""" faces = [] for obj in objectslist: faces.extend(obj.Shape.Faces) u = faces.pop(0) for f in faces: u = u.fuse(f) if DraftGeomUtils.isCoplanar(faces): u = DraftGeomUtils.concatenate(u) if not DraftGeomUtils.hasCurves(u): # several coplanar and non-curved faces: they can become a Draft wire newobj = makeWire(u.Wires[0],closed=True,face=True) else: # if not possible, we do a non-parametric union newobj = App.ActiveDocument.addObject("Part::Feature","Union") newobj.Shape = u addList.append(newobj) deleteList.extend(objectslist) return newobj return None
def execute(self, obj): import Part plm = obj.Placement if obj.Base and (not obj.Tool): if obj.Base.isDerivedFrom("Sketcher::SketchObject"): shape = obj.Base.Shape.copy() if obj.Base.Shape.isClosed(): if hasattr(obj, "MakeFace"): if obj.MakeFace: shape = Part.Face(shape) else: shape = Part.Face(shape) obj.Shape = shape elif obj.Base and obj.Tool: if hasattr(obj.Base, 'Shape') and hasattr(obj.Tool, 'Shape'): if (not obj.Base.Shape.isNull()) and ( not obj.Tool.Shape.isNull()): sh1 = obj.Base.Shape.copy() sh2 = obj.Tool.Shape.copy() shape = sh1.fuse(sh2) if DraftGeomUtils.isCoplanar(shape.Faces): shape = DraftGeomUtils.concatenate(shape) obj.Shape = shape p = [] for v in shape.Vertexes: p.append(v.Point) if obj.Points != p: obj.Points = p elif obj.Points: if obj.Points[0] == obj.Points[-1]: if not obj.Closed: obj.Closed = True obj.Points.pop() if obj.Closed and (len(obj.Points) > 2): pts = obj.Points if hasattr(obj, "Subdivisions"): if obj.Subdivisions > 0: npts = [] for i in range(len(pts)): p1 = pts[i] npts.append(pts[i]) if i == len(pts) - 1: p2 = pts[0] else: p2 = pts[i + 1] v = p2.sub(p1) v = DraftVecUtils.scaleTo( v, v.Length / (obj.Subdivisions + 1)) for j in range(obj.Subdivisions): npts.append( p1.add(App.Vector(v).multiply(j + 1))) pts = npts shape = Part.makePolygon(pts + [pts[0]]) if "ChamferSize" in obj.PropertiesList: if obj.ChamferSize.Value != 0: w = DraftGeomUtils.filletWire(shape, obj.ChamferSize.Value, chamfer=True) if w: shape = w if "FilletRadius" in obj.PropertiesList: if obj.FilletRadius.Value != 0: w = DraftGeomUtils.filletWire(shape, obj.FilletRadius.Value) if w: shape = w try: if hasattr(obj, "MakeFace"): if obj.MakeFace: shape = Part.Face(shape) else: shape = Part.Face(shape) except Part.OCCError: pass else: edges = [] pts = obj.Points[1:] lp = obj.Points[0] for p in pts: if not DraftVecUtils.equals(lp, p): if hasattr(obj, "Subdivisions"): if obj.Subdivisions > 0: npts = [] v = p.sub(lp) v = DraftVecUtils.scaleTo( v, v.Length / (obj.Subdivisions + 1)) edges.append( Part.LineSegment(lp, lp.add(v)).toShape()) lv = lp.add(v) for j in range(obj.Subdivisions): edges.append( Part.LineSegment(lv, lv.add(v)).toShape()) lv = lv.add(v) else: edges.append(Part.LineSegment(lp, p).toShape()) else: edges.append(Part.LineSegment(lp, p).toShape()) lp = p try: shape = Part.Wire(edges) except Part.OCCError: print("Error wiring edges") shape = None if "ChamferSize" in obj.PropertiesList: if obj.ChamferSize.Value != 0: w = DraftGeomUtils.filletWire(shape, obj.ChamferSize.Value, chamfer=True) if w: shape = w if "FilletRadius" in obj.PropertiesList: if obj.FilletRadius.Value != 0: w = DraftGeomUtils.filletWire(shape, obj.FilletRadius.Value) if w: shape = w if shape: obj.Shape = shape if hasattr(obj, "Area") and hasattr(shape, "Area"): obj.Area = shape.Area if hasattr(obj, "Length"): obj.Length = shape.Length obj.Placement = plm obj.positionBySupport() self.onChanged(obj, "Placement")