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: 

Get the user name

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
kandennti
343 Views, 2 Replies

Get the user name

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.

2 REPLIES 2
Message 2 of 3
JeromeBriot
in reply to: kandennti

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
in reply to: JeromeBriot

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