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: 

Example Code for calling third party add-ons?

5 REPLIES 5
Reply
Message 1 of 6
rob.sherwood
409 Views, 5 Replies

Example Code for calling third party add-ons?

Hi,

 

I'm a professional programmer but very new to CAD and Fusion 360.  I'm looking to write a python script to iteratively make calls to some of the third party gear add-ons (e.g., Helical Gear).  I've read a bunch of the API tutorials and it seems easy enough, but I haven't found one that talks about how to call other scripts/add-ons.

 

Questions:

1) Is it possible to call a third-party add on via API?

2) Does anyone have example code they can point me to?

 

Thank you in advance!

 

- Rob

.

5 REPLIES 5
Message 2 of 6
marshaltu
in reply to: rob.sherwood

Hello,

 

What did you mean "make calls to third-party add-ons"? We didn't provide API to let clients call into addons. However you could call some functions written in other Python addons if you know their path and import them to your python script successfully. If you mean to invoke those commands written in other addons, you can iterate them by id by Command-related API. 

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 6
rob.sherwood
in reply to: marshaltu

Thanks for the reply.

 

I'm trying to invoke commands created by other modules.

 

Specifically, if you take the helical gear add-on (https://apps.autodesk.com/FUSION/en/Detail/Index?id=9029586664984391977&appLang=en&os=Win64), which created the 'Helical Gear' entry under Create in Model mode.  When I manually click the Helical Gear entry under the Create tab, I get a dialog that asks me for gear parameters like module, number of teeth, etc.

 

 I would like to create a function that can call in to that code automatically; something like:

 

def create_gear_train(module, ...):

     helical  = rootComp.features.helical_gear_add_on

     # gear1

     gear1 = helical.createSimpleInput()

     gear1.module = module

     gear1.teeth = 15

     # gear 2

     gear2 = helical.createSimpleInput()

     gear2.module = module

     gear2.teeth = 30   

     # ...

That is, something that allows me to reuse the helical code from my own code.  The trick specific to the helical code is that it's creation methods seem tightly coupled to the UI system so even if I could just import the functions via the python 'import' command, I'd still need to initialize a 
HelicalGearAddin() class and fake/mock out the calls from the GUI.  Much better if I could just make an API call to fill in the fields like a regular, autocad supported feature (like createCylinder()).

 

From your mail "you can iterate them by id by Command-related API." sounds like the right thing but I don't think I understand.  How do I identify the ID of a third-party add-on?  Apologies if it's a dumb question but any pointers to example code should get me going in the right direction.

 

Thanks in advance!

 

- Rob

.

 

     

     

Message 4 of 6
marshaltu
in reply to: rob.sherwood

Hello,

 

You can invoke command by the following codes. The precondition is you need know the id or name of the command. And unfortunately it cannot be automated as a command dialog will pop up to collect users' inputs. I cannot figure out better way to do that. 

 

PS: you can find the command id from the source codes of the addin and the command name under "Create" tab. 

 

Thanks,

Marshal

 

 

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
 
        #myCmdDef = ui.commandDefinitions.itemById('HelicalGearAddin')
        myCmdDef = None
        for cmdDef in ui.commandDefinitions:
            if cmdDef.name == 'Helical Gear':
                myCmdDef = cmdDef
                break
        if myCmdDef:
            myCmdDef.execute()
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 5 of 6
rob.sherwood
in reply to: marshaltu

Thanks for the help.  This is definitely a step in the right direction but still not quite there because as you say, I can't directly input into the dialog box.  Is there a way I can from the ui object get a list of active dialog boxes such that maybe I can discover the dialog box?  If not, I can still manually type in values if I can get a pointer to the resulting objects that come out of the dialog boxes (e.g., so that I can move them and rotate them afterwards).  

 

Please let me know and thank you for your help!

 

- Rob

.

Message 6 of 6
marshaltu
in reply to: rob.sherwood

Hello,

 

Unfortunately I cannot figure out the way to let you do what you wanted. We don't have API to automate users' inputs in command dialog. 

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

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