Close Fusion 360 through API/text command?

Close Fusion 360 through API/text command?

j.han97
Advocate Advocate
681 Views
5 Replies
Message 1 of 6

Close Fusion 360 through API/text command?

j.han97
Advocate
Advocate

Hi all,

 

Regarding the topic, is it possible to close Fusion 360 application through API/text command?

 

I could not find anything related to this in the documentation.

0 Likes
Accepted solutions (2)
682 Views
5 Replies
Replies (5)
Message 2 of 6

sanjana.shankar.goli
Autodesk Support
Autodesk Support

@j.han97 If you're on Windows, "Fn+Alt+F4" closes Fusion 360.


Sanjana Goli
Software QA Engineer
Fusion 360 Webinars | Tips and Best Practices | Troubleshooting
Message 3 of 6

kandennti
Mentor
Mentor
Accepted solution

Hi @j.han97 .

 

I'm not sure if this is the correct way to exit, but I think it's done.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui: adsk.core.UserInterface = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        exitApplication()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def exitApplication():
    app: adsk.core.Application = adsk.core.Application.get()

    # close all doc
    docs = [doc for doc in app.documents]
    [doc.close(False) for doc in docs[::-1]]

    # close asset
    app.executeTextCommand(u'NuCommands.CloseAssetCmd')

    # Exit Application
    app.executeTextCommand(u'NuCommands.ExitApplicationCmd')
Message 4 of 6

j.han97
Advocate
Advocate

Thanks @kandennti ,

 

I have tried your code and despite several error messages, the application quitted as expected. Thank you!

0 Likes
Message 5 of 6

kandennti
Mentor
Mentor
Accepted solution

@j.han97 .

 

After searching for details, I found a CommandDefinition to exit.

I think this is safer.

def exitApplication():
    app: adsk.core.Application = adsk.core.Application.get()

    # close all doc
    docs = [doc for doc in app.documents]
    [doc.close(False) for doc in docs[::-1]]

    # Exit Application CommandDefinition
    ui: adsk.core.UserInterface = app.userInterface
    cmdDef: adsk.core.CommandDefinition = ui.commandDefinitions.itemById(
        'ExitApplicationCommand')

    # Execute
    if cmdDef:
        cmdDef.execute()

 

Message 6 of 6

j.han97
Advocate
Advocate

Thank you @kandennti, I believe this is safer than using text command too.

0 Likes