Is it possible to get the user's name and surname (profile), and maybe other details, from Account details, VBA/iLogic code?

Is it possible to get the user's name and surname (profile), and maybe other details, from Account details, VBA/iLogic code?

engilic
Advocate Advocate
1,085 Views
6 Replies
Message 1 of 7

Is it possible to get the user's name and surname (profile), and maybe other details, from Account details, VBA/iLogic code?

engilic
Advocate
Advocate

Hi,

 

Is it possible to get the user's name and surname (profile), and maybe other details, from Account details, VBA/iLogic code?

Just to have personalized messages, (would be nice).

 

I attached a screenshot with my details to specify what I want.

 

Thank you

0 Likes
Accepted solutions (1)
1,086 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor

Hi @engilic 

Seems like you want to get the info from a360. There's a lot of information you can get using the entitlement API.

See this iLogic example for first and last name 🙂

 

AddReference "AddinNETFramework.AdWebServicesWrapper.dll"
Imports Autodesk.WebServices
Sub Main
	Dim firstName As String = ""
	Dim lastName As String = ""

	If GetUserName(firstName, lastName) Then
		MessageBox.Show("Hello, " & firstName & " " & lastName, _
		"Personal message")
	Else
		MessageBox.Show("Failed to get user info.", "Fail")
	End If

End Sub
Public Function GetUserName(ByRef firstName As String, ByRef lastName As String) As Boolean
	Try
		Dim webServiceMgr As New CWebServicesManager()
		If webServiceMgr.Initialize() Then
			webServiceMgr.GetUserFirstName(firstName)
			webServiceMgr.GetUserLastName(lastName)
			If firstName = "" Or lastName = "" Then
				firstName = ""
				lastName = ""
				Return False
			Else
				Return True
			End If
		Else
			firstName = ""
			lastName = ""
			Return False
		End If

		Return True
	Catch ex As Exception
		firstName = ""
		lastName = ""
		Return False
	End Try
End Function
Message 3 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

I tried this in Inventor 2021 now and there it failed. So I added the line:

ThisApplication.Login()

before

webServiceMgr.Initialize()

and then it worked. So the complete code should look like this 🙂

 

AddReference "AddinNETFramework.AdWebServicesWrapper.dll"
Imports Autodesk.WebServices
Sub Main
	Dim firstName As String = ""
	Dim lastName As String = ""

	If GetUserName(firstName, lastName) Then
		MessageBox.Show("Hello, " & firstName & " " & lastName, _
		"Personal message")
	Else
		MessageBox.Show("Failed to get user info.", "Fail")
	End If

End Sub
Public Function GetUserName(ByRef firstName As String, ByRef lastName As String) As Boolean
	Try
		Dim webServiceMgr As New CWebServicesManager()
		ThisApplication.Login()
		If webServiceMgr.Initialize() Then
			webServiceMgr.GetUserFirstName(firstName)
			webServiceMgr.GetUserLastName(lastName)
			If firstName = "" Or lastName = "" Then
				firstName = ""
				lastName = ""
				Return False
			Else
				Return True
			End If
		Else
			firstName = ""
			lastName = ""
			Return False
		End If

		Return True
	Catch ex As Exception
		firstName = ""
		lastName = ""
		Return False
	End Try
End Function
Message 4 of 7

engilic
Advocate
Advocate

Thank you very much @JhoelForshav ,

 

This is great, works like a charm.

 

Is it difficult to transfer it to VBA or not?

Just not sure about the first two lines, AddReference, and Imports.

Also webServiceMgr function.

 

Thank you

0 Likes
Message 5 of 7

engilic
Advocate
Advocate

Can anyone make this code work in VBA?

 

Thx

0 Likes
Message 6 of 7

engilic
Advocate
Advocate

Please @JhoelForshav ,

 

Is it possible to get VBA code for macro, I cannot do it.

 

Thank you.

0 Likes
Message 7 of 7

jake_egley
Advocate
Advocate

In VBA it's much easier:

 

Dim UserName As String
UserName = Environ("USERNAME")
MsgBox (UserName)

 

Jake Egley
Inventor 2022
0 Likes