One script to launch another script

One script to launch another script

brad.bylls
Collaborator Collaborator
613 Views
3 Replies
Message 1 of 4

One script to launch another script

brad.bylls
Collaborator
Collaborator

I have a script file to check Entitlement.

When that comes back as true, I want it to launch the approved script.

I have tried 'subprocess' and 'runpy.' but it looks like they are trying to run outside of Fusion.

This is the entitlement code (sourced from Brian Ekins)

class CheckEntitlement(apper.Fusion360CommandBase):
    def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values):
        app = adsk.core.Application.get()
        ui = app.userInterface
        workSpace = ui.workspaces.itemById('FusionSolidEnvironment')
        tbPanels = workSpace.toolbarPanels

        global tbPanel

        try:
            userID = app.userId
            appID = '2588623515668137326'
            url = f'https://apps.autodesk.com/webservices/checkentitlement?userid={userID}&appid={appID}'
            response = urllib.request.urlopen(url)
            jsonb = response.read()
            jsont = jsonb.decode("utf-8")
            json_dict = json.loads(jsont)

            if json_dict['IsValid']:
                # ui.messageBox('The license is valid.')
                tbPanel = tbPanels.itemById('Mold Tech')
                if tbPanel:
                    tbPanel.deleteMe()
            else:
                ui.messageBox('License has Expired') # .\nMessage: ' + json_dict['Message'])

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

 Right after line 23 I want to launch the approved script.

The approved script is just code, no def or class modules.

Any help appreciated.

Brad Bylls
0 Likes
Accepted solutions (1)
614 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor
Accepted solution

To give credit where credit is due, I don't think that code is mine and probably came from Patrick Rainsberry.

 

Unfortunately, what you want to do isn't currently possible. The API needs an API wrapper around the functionality provided by the "Scripts and Add-Ins" command, so you can get a list of known scripts and add-ins, add new ones to the list, run scripts, and load and unload add-ins. None of that is currently available, but it would be nice.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 4

brad.bylls
Collaborator
Collaborator

To give credit where credit is due, it was you. 

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/entitlement-api/m-p/10908807

Thanks for the input. 

I guess I have to put the Entitlement code at the beginning of the script to get it to work. 

 

Brad Bylls
0 Likes
Message 4 of 4

BrianEkins
Mentor
Mentor

That's funny. I saw the use of apper in your sample and figured it wasn't mine but after looking at the referenced thread I see the code you posted is a variation of my original post. It's all coming back to me now. 😄

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes