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