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.