Merging all coplanar faces

Merging all coplanar faces

Anonymous
Not applicable
3,497 Views
5 Replies
Message 1 of 6

Merging all coplanar faces

Anonymous
Not applicable

I've imported an STL and want to combine all coplanar faces to make working with the model easier. I can do this by switching of Capture Design History and using 'Merge' in the Patch workspace and chain selecting each face in turn.

 

Obviously this would be much nicer if it was automated but i cant find a mergeFeature in the API anywhere, is it there under a different name or is this achievable in some other way?

0 Likes
3,498 Views
5 Replies
Replies (5)
Message 2 of 6

goyals
Autodesk
Autodesk

May be you can try stitch feature.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 3 of 6

imajar
Advisor
Advisor

Same problem here:  How to merge via API - Did you figure anything out?  (stitch didnt merge any coplanar faces for me, unless I forgot to check a secret option?)

 

-Thanks


Aaron Jarrett, PE
Inventor 2019 | i7-6700K 64GB NVidia M4000
LinkedIn

Life is Good.
0 Likes
Message 4 of 6

JesusFreke
Advocate
Advocate

Here's a quick function I whipped up that seems to work for me, on a simple cylinder that I exported and then reimported as a mesh, and then converted to brep. This may require the document to be in direct mode. I didn't try it in parametric mode.

 

import traceback
import adsk.core
import adsk.fusion


def run(context):
try:
root = adsk.core.Application.get().activeProduct.rootComponent # type: adsk.fusion.Component
merge_planar_faces(root.bRepBodies[0])
except Exception:
print(traceback.format_exc())


def collection_of(collection):
object_collection = adsk.core.ObjectCollection.create()
for obj in collection:
object_collection.add(obj)
return object_collection


def merge_planar_faces(body: adsk.fusion.BRepBody):
first_temp_surface = None
temp_unioned_surface = None

brep = adsk.fusion.TemporaryBRepManager.get()

for face in body.faces:
# convert the face to a temporary BRepBody
temp_surface = brep.copy(face)
if first_temp_surface is None:
# We need at least two faces to use a stitch feature, so keep a lone copy of the first face
first_temp_surface = temp_surface
elif temp_unioned_surface is None:
# All the other faces get unioned into a single temporary BRepBody
temp_unioned_surface = temp_surface
else:
# Adds this face to the temporary BRepBody that contains all the other faces
brep.booleanOperation(temp_unioned_surface, temp_surface, adsk.fusion.BooleanTypes.UnionBooleanType)

# Now stitch the first face, and all the remaining faces together, into a single solid body
# This has the side effect of merging any coplanar faces that share an edge
surfaces = [body.parentComponent.bRepBodies.add(first_temp_surface),
body.parentComponent.bRepBodies.add(temp_unioned_surface)]
stitch_input = body.parentComponent.features.stitchFeatures.createInput(
collection_of(surfaces),
adsk.core.ValueInput.createByReal(.01),
adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
body.parentComponent.features.stitchFeatures.add(stitch_input)
body.deleteMe()

 

Message 5 of 6

imajar
Advisor
Advisor

Thank You!  That was a great start.  One question:  I am having mixed results with this method.  Sometimes it works and sometimes it does not!  

 

I've attached a file with 2 bodies, one cleans up nicely, but the other does not.  Somehow, the merge function is able to clean the second.  Any thoughts about why stitch does not?

 

Thank You!

Capture.PNG


Aaron Jarrett, PE
Inventor 2019 | i7-6700K 64GB NVidia M4000
LinkedIn

Life is Good.
0 Likes
Message 6 of 6

BrianEkins
Mentor
Mentor

I was curious about this and looked at your model.  It seems the model where the faces are being merged aren't coplanar.  If I change the preference setting so that angles are reported with more decimal places, I can see that they're not 180 deg and are likely outside the tolerance that Fusion considers coplanar.

AngularPrecision.png

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com