Get current user

Programming and macros
berg_lauritz
Posts: 423
Joined: Tue Mar 09, 2021 10:11 am
Answers: 6
x 439
x 233

Get current user

Unread post by berg_lauritz »

I cannot seem to find any command within SolidWorks that will give me the current user that SolidWorks i.e. puts into the "last saved by" property.

Code: Select all

$PRP:"SW-Last saved by(Last Saved By)"
Any ideas how to access this without saving the document?

Is this any different for PDM? How are the abbreviations of the name determined?

I feel like I am missing something incredibly obvious here....

Edit:
I forgot to mention that
GetCurrentFileUser returns an empty string, although this document is saved already!
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: Get current user

Unread post by zwei »

If you want to access the user name without saving the doc, one way is to use the environment variable

Code: Select all

Environ("username")
Here is an example:

Code: Select all

Dim swApp               As SldWorks.SldWorks
Dim CurrentUser         As String

Sub main()

Set swApp = Application.SldWorks

'Get Username from environment variable
CurrentUser = Environ("username")

Debug.Print "Current User: " & CurrentUser


End Sub
Result:
image.png
*I am not sure about PDM since i am not using SOLIDWORKS PDM...
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
Post Reply