merge faces (again)

Need help, or want to share a macro? Post here!
Post Reply
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

merge faces (again)

Post by Cyril »

Hi,

I found many related topic but I cannot find the right way merges faces. My cases are simple. I would like to merge faces with a common edge (partial or full).
Image

Unsuccessful try
I found this old topic : face union. I made some tries using removeSplitter but no success :

Code: Select all

>>> cp = Part.Compound([doc.Face.Shape, doc.Face001.Shape])
>>> cp.removeSplitter()
<Shape object at 0x7fe3f8029580>
>>> result = cp.removeSplitter()
>>> result.Faces
[<Face object at 0x555e3c9484e0>, <Face object at 0x555e3c9cf8d0>]
Successful try but not allways merged
s1 and s2 are faces to merge

Code: Select all

>>> Part.ShapeUpgrade.UnifySameDomain(s1.fuse(s2))
<ShapeUpgrade_UnifySameDomain object>
>>> u = Part.ShapeUpgrade.UnifySameDomain(s1.fuse(s2))
>>> u.shape().Faces
[<Face object at 0x56418661fdb0>, <Face object at 0x564185fbb7c0>]
>>> u.build()
>>> u.shape().Faces
[<Face object at 0x5641826eab40>]
>>> s1.Area + s2.Area
357068.22801917716
>>> u.shape().Faces
[<Face object at 0x564186588430>]
>>> s3 = u.shape().Faces[0]
>>> s3.Area
357068.22801917745
Unfortunately I did not manage to make it always work yet. Also I don't understand all on this tool options.

Please help :D

Edits :
  • Using shape.sewShape() before using UnifySameDomain help.
  • Faces needs to be perfectly coplanar if you expect UnifySameDomain to build a single face from two or more faces.
  • Found related commit which is from this october.
  • Found more information in OCCT reference manual
  • SetLinearTolerance seems to have no effect. eg. if 2 faces have a 1 cm gap between them. Using SetLinearTolerance(10) or even 100 do not merge faces.
OS: Manjaro Linux (GNOME/gnome-xorg)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23211 (Git)
Build type: Release
Branch: master
Hash: caf30cd7ce14ebb06f11aa045e9f86ac284fa10a
Python version: 3.8.6
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: French/Switzerland (fr_CH)
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
openBrain
Veteran
Posts: 9019
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: merge faces (again)

Post by openBrain »

Did you try

Code: Select all

s1.fuse(s2)
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: merge faces (again)

Post by Cyril »

openBrain wrote: Sun Dec 13, 2020 6:59 pm Did you try

Code: Select all

s1.fuse(s2)
Yes. As describe above in the UnifySameDomain process. According to my observations fuse only create a container shape (shell, compound or else) containing fused shapes but do not actually merge 2 shapes into 1.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
mario52
Veteran
Posts: 4540
Joined: Wed May 16, 2012 2:13 pm

Re: merge faces (again)

Post by mario52 »

hi

like this ?
mergeFacesAgain.FCStd
(9.7 KiB) Downloaded 71 times

Code: Select all

import Part
comP = []
selectionObjects = FreeCADGui.Selection.getSelection()

for i in selectionObjects:
    comP.append(i.Shape)

comp = Part.makeCompound(comP)
Part.show(comp)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: merge faces (again)

Post by Cyril »

mario52 wrote: Mon Dec 14, 2020 4:58 pm hi

like this ?

mario
Thanks for suggesting but as I said. Compound is just a container. It does not merge 2 faces into 1 face. Goal is to start with 2 Part.Face and to end with 1 Part.Face (sum of areas). Why ? To simplify geometry as much as possible.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
kisolre
Veteran
Posts: 4117
Joined: Wed Nov 21, 2018 1:13 pm

Re: merge faces (again)

Post by kisolre »

Not a script but I tried drawing two touching triangles in Draft, selecting both and upgrading, applying Part/create a copy/refine shape on the result and that removed the seam. Maybe this can help?
mario52
Veteran
Posts: 4540
Joined: Wed May 16, 2012 2:13 pm

Re: merge faces (again)

Post by mario52 »

hi
Cyril wrote: Tue Dec 15, 2020 9:20 am Goal is to start with 2 Part.Face and to end with 1 Part.Face (sum of areas). Why ? To simplify geometry as much as possible.
ok
maybe with OpenSCAD2Dgeom

Code: Select all

def subtractfaces(faces):
def fusefaces(faces):
def subtractfaces2(faces):
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: merge faces (again)

Post by Cyril »

kisolre wrote: Tue Dec 15, 2020 10:06 am Not a script but I tried drawing two touching triangles in Draft, selecting both and upgrading, applying Part/create a copy/refine shape on the result and that removed the seam. Maybe this can help?
Interesting. I don't understand how it does this in source code yet but yes resulting shape contain only 1 face. It seems to run removeSplitter

Also I found out that executing upgrade twice (without using Part …) also join faces. A fixed bug report is talking about this. I found used function called joinFaces in Draft source code. They do it in a way I did not expect. I will compare this method with UnifySameDomain to see if one is giving better results.
mario52 wrote: Tue Dec 15, 2020 11:10 am maybe with OpenSCAD2Dgeom

Code: Select all

def subtractfaces(faces):
def fusefaces(faces):
def subtractfaces2(faces):
fusefaces return 2 faces (3 if they are overlapping). Other doesn't join faces neither.
I also tried OpenSCAD2Dgeom.Overlappingfaces which looked promising but did not get any good result.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
Post Reply