help on sheet metal script
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 384
- Joined: Sat Sep 24, 2016 6:51 am
Re: help on sheet metal script
Seems to be some precision issue with part 3d offset. if I change Length from 20 to 21 or 19, it works. If I changes thickness to 1.001 or any other value, offset is success. No much idea why it is happening.
Re: help on sheet metal script
A topic came up in the german subforum regarding bend along sketch line.
It looks like that this feature was somewhere developed but did not find it's way into master.
@wega found the code and merged it into master here: https://forum.freecadweb.org/viewtopic. ... 20#p288098 (not in git)
Would be nice to see this feature in the master. Is the code sitting somewhere, waiting to be merged?
It looks like that this feature was somewhere developed but did not find it's way into master.
@wega found the code and merged it into master here: https://forum.freecadweb.org/viewtopic. ... 20#p288098 (not in git)
Would be nice to see this feature in the master. Is the code sitting somewhere, waiting to be merged?
Re: help on sheet metal script
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Re: help on sheet metal script
I somehow put the files @wega supplied into a repo, see here: https://github.com/shaise/FreeCAD_Sheet ... x:new_wall
But some things do not work and there are three different invert options and I have no idea what they are about.
Also I found some code which will not work (grep for FIXME)
I'll create a PR and comment on the things which probably need some fixing.
Re: help on sheet metal script
At your convenience, care to weight in?shaise wrote:
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Re: help on sheet metal script
Its a nice feature, but unless most of the issues are resolved, I do not think it should be merged.
-
- Posts: 384
- Joined: Sat Sep 24, 2016 6:51 am
Re: help on sheet metal script
pls see new Fold Along line code
Steps
1. select face required to bend.
2. select sketch on that
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)
1. select face required to bend.
2. select sketch on that
- Attachments
-
- unfolded view.png (27.69 KiB) Viewed 1242 times
-
- folded view.png (21.61 KiB) Viewed 1242 times
Re: help on sheet metal script
@jaisejames
would you mind to post the FC file too?
Thanks
-
- Veteran
- Posts: 7788
- Joined: Tue Jan 07, 2014 11:10 am
- Contact:
Re: help on sheet metal script
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 pm pls 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
The hole should be deformed a little bit, like to see in my video with Creo:
https://peertube.mastodon.host/videos/w ... afe1c4eeaf
The wallthickness is 5mm, the bend radius 5mm, angle 45°.
Any idea to solve this?