<?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 Determine if document is a &amp;quot;Part&amp;quot; or a &amp;quot;Assembly in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10522085#M8337</link>
    <description>&lt;P&gt;Can anybody help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible, using a Python script to determine if the document that is opened, is a "Part" or an "Assembly" and show this in a message box?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The document is a Part&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The document is a Assembly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Darren&lt;/P&gt;</description>
    <pubDate>Thu, 05 Aug 2021 09:37:17 GMT</pubDate>
    <dc:creator>isocam</dc:creator>
    <dc:date>2021-08-05T09:37:17Z</dc:date>
    <item>
      <title>Determine if document is a "Part" or a "Assembly</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10522085#M8337</link>
      <description>&lt;P&gt;Can anybody help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible, using a Python script to determine if the document that is opened, is a "Part" or an "Assembly" and show this in a message box?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The document is a Part&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The document is a Assembly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Darren&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 09:37:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10522085#M8337</guid>
      <dc:creator>isocam</dc:creator>
      <dc:date>2021-08-05T09:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Determine if document is a "Part" or a "Assembly</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10522191#M8338</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/84538"&gt;@isocam&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I interpreted this as determining if Occurrence had a link.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the isReferencedComponent property to determine this.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6D3CD4ED-570D-433D-97AD-EB110DA94177" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6D3CD4ED-570D-433D-97AD-EB110DA94177&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app :adsk.fusion.Application = adsk.core.Application.get()
        ui = app.userInterface
        des :adsk.fusion.Design = app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        for occ in root.allOccurrences:
            print(f'{occ.name} : {occ.isReferencedComponent}')

    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, 05 Aug 2021 10:28:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10522191#M8338</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2021-08-05T10:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Determine if document is a "Part" or a "Assembly</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10524204#M8339</link>
      <description>&lt;P&gt;Fusion doesn't differentiate between a part and an assembly, so it's up to us to define what a part or assembly is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The pure definition is a part is a component that only contains bodies and not any occurrences.&amp;nbsp; An assembly is a component that only contains occurrences and no bodies.&amp;nbsp; Anything else is some kind of a part and assembly hybrid.&amp;nbsp; Here's some code that determines this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def determineDocumentType():
    try:
        app = adsk.core.Application.get() 
        ui = app.userInterface 
        design = adsk.fusion.Design.cast(app.activeProduct) 
        root = design.rootComponent 

        if root.occurrences.count &amp;gt; 0 and root.bRepBodies.count &amp;gt; 0:
            ui.messageBox('Document is a hybrid of assembly and part.')
        elif root.occurrences.count &amp;gt; 0 and root.bRepBodies.count == 0:
            ui.messageBox('Document is an assembly.')
        elif root.occurrences.count == 0 and root.bRepBodies.count &amp;gt; 0:
            ui.messageBox('Document is a part.')
        elif root.occurrences.count == 0 and root.bRepBodies.count == 0:
            ui.messageBox('Document is an empty part.')
    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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 00:48:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/determine-if-document-is-a-quot-part-quot-or-a-quot-assembly/m-p/10524204#M8339</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2021-08-06T00:48:37Z</dc:date>
    </item>
  </channel>
</rss>

