Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Close Fusion 360 through API/text command?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
j.han97
239 Views, 5 Replies

Close Fusion 360 through API/text command?

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.

5 REPLIES 5
Message 2 of 6

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


Sanjana Goli
Customer Technical Success
Fusion 360 Webinars | Tips and Best Practices | Troubleshooting
Message 3 of 6
kandennti
in reply to: j.han97

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
in reply to: j.han97

Thanks @kandennti ,

 

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

Message 5 of 6
kandennti
in reply to: j.han97

@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
in reply to: j.han97

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report