<?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: Bug Report? deleteMe Method Not Deleting All Sketch Curves in Fusion Support Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943000#M62899</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3865419"&gt;@JeromeBriot&lt;/a&gt;&amp;nbsp;thank you very much. Can you give more information about the SketchCurves collection object? Does it work just like a simple python list? If so then it would make sense as it would be just &lt;A href="https://stackoverflow.com/questions/2896752/removing-item-from-list-during-iteration-whats-wrong-with-this-idiom" target="_blank" rel="noopener"&gt;like this issue with python lists which causes undefined behavior&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Initially I guessed that the deleteMe method just removed them from the sketch and not the collection but it makes sense that Fusion would update its state between each iteration and thus update the sketch collection object, so then the index is moved over one.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Feb 2022 19:15:33 GMT</pubDate>
    <dc:creator>therealsamchaney</dc:creator>
    <dc:date>2022-02-10T19:15:33Z</dc:date>
    <item>
      <title>Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10941226#M62896</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I wrote a little script to find all projected sketch curves and delete them all. The script accurately counts that there are 10 projected sketch curves, then I call deleteMe method on all of them (in a for loop) but several remain untouched. It seems to be exactly every other curve that remains untouched.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;It seems strange that they are not all deleted. I've even tried deleting all curves in the sketch but it still only deletes half of the sketches.&lt;BR /&gt;&lt;BR /&gt;Why is the deleteMe method only deleting half of the curves and skipping the others? Is there some trick to iterating over the sketchCurve objects in the collection? Is this a bug?&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://knowledge.autodesk.com/community/screencast/0edd1c56-c426-480e-9492-47e9d9a131f4" target="_blank" rel="noopener"&gt;Here is a link to the screencast&lt;/A&gt;. I've attached the test design file here. The code is below:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Author-Sam Chaney
#Description-Selects and deletes all projected sketch entities

import adsk.core, adsk.fusion, adsk.cam, traceback, sys

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        active_component = design.activeComponent
        sketches = active_component.sketches
        active_sketch = adsk.core.Application.get().activeEditObject #Use this instead of chosen_sketch if you want to use active sketch
        
        sketch_name, cancelled  = ui.inputBox('Enter exact name of sketch to delete projected entities')
        if cancelled:
            ui.messageBox('Cancelled!')
            sys.exit('Cancelled')
        if sketches.itemByName(sketch_name) is None:
            ui.messageBox(f'Sketch named "{sketch_name}" not found')
            sys.exit('Sketch not found')

        chosen_sketch = sketches.itemByName(sketch_name)
        
        curves = chosen_sketch.sketchCurves
        ui.messageBox(f'Curve count is {curves.count}')
        lines = curves.sketchLines
        points = chosen_sketch.sketchPoints

        def is_projected(entity):
            projected_entities =[]
            if entity.isLinked:
                projected_entities.append(entity)
            return projected_entities

        def delete_projected(collection):
            for entity in collection:
                # if entity.isLinked:
                    # ui.messageBox('entity was linked')
                entity.deleteMe()
                
        def delete_all(collection):
            for entity in collection:
                entity.deleteMe # should delete all curves in sketch no matter what
                    
        delete_projected(curves)
        delete_all(curves) # even this only deletes 5 lines. It's every other line

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 07:32:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10941226#M62896</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-10T07:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10941267#M62897</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, this is not a bug. You have to delete the objects in reverse order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#Author-Sam Chaney
#Description-Selects and deletes all projected sketch entities

