I think it’s @rajaa who can shed some light in this.
My suspicion is that the command version of mergeallfaces is a much more robust implementation, dealing with less obvious configurations.
Out of curiosity I scrutinized your code:
My conclusion ( correct me if I’m wrong) is:
In your code you only pair up the ‘absolute’ planar surfaces, There is no tolerance to find ‘planar enough’ faces, nor is there any tolerance in how parallel planes need to be. It’s even disregarding possible floating point errors.
Let me try to follow you code:
You test for Absolute planarity of the face
I see you create a line from the origin in the face normal direction.
Next you find where that line intersects the face plane
Next you duplicate the face edges ( this could be done via Brep.DuplicateNakedEdgeCurves as well right?) I believe there is no provision for faces with holes as that would return a list of curves.
As a final step you create a dictionary key entry unique for this plane direction and height.(does a tuple get parsed as a key? I did not know that to be possible)
In the last loop I wonder again how the BooleanUnion deals with holes in faces if they get this far at all.
In a controlled environment like grasshopper however where the possible input is well known, it’s better to use optimized code rather than generic solutions meant to catch all possible configurations.
Thanks for sharing!