Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Can an add-in be Stopped from within the script ?

info83PHN
Advocate

Can an add-in be Stopped from within the script ?

info83PHN
Advocate
Advocate

Is there any python code that will Stop an add-in ?

I'm running a palette with a 'close' button, and it's firing the MyCloseEventHandler and displays a message.

But I still need to go to the Utilities > Scripts & Add-ins, and select the Add-in and Click on 'stop'

Can it be done in the script code ?

0 Likes
Reply
246 Views
1 Reply
Reply (1)

j4n.vokurka
Advocate
Advocate

Hello,

I've delved into the documentation and put together the following sample. The API provides access to the 'Scripts' object, which really should be called 'ScriptsAndAddins' or something similar to avoid confusion because it's the API equivalent of the 'Scripts and Add-Ins' dialog. I found this confusing initially as I instinctively looked for an analogous 'AddIns' object and couldn't find it.

Anyway you can use it to query collection of all API programs and via name or GUID determine the right add-in and call stop() method.

 

import traceback
import adsk.fusion
import adsk.core

def run(context):
    try:
       _app = adsk.core.Application.get()
       _ui = _app.userInterface  

       scriptsAndAddins = _app.scripts
       if scriptsAndAddins:
        for APIProgram in scriptsAndAddins:
            if APIProgram.isValid == True:
                if (APIProgram.name == "RunningAddin" or APIProgram.id == "35f8a1e4-2428-4970-b8b4-243242f8c35"):
                    APIProgram.stop()

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

 

 

 Word of caution - this object is in preview state and shouldn't be used in commercial apps. I also found out that often id is not defined but I would still suggest it for identification. 

1 Like