Page 1 of 1

Remove Internal Lines from Sketch

Posted: Sat Jul 02, 2022 10:44 pm
by makafaka
I was wondering if there was a function that would remove lines that are inside a sketch. I am not looking for isInside() because the lines in question are part of the sketch. In other words, I need an automatic way of getting lines that form the outline of the sketch.

Example:

Here is the starting sketch

1. Image

The function would return the internal lines of the sketch or simply delete them.

2. Image

This would be the result.
3. Image

Is there an existing function or algorithm to do this?

My FreeCAD Info:

OS: Windows 10 Version 2009
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 +148 (Git)
Build type: Release
Branch: Branch_0.19.4
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.3

Re: Remove Internal Lines from Sketch

Posted: Sun Jul 03, 2022 1:25 am
by chrisb
Moved from Developers forum. You post there if you are yourself a developer.

Re: Remove Internal Lines from Sketch

Posted: Sun Jul 03, 2022 4:51 pm
by TheMarkster
Presuming the sketch contains multiple closed wires you could make each wire into its own face, then fuse the list of faces together, then refine the output (to remove extraneous edges), and take the OuterWire of the final face.

Select the sketch and press Ctrl+Shift+P. This opens the python console with a few variables created. shp is the shape of the sketch object.

Code: Select all

#get the wires
wires = shp.Wires
#make the faces
faces = [Part.makeFace(w, "Part::FaceMakerCheese") for w in wires]
#fuse the faces
fusion = faces[0].fuse(faces[1:]) #fuses the first face to the remaining faces in the list
#note: above will fail if there is only one face, in which case just use faces[0] as the final_face below
#refine fusion object to remove extra edges
refined = fusion.removeSplitter()
final_face = refined.Face1
outer_wire = final_face.OuterWire
Part.show(outer_wire,"outer_wire")
test sketch
test sketch
Snip macro screenshot-a7cf62.png (9.86 KiB) Viewed 1009 times
outer wire object
outer wire object
Snip macro screenshot-a516c5.png (7.96 KiB) Viewed 1009 times