I somehow put the files @wega supplied into a repo, see here: https://github.com/shaise/FreeCAD_Sheet ... x:new_wall
At your convenience, care to weight in?shaise wrote:
Code: Select all
import Part
import BOPTools.SplitFeatures, BOPTools.JoinFeatures
def smthk(obj, foldface) :
normal = foldface.normalAt(0,0)
theVol = obj.Volume
if theVol < 0.0001:
SMError("Shape is not a real 3D-object or to small for a metal-sheet!")
else:
# Make a first estimate of the thickness
estimated_thk = theVol/(obj.Area / 2.0)
p1 = foldface.CenterOfMass
p2 = foldface.CenterOfMass + estimated_thk * -1.3 * normal
e1 = Part.makeLine(p1, p2)
thkedge = obj.common(e1)
thk = thkedge.Length
return thk
def smFold(bendR = 1.0, bendA = 90.0, kfactor = 0.45, invertbend = False, flipped = False, unfold = False,
bendlinesketch = None, selFaceNames = '', MainObject = None):
FoldShape = MainObject.Shape
foldface = FoldShape.getElement(selFaceNames[0])
normal = foldface.normalAt(0,0)
thk = smthk(FoldShape, foldface)
offset = thk / 2.0 * kfactor
tool = bendlinesketch.Shape
tool_faces = tool.extrude(normal * -thk)
#Part.show(tool_faces)
cutSolid = BOPTools.SplitAPI.slice(FoldShape, tool_faces.Faces, "Standard", 0.0)
cutface = BOPTools.SplitAPI.slice(foldface, tool.Edges, "Standard", 0.0)
sketch = tool.copy()
sketch.translate(normal * -offset)
cutface.translate(normal * -offset)
Axis = FoldShape.common(sketch)
#Part.show(Axis)
edge = Axis.Edges[0]
revAxisP = edge.valueAt(edge.FirstParameter)
revAxisV = edge.valueAt(edge.LastParameter) - edge.valueAt(edge.FirstParameter)
revAxisV.normalize()
face0 = cutface.childShapes()[0]
face1 = cutface.childShapes()[1]
face1.rotate(revAxisP, revAxisV, bendA)
#Part.show(face1)
facecommon = face1.common(tool)
#Part.show(facecommon)
if not(facecommon.Edges) :
revAxisV = revAxisV * -1
face1 = cutface.childShapes()[1]
face1.rotate(revAxisP, revAxisV, bendA)
solid0 = cutSolid.childShapes()[0]
solid1 = cutSolid.childShapes()[1]
solid1.rotate(revAxisP, revAxisV, bendA)
#Part.show(solid0)
#Part.show(solid1)
facelist = [face0, face1]
joinface = BOPTools.JoinAPI.connect(facelist)
filletedface = joinface.makeFillet(bendR + offset, joinface.Edges)
#Part.show(filletedface)
offsetfacelist = []
offsetsolidlist = []
for face in filletedface.Faces :
if str(face.Surface) != "<Plane object>" :
offsetface = face.makeOffsetShape(offset-thk, 0.0)
#Part.show(offsetface)
offsetfacelist.append(offsetface)
for face in offsetfacelist :
offsetsolid = face.makeOffsetShape(thk, 0.0, fill = True)
#Part.show(offsetsolid)
offsetsolidlist.append(offsetsolid)
if len(offsetsolidlist) > 1 :
offsetsolid = offsetsolidlist[0].multiFuse(offsetsolidlist[1:])
else :
offsetsolid = offsetsolidlist[0]
cutsolid1 = BOPTools.JoinAPI.cutout_legacy(solid0, offsetsolid, 0.0)
cutsolid2 = BOPTools.JoinAPI.cutout_legacy(solid1, offsetsolid, 0.0)
solidlist = [cutsolid1, cutsolid2, offsetsolid]
resultsolid = BOPTools.JoinAPI.connect(solidlist)
return resultsolid
base = Gui.Selection.getSelectionEx()[0].Object
face = Gui.Selection.getSelectionEx()[0].SubElementNames
sketch = Gui.Selection.getSelectionEx()[1].Object
a = smFold(bendR = 1.0, bendA = 90.0, kfactor = 0.4, bendlinesketch = sketch, selFaceNames = face, MainObject = base)
Part.show(a)
@jaisejames
Whow, thank you so much, very nice. Here is an example from the German forum section: If the sketch dimension is on 0mm it works, but if the sketch is on 2,5mm it fails, because of the hole, I guess.jaisejames wrote: ↑Sun Feb 24, 2019 2:51 pmpls see new Fold Along line code
StepsCode: Select all
import Part import BOPTools.SplitFeatures, BOPTools.JoinFeatures def smthk(obj, foldface) : normal = foldface.normalAt(0,0) theVol = obj.Volume if theVol < 0.0001: SMError("Shape is not a real 3D-object or to small for a metal-sheet!") else: # Make a first estimate of the thickness estimated_thk = theVol/(obj.Area / 2.0) p1 = foldface.CenterOfMass p2 = foldface.CenterOfMass + estimated_thk * -1.3 * normal e1 = Part.makeLine(p1, p2) thkedge = obj.common(e1) thk = thkedge.Length return thk def smFold(bendR = 1.0, bendA = 90.0, kfactor = 0.45, invertbend = False, flipped = False, unfold = False, bendlinesketch = None, selFaceNames = '', MainObject = None): FoldShape = MainObject.Shape foldface = FoldShape.getElement(selFaceNames[0]) normal = foldface.normalAt(0,0) thk = smthk(FoldShape, foldface) offset = thk / 2.0 * kfactor tool = bendlinesketch.Shape tool_faces = tool.extrude(normal * -thk) #Part.show(tool_faces) cutSolid = BOPTools.SplitAPI.slice(FoldShape, tool_faces.Faces, "Standard", 0.0) cutface = BOPTools.SplitAPI.slice(foldface, tool.Edges, "Standard", 0.0) sketch = tool.copy() sketch.translate(normal * -offset) cutface.translate(normal * -offset) Axis = FoldShape.common(sketch) #Part.show(Axis) edge = Axis.Edges[0] revAxisP = edge.valueAt(edge.FirstParameter) revAxisV = edge.valueAt(edge.LastParameter) - edge.valueAt(edge.FirstParameter) revAxisV.normalize() face0 = cutface.childShapes()[0] face1 = cutface.childShapes()[1] face1.rotate(revAxisP, revAxisV, bendA) #Part.show(face1) facecommon = face1.common(tool) #Part.show(facecommon) if not(facecommon.Edges) : revAxisV = revAxisV * -1 face1 = cutface.childShapes()[1] face1.rotate(revAxisP, revAxisV, bendA) solid0 = cutSolid.childShapes()[0] solid1 = cutSolid.childShapes()[1] solid1.rotate(revAxisP, revAxisV, bendA) #Part.show(solid0) #Part.show(solid1) facelist = [face0, face1] joinface = BOPTools.JoinAPI.connect(facelist) filletedface = joinface.makeFillet(bendR + offset, joinface.Edges) #Part.show(filletedface) offsetfacelist = [] offsetsolidlist = [] for face in filletedface.Faces : if str(face.Surface) != "<Plane object>" : offsetface = face.makeOffsetShape(offset-thk, 0.0) #Part.show(offsetface) offsetfacelist.append(offsetface) for face in offsetfacelist : offsetsolid = face.makeOffsetShape(thk, 0.0, fill = True) #Part.show(offsetsolid) offsetsolidlist.append(offsetsolid) if len(offsetsolidlist) > 1 : offsetsolid = offsetsolidlist[0].multiFuse(offsetsolidlist[1:]) else : offsetsolid = offsetsolidlist[0] cutsolid1 = BOPTools.JoinAPI.cutout_legacy(solid0, offsetsolid, 0.0) cutsolid2 = BOPTools.JoinAPI.cutout_legacy(solid1, offsetsolid, 0.0) solidlist = [cutsolid1, cutsolid2, offsetsolid] resultsolid = BOPTools.JoinAPI.connect(solidlist) return resultsolid base = Gui.Selection.getSelectionEx()[0].Object face = Gui.Selection.getSelectionEx()[0].SubElementNames sketch = Gui.Selection.getSelectionEx()[1].Object a = smFold(bendR = 1.0, bendA = 90.0, kfactor = 0.4, bendlinesketch = sketch, selFaceNames = face, MainObject = base) Part.show(a)
1. select face required to bend.
2. select sketch on that