Get the user name

Get the user name

kandennti
Mentor Mentor
755 Views
2 Replies
Message 1 of 3

Get the user name

kandennti
Mentor
Mentor

Hi everyone.

 

We wanted to get the active user name, so we created a test code like this.

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

def run(context):
    ui :adsk.core.UserInterface = None
    try:
        app :adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        
        user = app.currentUser
        info = [
            f'displayName : {user.displayName}',
            f'userName :{user.userName}',
            f'userId :{user.userId}',
            f'email :{user.email}',
            ]
        ui.messageBox('\n'.join(info))
    except:
        if ui:
            print('Failed:\n{}'.format(traceback.format_exc()))
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Looking at the description of the displayName property, I thought I could get it with displayName.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2CD5E1DC-A891-4893-AFC0-17224F2B765B 

 

The result is shown in the upper left of the image.

1.png

 

What is retrieved by displayName is the user name displayed in "My Profile".

 

Does anyone know how to get the user name displayed in the Fusion360 user interface?

Thank you in advance.

0 Likes
Accepted solutions (1)
756 Views
2 Replies
Replies (2)
Message 2 of 3

JeromeBriot
Mentor
Mentor
Accepted solution

Hi,

 

Maybe :

 

import adsk.core

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

        userName = app.executeTextCommand('Options.Get LastFullUserNameId').split(" has value ")[-1]

        ui.messageBox(userName)

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

 

I can't test because this is the same name on my profile and on the Fusion 360 UI.

Message 3 of 3

kandennti
Mentor
Mentor
0 Likes