10 Replies Latest reply on Apr 11, 2012 3:50 AM by Ales Svoboda

    User name in template properties

    Stian Solberg
      I want SW to insert the name of the creator of a file into the properties automaticly, depending on who is logged on.

      how can i do this?


      I do not wish to use the Windows logon name, i wish to use the name as below:

      Name: Madz Larsen
      Windows name: madzla
      This is the way i want it: M.Larsen

      Is this possible?

      Im currently using SW2007 SP5

        • User name in template properties
          Stian Solberg
          Does anyone know if it is possible to get the Windows account name into the drawing properties?
          • User name in template properties
            Charles Culp
            $PRP:"SW-Last Saved By" will give you the username of the last person to save the file. There is no way to get the person who first created the file.

            If you set up your part template with one per person, you can edit the "Author" field in the custom properties. Then you can pull that into the drawing with $PRP:"SW-Author". Of course I don't even do that. I just have a "Drawn By" field in the custom properties, and my part templates already have it pre-filled out with "C. CULP".
              • Re: User name in template properties
                robert dattilo



                        I'm working on my templates now, & just wondering whats the difference between me putting a custom property of drawn by, & then linking the appropriate

                text in the sheet format, or using the $prp: "SW-Author? Is it just as sufficient with my putting drawn by, or is there something better about the $prp: sw-author.




                      rob_d(2010, sp2.1)  

              • User name in template properties
                I spent a day or so writing up the following macro that reads a designer's name from a .txt file located on your local drive and fills it in to a custom property in the model then creates a drawing with 3 standard views (required in order to maintain an automatic link between model and drawing). Pretty cool if I do say so myself.<br /><br />(In case it isn't overly apparent, our titleblock has a field with the $PRP:"DETAILBY" note in it which refers to a custom property in the model called DETAILBY that we're using in this macro).<br /><br />Here's the code:<br /><br />Imports SolidWorks.Interop.sldworks<br />Imports SolidWorks.Interop.swconst<br />Imports System<br />Imports System.IO<br /><br />Partial Class SolidWorksMacro<br /><br />    Public Sub main()<br />        'Make Drawing Macro<br />        'Written by James Peltier of GFW Technologies Inc.<br />        'March 2009<br /><br />        'This macro is intended to be run on an open assembly (SLDASM) or part (SLDPRT) and create a drawing while<br />        'automatically filling in the "Detailed By" field on the titleblock. The designer's name will be stored in<br />        'a file stored locally on their machine.<br /><br />        'Variable Declarations<br />        Dim swDoc As ModelDoc2 = Nothing<br />        Dim swPart As PartDoc = Nothing<br />        Dim swDrawing As DrawingDoc = Nothing<br />        Dim swAssembly As AssemblyDoc = Nothing<br />        Dim boolstatus As Boolean = False<br />        Dim longstatus As Integer = 0<br />        Dim longwarnings As Integer = 0<br />        swDoc = CType(swApp.ActiveDoc, ModelDoc2)<br />        Dim FilePath As String = ""<br />        Dim DesignerName As String = ""<br />        Dim Part As ModelDoc2 = swApp.ActiveDoc<br /><br />        'Before we really do anything, we want to make sure a file is open (error-checking)<br />        If Part Is Nothing Then<br />            MsgBox("You must open a file for this macro to run", MsgBoxStyle.Exclamation)<br />            Exit Sub<br />        End If<br /><br />        'First, we need to get the filename of the open document<br />        FilePath = swDoc.GetPathName<br /><br />        'Next, we're going to check and see if the user is trying this macro on a SLDDRW (more error-checking)<br />        Dim FileType As String = IO.Path.GetExtension(FilePath)<br />        If (FileType = ".SLDDRW") Then<br />            MsgBox("You cannot create a drawing of a drawing!", MsgBoxStyle.Exclamation, "Duh!")<br />            Exit Sub<br />        ElseIf (FileType = "") Then<br />            MsgBox("File hasn't been saved yet. Save the file and try again!", MsgBoxStyle.Exclamation, "Oops!")<br />            Exit Sub<br />        End If<br /><br />        'Now we can check and see if a drawing already exists (more error-checking)<br />        Dim DrawingPath As String = IO.Path.ChangeExtension(FilePath, ".SLDDRW")<br />        If (System.IO.File.Exists(DrawingPath)) Then<br />            Dim Ignore As MsgBoxResult = MsgBox("Drawing Already Exists with that filename! Make Drawing Anyways?", MsgBoxStyle.YesNo, "Duplicate File Found")<br />            If Ignore = MsgBoxResult.No Then<br />                Exit Sub<br />            End If<br />        End If<br /><br /><br />        'We need to open a .txt file on the local computer that contains the designer's name<br />        'and put that name into a custom property (DetailBy) in the part or assembly<br />        Dim LocalDesigner As String = "C:\Documents and Settings\All Users\Application Data\GFW\LocalDesigner.txt"<br />        Dim sw As New StreamReader(LocalDesigner)<br />        Dim PropMgr As CustomPropertyManager<br />        Dim value As Integer<br />        Dim PropName As String = "DETAILBY"<br />        PropMgr = Part.Extension.CustomPropertyManager("")<br /><br />        'This gets the name from the file<br />        DesignerName = sw.ReadLine<br /><br />        'This fills in the custom property field<br />        value = PropMgr.Set(PropName, DesignerName)<br /><br />        'Finally, we create a drawing of the part with 3 standard views.<br />        swDoc = CType(swApp.NewDocument("Y:\GFW Templates\2009 Templates\GFW-B.slddrt", 12, 0.2794, 0.4318), ModelDoc2)<br />        swDrawing = CType(swDoc, DrawingDoc)<br />        boolstatus = swDrawing.Create3rdAngleViews(FilePath)<br />    End Sub<br /><br />    ''' <summary><br />    ''' The SldWorks swApp variable is pre-assigned for you.<br />    ''' </summary><br />    Public swApp As SldWorks<br /><br /><br />End Class<br /><br /><br /><br /><br /><br />I hope you find this as useful as I do. We used to use Task Scheduler to change that custom property on an entire project, but that becomes problematic when you have multiple designers working on a single project.
                • User name in template properties
                  (FYI: This works in SW 2009 SP2.1). Not sure what it will do in earlier versions.
                  • User name in template properties

                    In the section where I create a drawing of the part with 3 standard views, I use the line:
                    swDoc = CType(swApp.NewDocument("Y:\GFW Templates\2009 Templates\GFW-B.slddrt", 12, 0.2794, 0.4318), ModelDoc2)

                    Instead, I should be referencing a DRWDOT file. The macro otherwise worked fine until I went to put dimensions on it and wondered why none of the usual settings (dual units, etc) were applied. I guess those settings are stored in the DRWDOT file.

                    And NOW I understand what the difference is between a DRWDOT and a SLDDRT file.
                    • Re: User name in template properties
                      Matthew Lorono

                      I think you'll need some sort of look up table or a series of if-then statements in a macro to get what you are looking for.  Other than that, you can place a .txt file on each person's computer that has the name in the format you wish, then have the macro open that file and use that information for the specific document.  Without an add-in, this will have be done manually, which don't really provide any extra value than if the user just finds there name on a preset list in either the Property Tab or a more generic macro.


                      Matt Lorono

                      SolidWorks Legion

                      Follow  me on Twitter

                      • Re: User name in template properties
                        Ales Svoboda

                        Here https://forum.solidworks.com/thread/53091 is the macro. Description of how it use, is in the macro file.