Remove Internal Lines from Sketch

Need help, or want to share a macro? Post here!
Post Reply
makafaka
Posts: 6
Joined: Sun May 30, 2021 9:06 pm

Remove Internal Lines from Sketch

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

Re: Remove Internal Lines from Sketch

Post by chrisb »

Moved from Developers forum. You post there if you are yourself a developer.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 4517
Joined: Thu Apr 05, 2018 1:53 am

Re: Remove Internal Lines from Sketch

Post 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 152 times
outer wire object
outer wire object
Snip macro screenshot-a516c5.png (7.96 KiB) Viewed 152 times
Post Reply