How to capture Username and place in custom properties table.

Our Windows XP workstations have a username of the person logged on. I want to have that name placed in a custom property on model or drawing creation. Does anyone have experience automating this?

Specifics:

Whenever someone logs onto Windows XP, they type their name in the user name text box on the login screen. When a new model or drawing is created I want that name to be placed into a custom property file text box. This would be like the way the model description is automatically placed into the text field for the custom property "Description".

An alternative would be having a text file placed in a standard location with the name as a text item, that would be found and copied into the Description field on model or drawing creation.

One last thought, Microsoft Word has a method of storing the file creator as the person who filled out the Tools, Options, User Information, Name field. Is something like that available?

This feature would change the field only on document creation, or when a Save As, Save As Copy command were performed (to change the name when an unlinked copy were created).

Thanks,

Mark

Reply to
MrSlabaugh
Loading thread data ...

There is a property that we use that is called $PRP:"SW-Last Saved By". This is in a note in a drawing that updates any time the drawing is saved. Might be of some value to you.

WT

*** Free account sponsored by SecureIX.com *** *** Encrypt your Internet usage with a free VPN account from
formatting link
***
Reply to
Wayne Tiffany

This is from MSoft API help. In my case I have a macro that takes a new part, assembly or drawing, saves it to a user supplied name, asks for a description, fills in a few custom properties and could easily be made to add the custom property you asked for. Since we use three character initials the username would not be entirely helpful unless a lookup existed.

' ****************************************************************************** ' C:\DOCUME~1\kellnerp\LOCALS~1\Temp\swx3444\Macro1.swb - macro recorded on 02/14/06 by kellnerp ' ****************************************************************************** Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

'Per MSoft API help Debug.Print Environ("USERNAME")

End Sub

Reply to
TOP

This should help if you need to do it in VB or VBA.

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function SysGetUserName() As String

Dim UserName As String Dim BufSize As Long Dim RetCode As Long Dim NullCharPos As Long

UserName = Space(80) BufSize = Len(UserName)

'---call WINAPI RetCode = GetUserName(UserName, BufSize)

'---search for the end of the string NullCharPos = InStr(UserName, Chr(0)) If NullCharPos > 0 Then UserName = Left(UserName, NullCharPos - 1) Else UserName = "" End If

SysGetUserName = Left(UserName, 2) End Function

Reply to
Dataman

Just curious as to why you would go to all that trouble when Environ("USERNAME") seems to do the same thing in VB?

TOP

Reply to
TOP

I searched SolidWorks Help for Environ, and USERNAME with no results.

I am looking for some way of automatically identifying the person who created the part or drawing so that the name can be used through custom properties to fill in the engineered by, or drawn by box on our drawings.

We currently have to open the custom properties window and re-type these names for each drawing, part, or assembly. Since the workstation already knows who is logged on at the time, I thought that that would be a good place to find the name.

SolidWorks VAR help staff have not come up with a way inside of SolidWorks to make this happen.

Thanks,

Mark

Reply to
MrSlabaugh

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.