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: 

Global Variable Holding document no longer functional

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
nnamfoh
432 Views, 11 Replies

Global Variable Holding document no longer functional

Code that worked perfectly yesterday now no longer functions, I wonder if its related to the update?

I have been keeping a global variable document called settings associated with my plugin, this allows me to keep track of things like the ui and app variables across many documents so that I can create complex commands without cluttering up my main python file.

 

But this morning it stopped working. Code that works in a regular python enviroment won't function in the plugin anymore.

Here is simplified code below with two documents: setting.py, and HelloPlugin.py. They ar ein the same file location, in the add-ins folder for Fusion 360 and it should, on startup create a message box that says: "Hello addin: stuff". Really simple but not functioning. Can anyone see the bug or let me know why this isn't working any more?

 

#settings.py
stuff = None
def init():
    global stuff
    stuff = "stuff"


#HelloPlugin.py
import settings
settings.init()
import adsk.core, adsk.fusion, adsk.cam, traceback
app = None
ui = None
def run(context):
    try:
        global app
        app = adsk.core.Application.get()
        global ui
        ui  = app.userInterface
        ui.messageBox('Hello addin: '+settings.stuff)

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

def stop(context):
    try:
        ui.messageBox('Stop addin')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
11 REPLIES 11
Message 2 of 12
ekinsb
in reply to: nnamfoh

What error are you seeing?  I'm getting an error at the import because it's unable to find the "settings" module.  This is a problem but I want to confirm that you're having the same problem and not something else.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 12
nnamfoh
in reply to: ekinsb

I'm not seeing any error. I don't think the program gets past import settings, and for some reason my Spyder IDE does not give me a console to debug with so no errors come up at all. I've mentioned this bug with spyder in a different post but know one else seems to have the issue and I don't know how to recreate it since its just how Spyder came to me.

Message 4 of 12
ekinsb
in reply to: nnamfoh

I am able to debug it in Spyder and step through the code.  It's failing at the "import settings" line because it's not able to find the "settings" module. I checked sys.path and the local path is not there, so it makes sense it can't find the module.  I believe it should be the first one listed. I need to check to see if we've changed something and unintentionally broken this.

 

Regarding the console window in Spyder, I've not seen that either.  Do you have the Console pane turned on?

 

SpyderPanes.png

 

 

As a temporary work around the import problem you can add the following two lines to the top of your main module (HelloPlugin.py). This allows it to find the "settings" module.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 12
nnamfoh
in reply to: ekinsb

Now I do. Unfortunatly it crashes if I leave it on and then resart Spyder. So I'll just have to remember to turn it on each time

Message 6 of 12
ekinsb
in reply to: nnamfoh

I don't know why you're having the problem with Spyder.  Out of curiosity, are you on Windows or Mac?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 12
nnamfoh
in reply to: ekinsb

Thanks that sort of fixed it. It still won't let me debug properly with it but I see the error now
Message 8 of 12
nnamfoh
in reply to: ekinsb

Windows 10 64 bit.
I've been working around it, but every time I run the debuger Fusion 360 crashed. After the first time I couldn't get the console back
Message 9 of 12
nnamfoh
in reply to: ekinsb

Do you know roughly when this could be fixed or if its a general problem for people? Without being able to access other files it has destroyed months of work and it would be terrible coding practice to condense all of those files into one large document.
Message 10 of 12
frankzhang
in reply to: nnamfoh

Spyder settings will be fixed when you close it after you make any setting changes, for example, show "Variable Explorer". But the settings will be lost if in anyway it got crashed, so my suggestion is that you don't debug your script, but just edit it in Spyder, and then show "Variable Explorer" from View->Panes, and then close Spyder once, then the settings will be saved.

 

With regard to the debug crash, we have identified a problem, we'll try to fix it as soon as we can, but at this time, avoid stop a debug session from Spyder (or don't click the "Exit Debug" button), instead, you can stop a debug session from Fusion Scripts and Add-ins manager (Shown in below screenshot).

 

StopPythonDebugger.png

Message 11 of 12
ekinsb
in reply to: nnamfoh

The development team looked into this and nothing has changed in this area so we're not sure how it worked for you before.  My initial assumption about the core of the problem wasn't quite correct either and my first thought about fixing it isn't a good solution either.  Fusion is adding the current path to sys.path but this ends up being the location of where Fusion 360.exe is. In Fusion a single Python manager is shared by all scripts so there can be side effects to changing sys.path.

 

However, there is an easy solution in your case.  Instead of:

 

import settings
settings.init()

 

Change your code to:

from . import settings
settings.init() 

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 12 of 12
nnamfoh
in reply to: ekinsb

This solution seems to work, however the problems with using import seems to be a large problem when using python. I hope that there is a more permanent solution in the future 🙂

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