Entitlement API changes in Inventor 2020

We already have some articles on using the Entitlement API from Inventor:
Entitlement API in Inventor
Entitlement API in Inventor 2018

There is now a change you have to be aware of.
Starting with Inventor 2020, to guarantee the Entitlement API calls work properly to get the UserName, call the Inventor API’s Application.Login() function before or after webServiceMgr.Initialize() so the WebServices are fully initialized.
Otherwise, you may see a valid UserId, but an empty UserName when the user is already logged in:
NoUserName
Note: the Application.Login() function is hidden, so IntelliSense in Visual Studio will not list it.

And, if the user attempts to login when you have not used the Login() API call, they may get an error dialog that the service is not available:

Image-2019-05-09-12-26-49-479

You can use the following code to get userId and userName:

public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
m_inventorApplication = addInSiteObject.Application;
CWebServicesManager mgr = new CWebServicesManager();
bool isInitialized = mgr.Initialize();
if (isInitialized)
{
try
{
m_inventorApplication.Login();
string userId = "";
mgr.GetUserId(ref userId);
string userName = "";
mgr.GetLoginUserName(ref userName);
MsgBox.Show(
"User ID = '" + userId + "n" +
"User Name = '" + userName + "'");
}
catch (Exception ex)
{
MsgBox.Show(ex.Message);
}
}
}

This solved the problem:

NoUserNameFixed

As pointed out in one of the above-referenced articles, there is a GitHub repo with a project showing the usage of the Entitlement API from an Inventor add-in. I updated it with “releases” for Inventor 2016/2017, 2018/2019 and 2020: https://github.com/ADN-DevTech/EntitlementAPI_Inventor

-Adam


Comments

2 responses to “Entitlement API changes in Inventor 2020”

  1. Thomas Rambach Avatar
    Thomas Rambach

    Can you explain this better or give an example of what this would look like?

  2. Sure. I updated now the article with more details

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading