Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Working example of user entitlements

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
matt_jlt
806 Views, 14 Replies

Working example of user entitlements

Does anyone have a working example of user entitlements implemented for inventor 2021 and above?

I haven't found any examples of this as a complete / working reference but i would like to implement it.

Any help would be appreciated.

 

Thanks, Matt.

14 REPLIES 14
Message 2 of 15
JelteDeJong
in reply to: matt_jlt

Not sure if this is what you are referring to but I found this post "Entitlement API changes in Inventor 2020". With the information in that article (and some of the posts referred to in the post) I managed to get it working in an Ilogic rule in Inventor 2021. Maybe it helps you:

AddReference "C:\Program Files\Autodesk\Inventor 2021\Bin\AddinNETFramework.AdWebServicesWrapper.dll"
Imports Autodesk.WebServices
Dim mgr As CWebServicesManager = New CWebServicesManager()

If (mgr.Initialize()) Then
	ThisApplication.Login()
	
	Dim userId = ""
    mgr.GetUserId(userId)
  	Dim userName = ""
  	mgr.GetLoginUserName(userName)
  	MsgBox("User ID = '" + userId + " -> " + "User Name = '" + userName + "'")
End If

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 15
matt_jlt
in reply to: JelteDeJong

Thanks, seems like that link is along the right track of info. I just can't see anything about where it manages to check if the user has purchased the addin. All i can see is getting the active usename / id etc.

 

Thanks, Matt.

Message 4 of 15
matt_jlt
in reply to: JelteDeJong

I found an example for fusion, do i need to do a http request in .net like this or is there some built in function for that already?


https://github.com/sajith-subramanian/EntitlementAPI-for-Fusion-360

def run(context):

    ui = None

try:

        app = adsk.core.Application.get()

        ui  = app.userInterface

        userId = app.userId

        appId ="1006119760063675415"

        url  = "https://apps.exchange.autodesk.com/webservices/checkentitlement" +

       "?userid=" + userId + "&appid=" + appId

        r = requests.get(url)

        resp_dict = json.loads(r.text)

        val = resp_dict.get('IsValid')

if val:

            ui.messageBox("IsValid is True")

else:

            ui.messageBox("IsValid is False")

except:

if ui:

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

 

Message 5 of 15
JelteDeJong
in reply to: matt_jlt

try this rule and check the logger:

(i have not paid for any app so i could not check if it truly works but it looks good.Plz let me know if it works)

JelteDeJong_0-1636404133747.png

AddReference "C:\Program Files\Autodesk\Inventor 2021\Bin\AddinNETFramework.AdWebServicesWrapper.dll"
Imports Autodesk.WebServices
Imports System.Text.RegularExpressions
Dim appId = "<YOUR APP ID HERE>"

Dim mgr As CWebServicesManager = New CWebServicesManager()

If (mgr.Initialize()) Then
	ThisApplication.Login()
	
	Dim userId = ""
    mgr.GetUserId(userId)
  	Dim userName = ""
  	mgr.GetLoginUserName(userName)
  	' Logger.Info("User ID = '" + userId + " -> " + "User Name = '" + userName + "'")
	
	Dim url = String.Format("https://apps.exchange.autodesk.com/webservices/checkentitlement?userid={0}&appid={1}",
		userId,appId )
	Dim webClient As New System.Net.WebClient
	Dim resultJson As String = webClient.DownloadString(url)
	
	Dim regex As Regex = New Regex("{""UserId"":""(\w+)"",""AppId"":""(\w+)"",""IsValid"":(\w+),""Message"":""(\w+)""}")
	Dim match As Match = regex.Match(resultJson)
	
	If (match.Success) Then
        userId = match.Groups(1).Value
		appId = match.Groups(2).Value
		Dim isValid As String = match.Groups(3).Value
		Dim message As String = match.Groups(4).Value
        Logger.Info("userId = " & userId)
		Logger.Info("appId = " & appId)
		Logger.Info("isValid = " & isValid)
		Logger.Info("message = " & message)
	Else 
		MsgBox("there was a problem: " & resultJson)
    End If
		
End If

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 15
matt_jlt
in reply to: JelteDeJong

I did a quick test and it looks like its what i was after. Will take me a bit to be 100% sure that it all works properly. but looks right.

 

Thanks so much for your help.

 

Matt.

Message 7 of 15
c_stulz
in reply to: matt_jlt

Hello,
I tried this wit iLogic and it works 🙂

 

But I can't get an result with VisualStudio.

cstulz_0-1637166986630.png

I made an easy "Form.Project".

The dll I linked in "References"

cstulz_1-1637167182731.png

I Allthough tried all Settings with th CPU

cstulz_2-1637167303490.png

I could't find my mistake.

Any Idea?

 

Best Christoph

 

Message 8 of 15
JelteDeJong
in reply to: c_stulz

I got the same results with an external application. But I tested it also on an addin. then this worked for me. (btw this is in c#)

CWebServicesManager mgr = new CWebServicesManager();
if (mgr.Initialize())
{
    ThisApplication.Login();

    string userId = "";
    mgr.GetUserId(ref userId);
    string userName = "";
    mgr.GetLoginUserName(ref userName);

    string url = string.Format("https://apps.exchange.autodesk.com/webservices/checkentitlement?userid={0}&appid={1}",
        userId, appId);
    System.Net.WebClient webClient = new System.Net.WebClient();
    string resultJson = webClient.DownloadString(url);

    Regex regex = new Regex("{\"UserId\":\"(\\w+)\",\"AppId\":\"(\\w+)\",\"IsValid\":(\\w+),\"Message\":\"(\\w+)\"}");
    Match match = regex.Match(resultJson);

    if (match.Success)
    {
        userId = match.Groups[1].Value;
        appId = match.Groups[2].Value;
        string isValid = match.Groups[3].Value;
        string message = match.Groups[4].Value;
    }
}

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 9 of 15
c_stulz
in reply to: matt_jlt

Hello,

thanks for your reply.

In my case it is an (existing) external application where I want additional check the UserName.

 

 

Message 10 of 15
Maxim-CADman77
in reply to: c_stulz

@JelteDeJong@matt_jlt@c_stulz 

 

I've started to experiment with this entitlement stuff and would like to know some more niceties:
1. Whether UserName value is a constant or user can change it at any time just like UserEmail value* ?

 

2. Whether it possible for user to know he's  User Id** by some easy way (i.e. without using any code ... like see some part of some Autodesk user webpage ... or something alike)?

 

3. How could I get the complete list of CWebServicesManager methods?

 

*
There is GetUserEmail method which return the value.

 

**
For my account it is a 15digits and seems like date-time stamp of account creation:

Year(4digits) Month(+2) Day(+2) Hours(+2) Minutes(+2) Seconds(+3) 

Message 11 of 15
matt_jlt
in reply to: matt_jlt

I am not 100% certain but i think the username is constant for the active logged in user.


I ended up abandoning trying to use the user entitlements as i couldnt get it to work for multiple versions of inventor at once. I couldnt get the webservices to work for a newer and older version of inventor without having separate builds which i just didnt want to do / not worth the effort. 
If you manage to work out a way to do it, please let me know as i would also be interested.

Thanks, Matt.

Message 12 of 15

I don't have an answer for question 1

The user can find there ID easy in Inventor. Have a look at the top right corner of the window:

JelteDeJong_0-1678356620669.png

JelteDeJong_1-1678356700077.png

getting more info about an object can be done in Visual Studio. Have a look at the object browser. 

JelteDeJong_2-1678357286386.pngJelteDeJong_3-1678357301113.png

 

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 13 of 15

@JelteDeJong 

Thank so much for Answer for Question #3 !

 

As for Answer for Question #2
I don't believe "Autodesk Id" and "UserId" are the same.
In my case "Autodesk Id"  value equals to "UserEmail" value

while "UserId" value returned by CWebServicesManager is 15digits.

 

Message 14 of 15
Maxim-CADman77
in reply to: matt_jlt

@matt_jlt 

FYI: After I've added AddinNETFramework.AdWebServicesWrapper.dll from "C:\Program Files\Autodesk\Inventor 2020\Bin\" to VS project References my multi-version AddIn become able to get Autodesk user info in both AI2020 and AI2023 (DLL from older Software should also do things for newer unless there were some great changes introduced inbetween).

Message 15 of 15
matt_jlt
in reply to: matt_jlt

thankyou, i will have to try that out.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report