<?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: How can create a patch by a loop in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971482#M6512</link>
    <description>&lt;P&gt;&lt;SPAN&gt;hi Michael Tomsia&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks for your solution.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I try to do it.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Feb 2022 09:42:18 GMT</pubDate>
    <dc:creator>ho-kou</dc:creator>
    <dc:date>2022-02-25T09:42:18Z</dc:date>
    <item>
      <title>How can create a patch by a loop</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971046#M6508</link>
      <description>&lt;P&gt;Hi everybody,&lt;BR /&gt;I want to create a patch using the loop inside Fig.1 and Fig.2 according to the following flow.&lt;BR /&gt;①Gets all loops for each face of the target body.&lt;BR /&gt;②If the loop obtained in ① has an internal shape, use this loop to create a sketch.&lt;BR /&gt;③Create a patch using the sketch profile created in ②.&lt;BR /&gt;Issue: Depending on the shape of the internal loop, the sketch profile for patch creation may not be generated.&lt;BR /&gt;For example, [sample_a.step] is NG. [Sample_b.step] is OK.&lt;BR /&gt;Can you tell me how to create a patch even with the shape of [sample_a.step]?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ask_1.png" style="width: 746px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029551i9FC9EE403AD141A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="ask_1.png" alt="ask_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ask_2.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029552i48AC882244B7060D/image-size/large?v=v2&amp;amp;px=999" role="button" title="ask_2.png" alt="ask_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# Assuming you have not changed the general structure of the template no modification is needed in this file.
from . import commands
from .lib import fusion360utils as futil

import adsk.core, adsk.fusion, adsk.cam, traceback


_app = None
_ui  = None
_design = None
_rootComp = None

def run(context):
    try:
        # This will run the start function in each of your commands as defined in commands/__init__.py
        commands.start()

        # fusion情報を取得
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui  = _app.userInterface

        product = _app.activeProduct
        global _design
        _design = adsk.fusion.Design.cast(product)

        global _rootComp
        _rootComp = _design.rootComponent

        allBodies = _rootComp.bRepBodies

        bodycount = allBodies.count
        if allBodies.count &amp;lt; 1:
            _ui.messageBox('Body count is not exist')
            return
        newbody = allBodies.item(0)      

        # create patch
        oresult = [-1]
        CreatePatch(newbody, oresult)
        
        return

    except:
        futil.handle_error('run')

# create patch
def CreatePatch(targetbody,
                oresult):
    try:
        oresult[0] = -1
        i = 0
        j = 0
        for face in targetbody.faces:
            for Loop in face.loops:

                if Loop.isOuter:
                    # if Loop is Outer
                    continue
              
                # create sketch by inter loop
                brepEdges = Loop.edges
                skt = createsketch(brepEdges)

                # can not get sketch's profile
                profilecurve = skt.profiles[0]

                # Create the patch feature by sketch's profile
                patches = _rootComp.features.patchFeatures
                patchInput = patches.createInput(profilecurve, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
                patches.add(patchInput)

        oresult[0] = 0
    except:
         _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))    

