Fatal error after checking Application.userId

Fatal error after checking Application.userId

j.han97
Advocate Advocate
801 Views
9 Replies
Message 1 of 10

Fatal error after checking Application.userId

j.han97
Advocate
Advocate

Hi all,

 

I am actually facing a serious problem of Fusion 360. Let me describe the process in detail:

 

    1. Weeks ago I tried to get the user information by calling 

app: adsk.core.Application = adsk.core.Application.get()
app.userId

which according to documentation, should return the internal name of the Autodesk account currently logged in

 

    2. Right after I execute this line of code (in the text command window of Fusion 360), Fusion 360 froze indefinitely and I had to kill the application.

 

    3. I started to face a freeze-at-launch problem afterwards. I have sought for help in the Support forum but have not been able to solved it completely yet. The thread about this problem is here: Re: Fusion 360 freezes at launch - Autodesk Community - Fusion 360 in case anyone is interested.

 

Considering the rather serious consequences (Fusion 360 launching problem, unsolved till now), I do not want to test this on another computer to verify the source of error. In addition, I do not encourage you to test this code unless you are well aware of the possible consequences.

 

The reason I decided to post here (API forum) is to ask if anyone has experienced the same before, or tried this code (Application.userId) without problem. I am guessing that there are some problems within the API, since every time I called this line of code to get the userId property, Fusion 360 would freeze.

 

Any comments/suggestions/feedbacks are welcomed! Thank you!

 

0 Likes
802 Views
9 Replies
Replies (9)
Message 2 of 10

kandennti
Mentor
Mentor

Hi @j.han97 .

 

I ran the following as a script instead of a text command, and it worked fine.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui: adsk.core.UserInterface = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        print(app.userId)

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

 

 

Here are a few things I know about it.
If you see the linked output in the text command window at startup, the live update has failed.

https://forums.autodesk.com/t5/fusion-360-support/fusion-360-freezes-at-launch/m-p/10828698#M139811 

 

The current latest version is Ver 2.0.11894. Please check it.
If you do not have the latest version, you will need to install it manually.

 

Also, if you are participating in the Insider Program and have both PRODUCTION BUILD and INSIDER BUILD installed, when one of them is updated, you may see the same output in the text command window when you start the other one. In that case, I simply restarted Fusion360 and everything was fine.

 

 

Message 3 of 10

j.han97
Advocate
Advocate

Hi @kandennti ,

 

Really appreciate your help here! I have checked the version of my Fusion 360 and it is already the latest version (v2.0.11894).

 

jhan97_0-1640222963258.png

Besides that, I did not participate Fusion Insider Program, it should not be the problem.

 

Following your attempt, I tried to execute the code in script, rather than directly in the text command window. Unfortunately, this did not make any difference. 

 

If you are following my post in the Support forum, a Missing Authentication Token message has been found in the log file. Do you have any insight on this? Is it related to licensing issue? 

0 Likes
Message 4 of 10

kandennti
Mentor
Mentor

@j.han97 .

 

I don't know much more than that.

 

It may be faster to automatic clean uninstall Fusion360 and reinstall it.
However, you may want to back up your script files, cps files, thread files, etc. before you do this, as many things may be lost.

https://knowledge.autodesk.com/support/fusion-360/learn-explore/caas/sfdcarticles/sfdcarticles/How-t... 

0 Likes
Message 5 of 10

j.han97
Advocate
Advocate

Thank you @kandennti for sharing your advice. I have tried reinstalling Fusion 360 multiple times, including normal uninstall, automatic clean uninstall and even manual clean uninstall. With all that work done, the problem still persists.

 

I think that from a user's perspective, I have done pretty much everything I could do on my side. For now I am just waiting for help (and providing relevant information) in the Support forum.

0 Likes
Message 6 of 10

zxynine
Enthusiast
Enthusiast

I have experenced many problems with it, It all happens at start up of fusion. If you start with the script not loaded then start it, it should function normally. My guess is, whatever you have trying to catch the error that gets produced at start up is trying to access api objects that do not exist or is acting as a recursive function causing an infinite loop. 

I have created a delayed thread specifically because of this issue to give fusion a few seconds to get itsself situated before i try and access the userID. I advise you rethink when you are trying to access userID or waiting until its available.

 

It could be dependant on the number of addins you are running since fusion can spend alot of time loading them and not loading the user info (or something like that idk fusions userinfo is an enigma). Perhaps try using `adsk.doEvents()` before the call to let fusion catch up on some of its loading.

0 Likes
Message 7 of 10

j.han97
Advocate
Advocate

Thank you @zxynine for your suggestion. This is a new perspective that I have never thought of. I will try to inspect (and maybe solve) this problem following your advice.

0 Likes
Message 8 of 10

BrianEkins
Mentor
Mentor

I also had a problem with using the userId property but not with the catastrophic results that you're having. In my case, it was failing to return the userId.  I was told that the userId is not available to Fusion until it goes online.  When it first starts up and the add-ins are loaded it hasn't gone online yet.  I added some code to listen to the UserInterface.commandStarting event and waited for that before trying to get the userId.  I learned later that a better solution should be to listen to the Application.onlineStatusChanged event, which I intend to switch to but haven't tried yet.

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

j.han97
Advocate
Advocate

Thank you @BrianEkins for your valuable advice. It seems like my case is a little bit more complicated as it involves a 'Missing Authentication Token' issue. I am actively seeking for help in the Support forum and hoping for a solution soon.

 

Seems like Fusion 360 is not robust in these areas (involving online communication with Autodesk server) therefore I should be more careful in the future.

0 Likes
Message 10 of 10

zxynine
Enthusiast
Enthusiast

Hi,

I tested your suggestion and it does seem to work for me. I had an addin that needed the userID before it could do anything as the data is stored in a folder  named from it, by switching my workspace activated handler to onlinestatus changed handler it has yet to give the same error that would normally pop up.

the code i used is here:

#Sometimes when starting up, the ui isnt fully ready. This waits until it is then removes itself upon its first fire.
class AppReadyEventHandler(adsk.core.ApplicationEventHandler):
	#This init just calls its parent and then adds itself to handlers to prevent garbage collection
	def __init__(self): 
		super().__init__() 
		handlers.append(self)
	def notify(self, args:adsk.core.ApplicationEventArgs):
		try:
			app = adsk.core.Application.cast(adsk.core.Application.get())
			if app.isOffLine:return
			app.onlineStatusChanged.remove(self)
			runProcess(True)
		except: ErrorCast()



def run(context): 
	isStartup = bool(context['IsApplicationStartup'])
	if isStartup:
		app = adsk.core.Application.cast(adsk.core.Application.get())
		app.onlineStatusChanged.add(AppReadyEventHandler())
	else: 
		runProcess(False)
		ui.messageBox(f"The '{thisAddinTitle}' command has been added\nto the ADD-INS panel of the DESIGN workspace.", thisAddinDisplayTitle)
def stop(context): cleanUI()
0 Likes