Tuesday 22 December 2020

Debugging Fusion add-in using Visual Studio Code

Not pretending this is some run-of-the-mill activity for me but I had to attempt to figure out what the problem was with Tim's add-in for the Fusion post. The add-ins are written in Python, which pretty much rules me out when it comes to understanding what is going on at any depth, let alone making any changes. Javascript (used in the post processors) is about my limit and even then I wouldn't want to risk an old shirt on that. However, the debug feature within VSC seems to be almost usable by the likes of me - or at least enough to give me a clue where the problem lies. Question is whether I even have enough brainpower to work out how to use it.

Took me a while to understand the intro Tim gave me, along with the tutorial type material in his link. Here's what he said. This was enough to provoke me into giving it a go:

Since you know how to modify a post processor, you should have no trouble learning how to debug a Fusion 360 add-in. It requires Visual Studio Code. There's a quick tutorial (although slightly out of date) at:

https://modthemachine.typepad.com/my_weblog/2019/09/debug-fusion-360-add-ins.html

All we want to do is use a breakpoint to stop execution at line 892 where the call is made to Fusion 360 to post the operation. Then single step ahead a few lines to line 902 where the program opens the file Fusion 360 generated.

This link in turn took me to this page and I also found various Pootube vids, some of which were helpful, others not.

Lesson #1 

Some tosser at Microsoft decided to rename "Debug" as "Run" within VSC. That's designed to catch out beginners like me - as indeed it did for 20 mins or so. Thank you, tosser.

Anyway, I thought I'd note down what to do, as I have goldfish genes and if I ever need to repeat this exercise, I don't want to go through the learning process again.

Setting up VSC to debug the add-in:

Assuming the add-in is already installed (follow Tim's instructions), you need to stop it, then restart it in debug mode. For this, you need to be in the manufacturing environment and select Utilities > Add-Ins, then select the Add-Ins tab, find PostProcessAll within "My Add-Ins", select it and hit the "Stop" button.


Next, select "Debug" from the pulldown button:




This should open VSC with the Python file open in the editor:


This is all frightfully impressive stuff. Almost gives an air of competence and sophistication. Quiet deceptive.

But still nothing great is happening. The "Process All" icon has disappeared from the menu ribbon thing. Difficult to see how you can debug the thing if it isn't accessible. That's because you now need to go into VSC and start the debug process there.

The debug button in VSC is called "Run" of course, rather than the "Debug" button that is referred to in the documentation. Silly fucking me. 


When you press that, a panel opens on the left side displaying variables etc. You might think that would be enough to well.... run the thing. But you'd be wrong.

Now you have to actually start the debug process from within VSC. You might have thought you'd done this already. Here's the "Start Debugging" button. There's another, similar "start button at the top right of the window but that's a different kind of start obviously.


Finally...
Now, finally, we have a debug situation scenario occurring. The Process All icon has reappeared and when you click on it, VSC runs through the code, stopping at the breakpoints you have hopefully inserted. Whoopee.


There's a little control bar at the top of the screen (you can grab it and drag it where you prefer) that allows you to continue past the breakpoint, restart, disconnect etc. The latter breaks the link between Fusion and the debugger from what I can tell.


Obviously, Fusion freezes between breakpoints as it waits for you to step through the code. If it can execute the whole file without error, you emerge out the other end with all the processes completed, files written etc.

That took a little while to get running. Good to have a note of what to do for next time - if there is a next time.

No comments:

Post a Comment

Final assembly and test of the spindle nose adaptor - RESULT!!

After the recent distraction caused by the 3D scanner, resurrecting the 3D printer and buggering about with the throttle bodies for my Honda...