# crate loop's sketch
def createsketch(brepEdges):
    try:
        oresult = -1
        skt :adsk.fusion.Sketch = _rootComp.sketches.add(_rootComp.xYConstructionPlane)
        skt.arePointsShown = False

        edge = brepEdges.item(0)
        edgegeo :adsk.core.NurbsCurve3D = None
        curveType = edge.geometry.curveType
        
        sktFits = None
        if curveType == 2:
            # Circle3DCurveType
            sktFits :adsk.fusion.SketchFixedSplines = skt.sketchCurves.sketchFixedSplines
        else:
            # NurbsCurve3DCurveType
            sktFits :adsk.fusion.SketchFittedSplines = skt.sketchCurves.sketchFittedSplines
        
        for edge in brepEdges:
        
            if curveType == 2:
                # Circle3DCurveType
                edgegeo = edge.geometry.asNurbsCurve
                
                sktFits.addByNurbsCurve(edgegeo)
            else:
                # NurbsCurve3DCurveType
                edgegeo = edge.geometry
                eva :adsk.core.SurfaceEvaluator = edgegeo.evaluator
                _, sPnt, ePnt = eva.getEndPoints()
                _, [sPrm, ePrm] = eva.getParametersAtPoints([sPnt, ePnt])

                # get Transit point
                _, pnts = eva.getStrokes(sPrm, ePrm, 0.01)
                pntLst = adsk.core.ObjectCollection.create()
                [pntLst.add(p) for p in pnts]
                
                sktFits.add(pntLst)

        skt.name = 'test'
        
        return skt
    except:
        _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def stop(context):
    try:
        # Remove all of the event handlers your app has created
        futil.clear_handlers()

        # This will run the start function in each of your commands as defined in commands/__init__.py
        commands.stop()

    except:
        futil.handle_error('stop')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 02:31:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971046#M6508</guid>
      <dc:creator>ho-kou</dc:creator>
      <dc:date>2022-02-25T02:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: How can create a patch by a loop</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971380#M6509</link>
      <description>&lt;P&gt;The problem you encounter is that a SketchProfile is, in my understanding, planar. You logically encounter a problem when trying to make a profile from a non planar edge. However, according to the documentation, a PatchFeature can take BRepGeometry, thus we should be able to forego using a sketch all together. I've tried to throw in a sample code, tell me if it works out for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# create patch
def CreatePatch(targetbody,
                oresult):
    try:
        oresult[0] = -1
        i = 0
        j = 0
        for face in targetbody.faces:
            for Loop in face.loops:
                Loop: adsk.fusion.BRepLoop
                if Loop.isOuter:
                    # if Loop is Outer
                    continue
              
                # create sketch by inter loop
                brepEdges = Loop.edges
                pathEdgeCollection = adsk.core.ObjectCollection.create()
                [pathEdgeCollection.add(edge) for edge in brepEdges]
                path = adsk.fusion.Path.create(pathEdgeCollection, 0)

                # Create the patch feature by sketch's profile
                global _rootComp
                patches = _rootComp.features.patchFeatures
                patchInput = patches.createInput(
                    path,
                    adsk.fusion.FeatureOperations.NewBodyFeatureOperation
                )
                patches.add(patchInput)

        oresult[0] = 0
    except:
         _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first sample, which gave you trouble, the script produced this :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2022-02-25 093143.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029630iEE28B77C6A1EFF72/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2022-02-25 093143.png" alt="Capture d’écran 2022-02-25 093143.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 08:33:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971380#M6509</guid>
      <dc:creator>tykapl.breuil</dc:creator>
      <dc:date>2022-02-25T08:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can create a patch by a loop</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971417#M6510</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Hi Mr. Ho-Kou,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Consider ... &lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;instead of creating sketch with profile&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt; to be used as a patch, &lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;split a face of target body with the surface body tool&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;, and use the resulting &lt;FONT color="#0000FF"&gt;&lt;EM&gt;&lt;STRONG&gt;cut-off face&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt; as a patch(s). Contrary to sketch profiles they don't need to be flat.&lt;/P&gt;&lt;P&gt;Look at the attached file. I believe that converting this idea to respective script would be ... &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;a piece of cake&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":woman_cook:"&gt;👩‍🍳&lt;/span&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Test_Patch.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1029636i9C8D5ED6803C775C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Test_Patch.png" alt="Test_Patch.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;MichaelT&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 08:52:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971417#M6510</guid>
      <dc:creator>MichaelT_123</dc:creator>
      <dc:date>2022-02-25T08:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can create a patch by a loop</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971478#M6511</link>
      <description>&lt;P&gt;&lt;SPAN&gt;hi,Paul Breuil&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Use your code,&amp;nbsp; i am succeed to create the patch,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank you very much.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 09:40:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971478#M6511</guid>
      <dc:creator>ho-kou</dc:creator>
      <dc:date>2022-02-25T09:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: How can create a patch by a loop</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971482#M6512</link>
      <description>&lt;P&gt;&lt;SPAN&gt;hi Michael Tomsia&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks for your solution.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I try to do it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 09:42:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-can-create-a-patch-by-a-loop/m-p/10971482#M6512</guid>
      <dc:creator>ho-kou</dc:creator>
      <dc:date>2022-02-25T09:42:18Z</dc:date>
    </item>
  </channel>
</rss>

