<?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 Document Opening Class - Does Not Work With Drawings in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/document-opening-class-does-not-work-with-drawings/m-p/11465586#M5296</link>
    <description>&lt;P&gt;Can anybody help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following Fusion 360 Python "Class" works OK when opening an assembly, or a part, but does &lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; work when opening a drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;class MyDocumentOpenedHandler(adsk.core.DocumentEventHandler):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;def __init__(self):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;super().__init__()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;def notify(self, args):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;global app, ui&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ui = app.userInterface&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;design = adsk.fusion.Design.cast(app.activeProduct)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;document = design.parentDocument&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ui.messageBox("DOCUMENT OPENING", 'Fusion 360', 0, 3)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody know how to modify the code so that it also works when opening a drawing?&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, 06 Oct 2022 10:57:40 GMT</pubDate>
    <dc:creator>isocam</dc:creator>
    <dc:date>2022-10-06T10:57:40Z</dc:date>
    <item>
      <title>Document Opening Class - Does Not Work With Drawings</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/document-opening-class-does-not-work-with-drawings/m-p/11465586#M5296</link>
      <description>&lt;P&gt;Can anybody help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following Fusion 360 Python "Class" works OK when opening an assembly, or a part, but does &lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; work when opening a drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;class MyDocumentOpenedHandler(adsk.core.DocumentEventHandler):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;def __init__(self):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;super().__init__()&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;def notify(self, args):&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;global app, ui&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ui = app.userInterface&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;design = adsk.fusion.Design.cast(app.activeProduct)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;document = design.parentDocument&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ui.messageBox("DOCUMENT OPENING", 'Fusion 360', 0, 3)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anybody know how to modify the code so that it also works when opening a drawing?&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, 06 Oct 2022 10:57:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/document-opening-class-does-not-work-with-drawings/m-p/11465586#M5296</guid>
      <dc:creator>isocam</dc:creator>
      <dc:date>2022-10-06T10:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Document Opening Class - Does Not Work With Drawings</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/document-opening-class-does-not-work-with-drawings/m-p/11465791#M5297</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/84538"&gt;@isocam&lt;/a&gt;&amp;nbsp;for drawing file the design object is returned as None. An error occurs for the line&amp;nbsp;&lt;STRONG&gt;document = design.parentDocument.&amp;nbsp;&lt;/STRONG&gt;Hence the message box line is never executed.&lt;/P&gt;
&lt;P&gt;Here is the modified code which worked for me.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;class MyDocumentOpenedHandler(adsk.core.DocumentEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try: 
            global app, ui
            ui = app.userInterface
            design = adsk.fusion.Design.cast(app.activeProduct)
            if design is not None:
                document = design.parentDocument
            ui.messageBox("DOCUMENT OPENING", 'Fusion 360', 0, 3)
        except:
            app.log('AddIn Stop Failed: {}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;------------------------------------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 12:36:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/document-opening-class-does-not-work-with-drawings/m-p/11465791#M5297</guid>
      <dc:creator>Rushikesh.kadam</dc:creator>
      <dc:date>2022-10-06T12:36:03Z</dc:date>
    </item>
  </channel>
</rss>

