<?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: linked assembly Bug? can't traverse over assy in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9784193#M10623</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't remove item from a list while iterating over it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;occList = [occ for occ in occList if occ.joints.count &amp;gt; 0]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also modify the first code:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;if not occ in occList and occ.joints.count &amp;gt; 0:&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 05 Oct 2020 11:47:02 GMT</pubDate>
    <dc:creator>JeromeBriot</dc:creator>
    <dc:date>2020-10-05T11:47:02Z</dc:date>
    <item>
      <title>linked assembly Bug? can't traverse over assy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9771693#M10620</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to modify the traverse-sample to output all occurrences with joints. The Script worked fine while testing with small assemblies, but as soon as I tested it on a larger assy with sub-assemblies, the occurrences in linked assys won´t get detected. Here is my modified script, it gets '&lt;SPAN style="font-family: inherit;"&gt;root.occurrences.asList' and an 'empty list'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def traverseAssembly(occurrences, occList):
    ''' outputs a list of occurrences that have joints
    '''
    occ = adsk.fusion.Occurrence.cast(None)
    for occ in occurrences:     
        try:
            if occ.joints.count:    # if the occurrence has joints, append the occ's name to the list
                occList.append(occ.name)
        except:
            print('Error')

        if occ.childOccurrences:    # if there are childs, repeat the function
            occList = traverseAssembly(occ.childOccurrences, occList)
        if len(occList):
            print(occList[-1])
    return occList&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I manually break the link, the script works fine. So I think there is an issue with the link of the components?&lt;/P&gt;&lt;P&gt;Does anybody know if that's a bug or is my code wrong?&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1639694"&gt;@goyals&lt;/a&gt;, can you help?&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 08:35:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9771693#M10620</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-28T08:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: linked assembly Bug? can't traverse over assy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9781987#M10621</link>
      <description>&lt;P&gt;I modified your sample to remove the joints check so it now reports every occurrence.&amp;nbsp; In my simple test it works correctly regardless of whether there are referenced components or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root : adsk.fusion.Component = des.rootComponent
        traverseAssembly(root.occurrences, 0)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def traverseAssembly(occurrences, level):
    occ = adsk.fusion.Occurrence.cast(None)
    for occ in occurrences:     
        print(' ' * (level * 5) + occ.name)
        if occ.childOccurrences:    # if there are childs, repeat the function
            occList = traverseAssembly(occ.childOccurrences, level + 1)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 03 Oct 2020 06:22:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9781987#M10621</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2020-10-03T06:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: linked assembly Bug? can't traverse over assy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9783967#M10622</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5741855"&gt;@BrianEkins&lt;/a&gt; for your Answer.&lt;/P&gt;&lt;P&gt;I tested your Code and it outputs all occurrences as expected, but I need all occurrences with joints as a list or dict.&lt;/P&gt;&lt;P&gt;So I added a line to append all occurrences to a global list:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def traverseAssembly(occurrences, level):
    global occList
    occ = adsk.fusion.Occurrence.cast(None)
    for occ in occurrences:  
        if not occ in occList:
            try:
                occList.append(occ)   
            except:
                print(occ.fullPathName+' - Error')
        #print(' ' * (level * 5) + occ.name)
        if occ.childOccurrences:    # if there are childs, repeat the function
            traverseAssembly(occ.childOccurrences, level + 1)&lt;/LI-CODE&gt;&lt;P&gt;When I run this script, I get a list with all occurrences. So I added a loop to remove all occs without joints.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for occ in occList:
            if occ.joints.count == 0:
                occList.remove(occ)
        print(occList)&lt;/LI-CODE&gt;&lt;P&gt;I tested this code with the GenevaDrive-model from the "Basic Training-&amp;gt;06 Assemblies-&amp;gt;GenevaDrive".&lt;/P&gt;&lt;P&gt;An Error occurs when the loop comes to "frame:0801-04P:1" : "RuntimeError 3 : object does not belong to the occurrence's component"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why does this error occur? I mean this occurrence belongs to the assembly, doesn't it?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 09:04:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9783967#M10622</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-05T09:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: linked assembly Bug? can't traverse over assy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9784193#M10623</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't remove item from a list while iterating over it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;occList = [occ for occ in occList if occ.joints.count &amp;gt; 0]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also modify the first code:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;if not occ in occList and occ.joints.count &amp;gt; 0:&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 05 Oct 2020 11:47:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9784193#M10623</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2020-10-05T11:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: linked assembly Bug? can't traverse over assy</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9784244#M10624</link>
      <description>&lt;P&gt;Thanks,&lt;BR /&gt;this helps a bit, but does not solve the problem with the RuntimeError that occurs at larger assemblies.&lt;BR /&gt;&lt;BR /&gt;Even if I connect two blocks with a revolute joint and move one component in a sub-component this error occurs. The browser looks like:&lt;BR /&gt;-root&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -box1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -sub1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -box2&lt;BR /&gt;Errormsg: "RuntimeError 3 : object does not belong to the occurrence's component"&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 12:21:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/linked-assembly-bug-can-t-traverse-over-assy/m-p/9784244#M10624</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-05T12:21:03Z</dc:date>
    </item>
  </channel>
</rss>

