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!
Post Reply
chrisb
Veteran
Posts: 54303
Joined: Tue Mar 17, 2015 9:14 am

Re: help on sheet metal script

Post by chrisb »

shaise wrote: Sat Jun 23, 2018 9:04 pm Can try selecting different faces for the unfold, then try converting to sketch?
Selecting different faces the unfold projection is always in XY plane. Is this on purpose? Converting to sketch worked in all cases (which I tried).
Attachments
Bildschirmfoto 2018-06-23 um 23.09.20.png
Bildschirmfoto 2018-06-23 um 23.09.20.png (20.31 KiB) Viewed 1750 times
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
shaise
Posts: 492
Joined: Thu Jun 11, 2015 8:11 am

Re: help on sheet metal script

Post by shaise »

Here is my file, where it failed (attached)
I have selected the outside left wall of bend005, unfold and try to draft convert to sketch.
ProjectIssue.png
ProjectIssue.png (216.69 KiB) Viewed 1747 times
Attachments
TestSheetmetalProject.FCStd
(13.71 KiB) Downloaded 47 times
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 »

shaise wrote: Sat Jun 23, 2018 8:47 pm The generated projection is a part, not a sketch. It looks like if I try to unfold by selecting a standing wall as a seed to unfold, the outcome projection can not be converted to sketch (I get a c++ error. bug?)

Thanks!
shai
Hi @shai,
please have a try with the attached file.
I have added the code to create a sketch from the projection (and I set the transparency of the Undold to 70%).
SheetMetalUnfolder.py
(64.1 KiB) Downloaded 48 times
Feel free to adapt or modify as you prefer.

Thanks again for your WB. it is very useful! :D

PS I tested fine with some old user cases:
https://forum.freecadweb.org/viewtopic. ... 10#p229329
https://forum.freecadweb.org/viewtopic. ... 40#p225073
https://forum.freecadweb.org/viewtopic. ... 20#p200544
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 »

shaise wrote: Sat Jun 23, 2018 9:35 pm Here is my file, where it failed (attached)
I have selected the outside left wall of bend005, unfold and try to draft convert to sketch.
ProjectIssue.png
Hi @shai,
I noticed your post after posting my code...
I managed to change my code to work with your example too.
SheetMetalUnfolder.py
(64.16 KiB) Downloaded 53 times
here it is.
Please have a try.
User avatar
shaise
Posts: 492
Joined: Thu Jun 11, 2015 8:11 am

Re: help on sheet metal script

Post by shaise »

Hi easyw,

No, it still have the same issue. Load the attached file, click on the left wall (the green face in the image) and perform unfold. The same error. (happens only on certain faces)
ProjectIssue1.png
ProjectIssue1.png (37.81 KiB) Viewed 1723 times
shai
Attachments
TestSheetmetalProject1.FCStd
(7.79 KiB) Downloaded 45 times
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 »

shaise wrote: Sun Jun 24, 2018 5:31 am Hi easyw,

No, it still have the same issue. Load the attached file, click on the left wall (the green face in the image) and perform unfold. The same error. (happens only on certain faces)

shai
This issue could happens also when doing the conversion through the Draft Menu 'Draft to Sketch'

Code: Select all

('[Draft.todo.commit] Unexpected error:', <class 'Base.FreeCADError'>, 'in ', <built-in method closeDialog of tuple object at 0x000001EEBAC047C8>, '(', None, ')')
It seems a bug in orienting the edges when converting the edges to the Sketch.
We could fill a bug with a simple example.

Anyway, the actual code is adding already a very useful feature :)
User avatar
shaise
Posts: 492
Joined: Thu Jun 11, 2015 8:11 am

Re: help on sheet metal script

Post by shaise »

easyw-fc wrote: Sun Jun 24, 2018 8:23 am Anyway, the actual code is adding already a very useful feature :)
Indeed This is helpful. At first I thought it will be quite complex to add the fold lines (as the unfold code is not mine, and I'm not as talented as Ulrich1a...) But it turned out to be ok.
I will now wrap up things (I want to add a task dialog, so the user can select weather to generate the sketch or not) and commit it to the main code.
Thanks for all the help with the sample code.

shai
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 »

shaise wrote: Sun Jun 24, 2018 9:06 am I will now wrap up things (I want to add a task dialog, so the user can select weather to generate the sketch or not) and commit it to the main code.
Thanks a lot!
I was trying to create a Sketch using the edges and creating the geometry, but I cannot generate correctly open Arcs...
Here my tentative:

Code: Select all

import FreeCAD, Draft, Sketcher

doc = App.ActiveDocument
edges = doc.UnfoldProjection.Shape.Edges
# doc.Shape2DView_sc.Shape.Edges #App.ActiveDocument.UnfoldProjection.Shape.Edges

usk = FreeCAD.activeDocument().addObject('Sketcher::SketchObject',"Unfold_Sketch")
for e in edges:
    print e.Curve
geo=[]
for e in edges:
    if 'Line' in str(e.Curve):
        geo.append(Part.LineSegment(e.Vertexes[0].Point,e.Vertexes[1].Point))
    elif 'Circle' in str(e.Curve):
        Radius = e.Curve.Radius
        Center = e.Curve.Center
        Axis = e.Curve.Axis
        StartAngle = e.Curve.FirstParameter
        EndAngle = e.Curve.LastParameter
        geo.append(Part.ArcOfCircle( Part.Circle(Center,Axis,Radius),StartAngle,EndAngle , False))
#print geo
usk.addGeometry(geo)
doc.recompute()
I'm attaching also the FC file
test-sketch-2.FCStd
(38.6 KiB) Downloaded 48 times
I cannot create a not closed Arc
User avatar
shaise
Posts: 492
Joined: Thu Jun 11, 2015 8:11 am

Re: help on sheet metal script

Post by shaise »

easyw-fc wrote: Sun Jun 24, 2018 3:05 pm I was trying to create a Sketch using the edges and creating the geometry, but I cannot generate correctly open Arcs...
is this to bypass the Draft.makeSketch?
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 »

shaise wrote: Sun Jun 24, 2018 9:06 am I will now wrap up things (I want to add a task dialog, so the user can select weather to generate the sketch or not) and commit it to the main code.
Hi Shai,
I've solved the issue of Arcs...
Here the code that will generate Sketches in all cases... What are not considered are BSplines.. but they shouldn't be in the generated UnfoldProjection, if I recall correctly...
SheetMetalUnfolder.py
(64.88 KiB) Downloaded 51 times
Please have a try :D
test-sketch-3.FCStd
(38.17 KiB) Downloaded 49 times
Post Reply