Page 1 of 1

Get current user

Posted: Sun Oct 30, 2022 1:33 pm
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!

Re: Get current user

Posted: Sun Oct 30, 2022 6:46 pm
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...