<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Merging all coplanar faces in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8817217#M15338</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;traceback&lt;BR /&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;adsk.core&lt;BR /&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;adsk.fusion&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;(&lt;SPAN&gt;context&lt;/SPAN&gt;):&lt;BR /&gt;    &lt;SPAN&gt;try&lt;/SPAN&gt;:&lt;BR /&gt;        root = adsk.core.Application.get().activeProduct.rootComponent  &lt;SPAN&gt;# type: adsk.fusion.Component&lt;BR /&gt;&lt;/SPAN&gt;        merge_planar_faces(root.bRepBodies[&lt;SPAN&gt;0&lt;/SPAN&gt;])&lt;BR /&gt;    &lt;SPAN&gt;except &lt;/SPAN&gt;&lt;SPAN&gt;Exception&lt;/SPAN&gt;:&lt;BR /&gt;        &lt;SPAN&gt;print&lt;/SPAN&gt;(traceback.format_exc())&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;collection_of&lt;/SPAN&gt;(collection):&lt;BR /&gt;    object_collection = adsk.core.ObjectCollection.create()&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;obj &lt;SPAN&gt;in &lt;/SPAN&gt;collection:&lt;BR /&gt;        object_collection.add(obj)&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;object_collection&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;merge_planar_faces&lt;/SPAN&gt;(body: adsk.fusion.BRepBody):&lt;BR /&gt;    first_temp_surface = &lt;SPAN&gt;None&lt;BR /&gt;&lt;/SPAN&gt;    temp_unioned_surface = &lt;SPAN&gt;None&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    brep = adsk.fusion.TemporaryBRepManager.get()&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;face &lt;SPAN&gt;in &lt;/SPAN&gt;body.faces:&lt;BR /&gt;        &lt;SPAN&gt;# convert the face to a temporary BRepBody&lt;BR /&gt;&lt;/SPAN&gt;        temp_surface = brep.copy(face)&lt;BR /&gt;        &lt;SPAN&gt;if &lt;/SPAN&gt;first_temp_surface &lt;SPAN&gt;is None&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# We need at least two faces to use a stitch feature, so keep a lone copy of the first face&lt;BR /&gt;&lt;/SPAN&gt;            first_temp_surface = temp_surface&lt;BR /&gt;        &lt;SPAN&gt;elif &lt;/SPAN&gt;temp_unioned_surface &lt;SPAN&gt;is None&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# All the other faces get unioned into a single temporary BRepBody&lt;BR /&gt;&lt;/SPAN&gt;            temp_unioned_surface = temp_surface&lt;BR /&gt;        &lt;SPAN&gt;else&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# Adds this face to the temporary BRepBody that contains all the other faces&lt;BR /&gt;&lt;/SPAN&gt;            brep.booleanOperation(temp_unioned_surface, temp_surface, adsk.fusion.BooleanTypes.UnionBooleanType)&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;# Now stitch the first face, and all the remaining faces together, into a single solid body&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    # This has the side effect of merging any coplanar faces that share an edge&lt;BR /&gt;&lt;/SPAN&gt;    surfaces = [body.parentComponent.bRepBodies.add(first_temp_surface),&lt;BR /&gt;                body.parentComponent.bRepBodies.add(temp_unioned_surface)]&lt;BR /&gt;    stitch_input = body.parentComponent.features.stitchFeatures.createInput(&lt;BR /&gt;        collection_of(surfaces),&lt;BR /&gt;        adsk.core.ValueInput.createByReal(&lt;SPAN&gt;.01&lt;/SPAN&gt;),&lt;BR /&gt;        adsk.fusion.FeatureOperations.NewBodyFeatureOperation)&lt;BR /&gt;    body.parentComponent.features.stitchFeatures.add(stitch_input)&lt;BR /&gt;    body.deleteMe()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 May 2019 00:57:39 GMT</pubDate>
    <dc:creator>JesusFreke</dc:creator>
    <dc:date>2019-05-28T00:57:39Z</dc:date>
    <item>
      <title>Merging all coplanar faces</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8333642#M15335</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 03:45:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8333642#M15335</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-15T03:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merging all coplanar faces</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8334178#M15336</link>
      <description>&lt;P&gt;May be you can try stitch feature.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 10:04:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8334178#M15336</guid>
      <dc:creator>goyals</dc:creator>
      <dc:date>2018-10-15T10:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merging all coplanar faces</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8817155#M15337</link>
      <description>&lt;P&gt;Same problem here:&amp;nbsp; How to merge via API - Did you figure anything out?&amp;nbsp; (stitch didnt merge any coplanar faces for me, unless I forgot to check a secret option?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 22:51:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8817155#M15337</guid>
      <dc:creator>imajar</dc:creator>
      <dc:date>2019-05-27T22:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merging all coplanar faces</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8817217#M15338</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;traceback&lt;BR /&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;adsk.core&lt;BR /&gt;&lt;SPAN&gt;import &lt;/SPAN&gt;adsk.fusion&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;(&lt;SPAN&gt;context&lt;/SPAN&gt;):&lt;BR /&gt;    &lt;SPAN&gt;try&lt;/SPAN&gt;:&lt;BR /&gt;        root = adsk.core.Application.get().activeProduct.rootComponent  &lt;SPAN&gt;# type: adsk.fusion.Component&lt;BR /&gt;&lt;/SPAN&gt;        merge_planar_faces(root.bRepBodies[&lt;SPAN&gt;0&lt;/SPAN&gt;])&lt;BR /&gt;    &lt;SPAN&gt;except &lt;/SPAN&gt;&lt;SPAN&gt;Exception&lt;/SPAN&gt;:&lt;BR /&gt;        &lt;SPAN&gt;print&lt;/SPAN&gt;(traceback.format_exc())&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;collection_of&lt;/SPAN&gt;(collection):&lt;BR /&gt;    object_collection = adsk.core.ObjectCollection.create()&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;obj &lt;SPAN&gt;in &lt;/SPAN&gt;collection:&lt;BR /&gt;        object_collection.add(obj)&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;object_collection&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;merge_planar_faces&lt;/SPAN&gt;(body: adsk.fusion.BRepBody):&lt;BR /&gt;    first_temp_surface = &lt;SPAN&gt;None&lt;BR /&gt;&lt;/SPAN&gt;    temp_unioned_surface = &lt;SPAN&gt;None&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    brep = adsk.fusion.TemporaryBRepManager.get()&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;for &lt;/SPAN&gt;face &lt;SPAN&gt;in &lt;/SPAN&gt;body.faces:&lt;BR /&gt;        &lt;SPAN&gt;# convert the face to a temporary BRepBody&lt;BR /&gt;&lt;/SPAN&gt;        temp_surface = brep.copy(face)&lt;BR /&gt;        &lt;SPAN&gt;if &lt;/SPAN&gt;first_temp_surface &lt;SPAN&gt;is None&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# We need at least two faces to use a stitch feature, so keep a lone copy of the first face&lt;BR /&gt;&lt;/SPAN&gt;            first_temp_surface = temp_surface&lt;BR /&gt;        &lt;SPAN&gt;elif &lt;/SPAN&gt;temp_unioned_surface &lt;SPAN&gt;is None&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# All the other faces get unioned into a single temporary BRepBody&lt;BR /&gt;&lt;/SPAN&gt;            temp_unioned_surface = temp_surface&lt;BR /&gt;        &lt;SPAN&gt;else&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;# Adds this face to the temporary BRepBody that contains all the other faces&lt;BR /&gt;&lt;/SPAN&gt;            brep.booleanOperation(temp_unioned_surface, temp_surface, adsk.fusion.BooleanTypes.UnionBooleanType)&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;# Now stitch the first face, and all the remaining faces together, into a single solid body&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    # This has the side effect of merging any coplanar faces that share an edge&lt;BR /&gt;&lt;/SPAN&gt;    surfaces = [body.parentComponent.bRepBodies.add(first_temp_surface),&lt;BR /&gt;                body.parentComponent.bRepBodies.add(temp_unioned_surface)]&lt;BR /&gt;    stitch_input = body.parentComponent.features.stitchFeatures.createInput(&lt;BR /&gt;        collection_of(surfaces),&lt;BR /&gt;        adsk.core.ValueInput.createByReal(&lt;SPAN&gt;.01&lt;/SPAN&gt;),&lt;BR /&gt;        adsk.fusion.FeatureOperations.NewBodyFeatureOperation)&lt;BR /&gt;    body.parentComponent.features.stitchFeatures.add(stitch_input)&lt;BR /&gt;    body.deleteMe()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 00:57:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8817217#M15338</guid>
      <dc:creator>JesusFreke</dc:creator>
      <dc:date>2019-05-28T00:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Merging all coplanar faces</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8819070#M15339</link>
      <description>&lt;P&gt;Thank You!&amp;nbsp; That was a great start.&amp;nbsp; One question:&amp;nbsp; I am having mixed results with this method.&amp;nbsp; Sometimes it works and sometimes it does not!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached a file with 2 bodies, one cleans up nicely, but the other does not.&amp;nbsp; Somehow, the merge function is able to clean the second.&amp;nbsp; Any thoughts about why stitch does not?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 177px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/641517iB4C892F05B9B51B0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 16:31:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8819070#M15339</guid>
      <dc:creator>imajar</dc:creator>
      <dc:date>2019-05-28T16:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Merging all coplanar faces</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8819445#M15340</link>
      <description>&lt;P&gt;I was curious about this and looked at your model.&amp;nbsp; It seems the model where the faces are being merged aren't coplanar.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AngularPrecision.png" style="width: 852px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/641576iF15018F74100FA0E/image-size/large?v=v2&amp;amp;px=999" role="button" title="AngularPrecision.png" alt="AngularPrecision.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 19:08:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/merging-all-coplanar-faces/m-p/8819445#M15340</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2019-05-28T19:08:34Z</dc:date>
    </item>
  </channel>
</rss>

