<?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 to Exit / Stop Fusion API Script From Within Script (Throw Fatal Error) in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10933067#M6672</link>
    <description>&lt;P&gt;&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;I don't understand anything but Japanese.&lt;/P&gt;
&lt;P&gt;私の英語より、きれいな日本語になっていますよ。&lt;/P&gt;</description>
    <pubDate>Mon, 07 Feb 2022 09:17:55 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2022-02-07T09:17:55Z</dc:date>
    <item>
      <title>How to Exit / Stop Fusion API Script From Within Script (Throw Fatal Error)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10931037#M6668</link>
      <description>&lt;P&gt;Hi, &lt;STRONG&gt;is it possible to throw an exception that will end/stop a Fusion 360 API script?&lt;/STRONG&gt; Basically, I want to check something (for instance a folder directory given by a user) and if they give a bad path, exit the entire Fusion script (or stop the Run function) from within a function block. I've tried sys.exit() but it's not working as expected. I know the &lt;STRONG&gt;ui.inputBox&lt;/STRONG&gt; has a &lt;STRONG&gt;cancel method&lt;/STRONG&gt; that can exit the script so it would be great to be able to do something like that.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Feb 2022 22:12:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10931037#M6668</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-05T22:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to Exit / Stop Fusion API Script From Within Script (Throw Fatal Error)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10931043#M6669</link>
      <description>&lt;P&gt;I did get sys.exit() to work but it has to not be in a try/except block. &lt;STRONG&gt;I'm still wondering if there is a more Fusion API way to do this, like if there is a built-in cancel or exit method to stop scripts so I would say this doesn't really answer my original question&lt;/STRONG&gt;.&lt;BR /&gt;If anyone is wondering, my code is below. It's a simple function to get a file folder path from the user.&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;        def get_path():
            export_path, cancelled = ui.inputBox('Enter path to the export folder')
            if cancelled:
                ui.messageBox('Cancelled')
                sys.exit('Cancelled')
            if not os.path.isdir(export_path):
                ui.messageBox('Path does not exist. Aborting program')
                sys.exit('Path does not exist')
            export_path = os.path.abspath(export_path)
            export_path+='\\'
            return export_path&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;&lt;P&gt;One thing I noticed is that &lt;STRONG&gt;if you have a ui.inputBox call inside a function block, the cancel method doesn't actually end the script&lt;/STRONG&gt;&amp;nbsp;(hence why I had to have the second sys.exit). However, &lt;STRONG&gt;if you call the ui.inputBox method outside a block (just in the main run function), it does actually end the script.&amp;nbsp;&lt;/STRONG&gt;Must be a quirk about how cancel works. I looked into fusion.py and found the cancel method but it just calls&amp;nbsp;TrimFeatureInput_cancel(self) and I can't find the definition for that method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Feb 2022 22:56:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10931043#M6669</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-05T22:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Exit / Stop Fusion API Script From Within Script (Throw Fatal Error)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10931752#M6670</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;Instead of aborting in the get_path function, how about aborting in the caller?&lt;/P&gt;
&lt;P&gt;Also, since the UserInterface object has createFileDialog and createFolderDialog, I think it would be more user-friendly to use them.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core
import os

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        export_path: str = get_folder_path()
        if len(export_path) &amp;lt; 1:
            return
        
        ui.messageBox(export_path)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def get_folder_path() -&amp;gt; str:
    app: adsk.core.Application = adsk.core.Application.get()
    ui: adsk.core.UserInterface = app.userInterface

    dlg: adsk.core.FolderDialog = ui.createFolderDialog()
    res: adsk.core.DialogResults = dlg.showDialog()

    if res:
        ui.messageBox('Cancelled')
        return ''

    export_path: str = dlg.folder
    if not os.path.isdir(export_path):
        ui.messageBox('Path does not exist. Aborting program')
        return ''

    return export_path + '\\'&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 06 Feb 2022 13:34:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10931752#M6670</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2022-02-06T13:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Exit / Stop Fusion API Script From Within Script (Throw Fatal Error)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10932152#M6671</link>
      <description>Thank you. I had thought about aborting in the caller, that might be better. I did not know about createFileDialog or createFolderDialog, so thank you. That is definitely better than the inputBox I was using. I am new to the API so there is a lot I don't know about yet. This should definitely improve my script!&lt;BR /&gt;&lt;BR /&gt;あなたのバイオは日本語があります。日本語は話せますか？勉強しています</description>
      <pubDate>Sun, 06 Feb 2022 19:41:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10932152#M6671</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-02-06T19:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to Exit / Stop Fusion API Script From Within Script (Throw Fatal Error)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10933067#M6672</link>
      <description>&lt;P&gt;&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;I don't understand anything but Japanese.&lt;/P&gt;
&lt;P&gt;私の英語より、きれいな日本語になっていますよ。&lt;/P&gt;</description>
      <pubDate>Mon, 07 Feb 2022 09:17:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-to-exit-stop-fusion-api-script-from-within-script-throw/m-p/10933067#M6672</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2022-02-07T09:17:55Z</dc:date>
    </item>
  </channel>
</rss>

