help on sheet metal script

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
-alex-
Veteran
Posts: 1861
Joined: Wed Feb 13, 2019 9:42 pm
Location: France

Re: help on sheet metal script

Post by -alex- »

easyw-fc wrote: Tue May 14, 2019 9:14 pm Here may PR 83
That's great. Just one word: Thanks :D
User avatar
shaise
Posts: 486
Joined: Thu Jun 11, 2015 8:11 am

Re: help on sheet metal script

Post by shaise »

jaisejames wrote: Tue Mar 19, 2019 6:37 am ping
jaisejames,

can you please look into issue #89 on sheetmetal. It looks like there is a problem: When you set a gap of X mm, you get a gap of 2X mm. It looks like the miter function returns the gap doubled
https://github.com/shaise/FreeCAD_SheetMetal/issues/89

shai
jaisejames
Posts: 384
Joined: Sat Sep 24, 2016 6:51 am

Re: help on sheet metal script

Post by jaisejames »

By Wednesday, I can check.

We can change x+ y to max(x,y) line 356 & 357. While adding x + y gap 5 + 5 become 10. So that May be the problem.
User avatar
-alex-
Veteran
Posts: 1861
Joined: Wed Feb 13, 2019 9:42 pm
Location: France

Re: help on sheet metal script

Post by -alex- »

easyw-fc wrote: Sun Apr 28, 2019 6:52 pm
-alex- wrote: Sun Apr 28, 2019 7:56 am please find here the model.
WIP with peripheral fillets and invalid tolerance values ;)

phpBB [video]


-
3D-shell-sloped-sheet-metal-v2.FCStd
Hi Maurice!
I'm back again about your fix PR 83
This was a great fix, but it involved a minor drawback though: with full 3D sheet metal parts like this 3D-shell-sloped-sheet-metal-v2.FCStd peripheral filets are transformed to Bsplines in unfold outline sketch.
However arcs would be better for Gcode export purpose IMHO.
As you know it's possible to get arcs from Bspline in sketches, like with this macro for eg.
Would you mind to include such behavior in the sheet metal unfold tool? As an integrated post-process maybe? As an option maybe as well?
What's your opinion about that?
Thanks for your kind attention.
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: help on sheet metal script

Post by easyw-fc »

-alex- wrote: Wed Apr 21, 2021 10:25 pm Would you mind to include such behavior in the sheet metal unfold tool? As an integrated post-process maybe? As an option maybe as well?
Hi @-alex-
I have adapted the macro code to cover most the user case of SM wb. It could be just integrated as an extra button to simplify the sketches.

Code: Select all

# -*- coding: utf-8 -*-
''' Approximation of wires containing bezier curves by arcs '''

import FreeCAD
from DraftGeomUtils import geomType
import Draft

def cleanedges(splines, precision):
    '''cleanedges([splines],precision). Convert BSpline curves, Beziers, to arcs that can be used for cnc paths.
    Returns Lines as is. Filters Circle and Arcs for over 180 degrees. Discretizes Ellipses. Ignores other geometry. '''
    edges = []
    for spline in splines:
        if geomType(spline) == "BSplineCurve":
            arcs = spline.Curve.toBiArcs(precision)
            for i in arcs:
                edges.append(Part.Edge(i))

        elif geomType(spline) == "BezierCurve":
            newspline = spline.Curve.toBSpline()
            arcs = newspline.toBiArcs(precision)
            for i in arcs:
                edges.append(Part.Edge(i))

        elif geomType(spline) == "Ellipse":
            edges.append(Part.makePolygon(spline.discretize(QuasiDeflection=precision/2)))  # fixme hardcoded value
            # edges = curvetowire(spline, 1.0)  # fixme hardcoded value

        elif geomType(spline) == "Circle":
            # arcs = PathUtils.filterArcs(spline)
            # for i in arcs:
            #     edges.append(Part.Edge(i))
            edges.append(spline)

        elif geomType(spline) == "Line":
            edges.append(spline)

        elif geomType(spline) == "LineSegment":
            edges.append(spline)

        else:
            pass

    return edges

def shape2Sketch(shape, label):
    # replace shape.edges with arcs
    global test
    newEdges = cleanedges(shape.Edges,0.2)
    # for i in newEdges:
    #   s=Part.Edge(i)
    #   Part.show(s)
    # wire = Part.Wire([Part.Edge(i) for i in newEdges])
    # sketch = Draft.makeSketch(wire,autoconstraints=True,delete=True)
    sketch = Draft.makeSketch(newEdges,autoconstraints=True,delete=True)
    sketch.Label = label + '_simplified'
  
selection = FreeCADGui.Selection.getSelectionEx()
for s in selection:
    need2symplify = False
    for e in s.Object.Shape.Edges:
        if geomType(e) == "BSplineCurve" or geomType(e) == "BezierCurve" or geomType(e) == "Ellipse":
            need2symplify = True
    if need2symplify:
        shape2Sketch(s.Object.Shape,s.Object.Label)
        print (s.Object.Label, "simplified")
        s.Object.Visibility=False
    else:
        print (s.Object.Label, "not needed to be simplified")
FreeCAD.ActiveDocument.recompute()
User avatar
-alex-
Veteran
Posts: 1861
Joined: Wed Feb 13, 2019 9:42 pm
Location: France

Re: help on sheet metal script

Post by -alex- »

easyw-fc wrote: Fri Apr 23, 2021 1:21 pm I have adapted the macro code to cover most the user case of SM wb. It could be just integrated as an extra button to simplify the sketches.
Thanks for this improvement, works great :-D
Ok, I'll add a custom shortcut to use it.
Thanks again Maurice
Post Reply