Automating a python script for Fusion360

Automating a python script for Fusion360

Anonymous
Not applicable
4,521 Views
11 Replies
Message 1 of 12

Automating a python script for Fusion360

Anonymous
Not applicable

I was recently working on a script to convert a .sldprt file to .stl and I got helped out by @BrianEkins. The original question is posted here. As of now, I have to open Fusion360, click at the add-ins option manually and then run my script. However, my original aim was to make the process automated. Is there a way that I can run the python script I wrote just by double-clicking it or maybe from a command line instead of the Autodesk Fusion360 GUI interface? 

Accepted solutions (1)
4,522 Views
11 Replies
Replies (11)
Message 2 of 12

JesusFreke
Advocate
Advocate

You can do IPC in your python script. So, for example, you could open a socket and wait (on a separate thread) for an external program to connect and, e.g. send a filename to convert or something, and then post a message to the main thread to perform the conversion.

Message 3 of 12

Anonymous
Not applicable

Thanks for your response, but how do I start the script from within Fusion360 using Python? So lets say I have file.sldprt, how do I run the python script (which, as of now, I start from Fusion360 interface). Because double-clicking the script gives import errors (for adsk.fusion etc). Does that make sense?

0 Likes
Message 4 of 12

JesusFreke
Advocate
Advocate

You can create an add-in that automatically starts when fusion starts. In the add-in, you would open a socket and start listening for connections (on a separate thread). You can then connect to that socket from an external program and pass data to it, which your add-in can then take action on.

0 Likes
Message 5 of 12

BrianEkins
Mentor
Mentor

What your describing is one of the primary reasons the add-in architecture exists.  With an add-in you can add a button into the UI anywhere you want and execute your functionality by clicking the button just the same as any other Fusion command.  

 

Look at the Creating a Script or Add-In topic and the other topics about working with the UI; User Interface Customization, Commands,  and Command Inputs

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 12

Anonymous
Not applicable

Thanks for your response. I will write an add-in.

 

Right now, I am using Windows Operating System, but my ultimate goal is to make this run on a Linux server. I just found out that Fusion360 is not Linux compatible. Does that mean I won't be able to transfer this set-up on Linux? I was wondering that all the conversion (.sldprt to .stl) is being done on the cloud and then downloaded, so it might be possible. However, since the environment is Windows base (adsk.fusion etc), this makes me think I won't be able to.

0 Likes
Message 7 of 12

BrianEkins
Mentor
Mentor
Accepted solution

If you're just translating existing files and not doing any modeling, you should look at Forge. It's a set of web services and supports file translations.  Because it's a web service you can use it from any platform that's capable of using a REST ALL. forge.autodesk.com

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

Anonymous
Not applicable

Thanks for the response. I will start looking into Forge (not sure what you mean by REST ALL). Can you give me any direction on how to proceed with Python to use Forge?

0 Likes
Message 9 of 12

BrianEkins
Mentor
Mentor

Auto correct got me. It should be REST API. Forge is exposed through a RESTful API.  

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

Anonymous
Not applicable

Got it. I will take look into the REST API. 

 

I apologize for asking this again, but is there any useful example available that deals with FORGE imports/exports online? Like this for local conversions. The closest thing I found was this code online but I believe this too is insufficient, as it does not deal with any import/export. 

 

I have started searching too, but my first preference is to find something online that gives me some direction for import export, as there is no use re-inventing the wheel. 

 

Thanks for all your help.

0 Likes
Message 11 of 12

BrianEkins
Mentor
Mentor

There are several different services that make up the Forge API.  The Data Management API" provides the ability to upload and download from Forge.  The Model Derivative API supports the ability to convert between more than 60 different file formats, including STL.  The links above will take you to pages that have links to the developer guide, tutorials and the API reference.

 

One thing to be aware of when using Forge that's very different from the Fusion API is that you have to deal with authorization to access and use the API.  With Fusion you're using the user's authorization to gain access and don't have to mess with it.  It adds quite a bit to the complexity.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 12 of 12

Anonymous
Not applicable
Hi! I wanted to ask if you were able to successfully implement a solution using an Add-In and/or socket. If so, are you willing to release the part of your code that contains your implementation?