How to capture Username and place in custom properties table.

Discussion in 'SolidWorks' started by MrSlabaugh, Feb 14, 2006.

  1. MrSlabaugh

    MrSlabaugh Guest

    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
     
    MrSlabaugh, Feb 14, 2006
    #1
  2. 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 http://www.SecureIX.com ***
     
    Wayne Tiffany, Feb 14, 2006
    #2
  3. MrSlabaugh

    TOP Guest

    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
     
    TOP, Feb 14, 2006
    #3
  4. MrSlabaugh

    Dataman Guest

    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
     
    Dataman, Feb 14, 2006
    #4
  5. MrSlabaugh

    TOP Guest

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

    TOP
     
    TOP, Feb 15, 2006
    #5
  6. MrSlabaugh

    MrSlabaugh Guest

    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
     
    MrSlabaugh, Feb 15, 2006
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.