from audioop import reverse
import adsk.core, adsk.fusion, adsk.cam, traceback, sys

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        active_component = design.activeComponent
        sketches = active_component.sketches
        active_sketch = adsk.core.Application.get().activeEditObject #Use this instead of chosen_sketch if you want to use active sketch

        sketch_name, cancelled  = ui.inputBox('Enter exact name of sketch to delete projected entities')
        if cancelled:
            ui.messageBox('Cancelled!')
            sys.exit('Cancelled')
        if sketches.itemByName(sketch_name) is None:
            ui.messageBox(f'Sketch named "{sketch_name}" not found')
            sys.exit('Sketch not found')

        chosen_sketch = sketches.itemByName(sketch_name)

        curves = chosen_sketch.sketchCurves
        ui.messageBox(f'Curve count is {curves.count}')
        lines = curves.sketchLines
        points = chosen_sketch.sketchPoints

        def is_projected(entity):
            projected_entities =[]
            if entity.isLinked:
                projected_entities.append(entity)
            return projected_entities

        def delete_projected(collection):
            for entity in reversed(collection):
                entity.deleteMe()

        def delete_all(collection):
            for entity in reversed(collection):
                entity.deleteMe()

        delete_projected(curves)
        delete_all(curves) # even this only deletes 5 lines. It's every other line

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 07:54:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10941267#M62897</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2022-02-10T07:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10941282#M62898</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7507875"&gt;@therealsamchaney&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I guess what really happened is that the list (or collection) has been changed when you delete its items. See example below for explanation:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;a = [1, 2, 3, 4, 5, 6]
for a1 in a:
    a.remove(a1)

print(a)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will get&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[2, 4, 6]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, if you loop over a copy of the list (or collection):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;b = [1, 2, 3, 4, 5, 6]
for b1 in list(b):
    b.remove(b1)

print(b)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You will get the expected result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would suggest you to try modifying the lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;for entity in collection:&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;for entity in list(collection):&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 08:05:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10941282#M62898</guid>
      <dc:creator>j.han97</dc:creator>
      <dc:date>2022-02-10T08:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943000#M62899</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3865419"&gt;@JeromeBriot&lt;/a&gt;&amp;nbsp;thank you very much. Can you give more information about the SketchCurves collection object? Does it work just like a simple python list? If so then it would make sense as it would be just &lt;A href="https://stackoverflow.com/questions/2896752/removing-item-from-list-during-iteration-whats-wrong-with-this-idiom" target="_blank" rel="noopener"&gt;like this issue with python lists which causes undefined behavior&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;Initially I guessed that the deleteMe method just removed them from the sketch and not the collection but it makes sense that Fusion would update its state between each iteration and thus update the sketch collection object, so then the index is moved over one.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 19:15:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943000#M62899</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-10T19:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943007#M62900</link>
      <description>&lt;P&gt;Thank you. This makes sense. After using deleteMe on the first curve, I guess that Fusion must update its state making the new curves collection 1 item smaller. Now the first index is on curve 2 but I'm telling it to go to the next index so it skips curve 2 and ends up on curve 3. Repeat and you're left with every other curve.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 19:17:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943007#M62900</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-10T19:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943057#M62901</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7507875"&gt;@therealsamchaney&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Can you give more information about the SketchCurves collection object?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Read the documentation: &lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-743C88FB-CA3F-44B0-B0B9-FCC378D0D782" target="_blank" rel="noopener"&gt;Python Specific Issues - Working with Collections&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7507875"&gt;@therealsamchaney&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;After using deleteMe on the first curve, I guess that Fusion must update its state making the new curves collection 1 item smaller. Now the first index is on curve 2 but I'm telling it to go to the next index so it skips curve 2 and ends up on curve 3. Repeat and you're left with every other curve.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's exactly what &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11275785"&gt;@j.han97&lt;/a&gt; explained in his message previously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 19:33:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943057#M62901</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2022-02-10T19:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Bug Report? deleteMe Method Not Deleting All Sketch Curves</title>
      <link>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943069#M62902</link>
      <description>&lt;P&gt;I just wanted to say that normally in python when iterating over a list and modifying it, you make a copy of it and most people I see tend to use slice notation like&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;for item in my_list[:]:
    #do something&lt;/LI-CODE&gt;&lt;P&gt;however, the Fusion 360 sketchCurves collection object is not a python list, so you cannot use that notation. I think&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11275785"&gt;@j.han97&lt;/a&gt;&amp;nbsp;'s answer is the best approach because it makes the collection into a normal Python list of sketchCurve objects and doesn't touch the actual collection object directly.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 19:38:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-support-forum/bug-report-deleteme-method-not-deleting-all-sketch-curves/m-p/10943069#M62902</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-10T19:38:07Z</dc:date>
    </item>
  </channel>
</rss>

