Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Changing dimensions of a model from POST requests

Anonymous

Changing dimensions of a model from POST requests

Anonymous
Not applicable

I am trying to make an application via Fusion 360 API scripting wherein a continuously running app would get POST requests from clients and by parsing parameters from that POST request, the app will, lets say, change the dimension of a model in the current document. My question is:

Is this possible?

I was wondering of, lets say, starting a Flask server from within the Fusion 360 script, spawned from a separate thread and that Flask server would handle the POST request. Any parameters sent via the request would then be transferred to the main thread controlling the UI by firing custom events.

Are there any better ways of doing this (if at all possible)?

0 Likes
Reply
Accepted solutions (1)
818 Views
6 Replies
Replies (6)

BrianEkins
Mentor
Mentor

There's not anything in the API that was specifically designed to support something like this but there are a couple of things that you still might be able to use.  One of them is the custom event functionality which is intended to you let you run something (that's not calling the Fusion API) and then let it call back into the Fusion main thread via a custom event.  Then your add-in handling the event can use the API to do whatever it wants.

 

Another option is to have a process running outside of Fusion that calls into Fusion using the Fusion 360 protocol handler.  It's documented in the API help.  Your add-in can be watching for when the protocol handler is invoked and do whatever it wants in response.

 

The main difference between these two approaches is where your program is that's receiving the POST request; running within the Fusion 360 process or running as its own process.  There's much more flexibility by having it as a separate process and I would expect you'll run into fewer problems.  In the second case, there's also the option of Fusion 360 being started if it isn't already running.

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

Anonymous
Not applicable

Thanks for the suggestions. I did actually give it a try by running a Flask server in a separate thread using custom event handlers in the main thread and it works fine.

 

Talking about the other option, is there any way to programmatically invoking the fusion 360 protocol handler from , lets say, a script, as opposed to from a web based protocol handler ( as shown in the documentation)? Is there something in the documentation I am missing? Can it be done in Python? What libraries do you suggest?

0 Likes

BrianEkins
Mentor
Mentor

I did a couple of quick tests to call the protocol handler from something other than a browser (curl and Python requests) and didn't have any success.  I'm certainly not an expert in this area so it could very well be something simple I'm missing but I also had a hard time finding anything when searching.  I would assume it's possible but I'm not much help.

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

Anonymous
Not applicable

Close but no cigar, it appears that the protocol handlers are an OS-specific thing which is reasonably well documented at https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app for the UWP at least. I don't know how this works outside Windows 10 and UWP.

0 Likes

Anonymous
Not applicable

since the file link is not a usual http endpoint, thats why curl and requests also didnt work for me. I tried with Python webbrowser module in a quick test and it does work and successfully initiates Fusion360 with the model loaded.

 

You had previously mentioned that, another option is to have a process running outside of Fusion that calls into Fusion using the Fusion 360 protocol handler. my add-in could be watching for when the protocol handler is invoked and do whatever it wants in response.

 

Now, how could I actually make a communication between this process running externally outside of Fusion, which initiates Fusion using the protocol handler, and the addin inside of Fusion that I could make to run on startup. Are there any events as such inside the Fusion process that are fired when the protocol handler is called? How could I actually establish a communication between the two running scripts (protocol handler and fusion addin)?

 

Any help would be appreciated

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

Take a look at the user manual topic on this and particularly the sections on privateInfo and Events towards the end of the topic. 

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